25 #include <ColPack/ColPackHeaders.h>
27 using namespace Eigen;
28 using namespace ColPack;
33 CProbingSampler::CProbingSampler() : CTraceSampler()
38 CProbingSampler::CProbingSampler(
39 CSparseMatrixOperator<float64_t>* matrix_operator, int64_t power,
40 EOrderingVariant ordering, EColoringVariant coloring)
41 : CTraceSampler(matrix_operator->get_dimension())
46 m_matrix_operator=matrix_operator;
53 void CProbingSampler::init()
55 m_matrix_operator=NULL;
58 m_coloring=DISTANCE_TWO;
59 m_is_precomputed=
false;
61 SG_ADD(&m_coloring_vector,
"coloring_vector",
"the coloring vector generated"
64 SG_ADD(&m_power,
"matrix_power",
"power of the sparse-matrix for coloring",
67 SG_ADD(&m_is_precomputed,
"is_precomputed",
70 SG_ADD((CSGObject**)&m_matrix_operator,
"matrix_operator",
74 CProbingSampler::~CProbingSampler()
79 void CProbingSampler::set_coloring_vector(SGVector<int32_t> coloring_vector)
81 m_coloring_vector=coloring_vector;
82 m_is_precomputed=
true;
85 SGVector<int32_t> CProbingSampler::get_coloring_vector()
const
87 return m_coloring_vector;
90 void CProbingSampler::precompute()
97 SG_DEBUG(
"Coloring vector already computed! Exiting!\n");
102 SparsityStructure* sp_str=m_matrix_operator->get_sparsity_structure(m_power);
104 GraphColoringInterface* Color
105 =
new GraphColoringInterface(SRC_MEM_ADOLC, sp_str->m_ptr, sp_str->m_num_rows);
107 std::string str_ordering;
111 str_ordering=
"NATURAL";
114 str_ordering=
"LARGEST_FIRST";
116 case DYNAMIC_LARGEST_FIRST:
117 str_ordering=
"DYNAMIC_LARGEST_FIRST";
119 case DISTANCE_TWO_LARGEST_FIRST:
120 str_ordering=
"DISTANCE_TWO_LARGEST_FIRST";
123 str_ordering=
"SMALLEST_LAST";
125 case DISTANCE_TWO_SMALLEST_LAST:
126 str_ordering=
"DISTANCE_TWO_SMALLEST_LAST";
128 case INCIDENCE_DEGREE:
129 str_ordering=
"INCIDENCE_DEGREE";
131 case DISTANCE_TWO_INCIDENCE_DEGREE:
132 str_ordering=
"DISTANCE_TWO_INCIDENCE_DEGREE";
135 str_ordering=
"RANDOM";
139 std::string str_coloring;
143 str_coloring=
"DISTANCE_ONE";
146 str_coloring=
"ACYCLIC";
148 case ACYCLIC_FOR_INDIRECT_RECOVERY:
149 str_coloring=
"ACYCLIC_FOR_INDIRECT_RECOVERY";
154 case RESTRICTED_STAR:
155 str_coloring=
"RESTRICTED_STAR";
158 str_coloring=
"DISTANCE_TWO";
162 Color->Coloring(str_ordering, str_coloring);
164 std::vector<int32_t> vi_VertexColors;
165 Color->GetVertexColors(vi_VertexColors);
167 REQUIRE(vi_VertexColors.size()==
static_cast<uint32_t
>(m_dimension),
168 "dimension mismatch, %d vs %d!\n", vi_VertexColors.size(), m_dimension);
170 m_coloring_vector=SGVector<int32_t>(vi_VertexColors.size());
172 for (std::vector<int32_t>::iterator it=vi_VertexColors.begin();
173 it!=vi_VertexColors.end(); it++)
176 m_coloring_vector[i]=*it;
179 Map<VectorXi> colors(m_coloring_vector.vector, m_coloring_vector.vlen);
180 m_num_samples=colors.maxCoeff()+1;
181 SG_DEBUG(
"Using %d samples (aka colours) for probing trace sampler\n",
188 m_is_precomputed=
true;
193 SGVector<float64_t> CProbingSampler::sample(
index_t idx)
const
195 REQUIRE(idx<m_num_samples,
"Given index (%d) must be smaller than "
196 "number of samples to draw (%d)\n", idx, m_num_samples);
198 SGVector<float64_t> s(m_dimension);
201 for (
index_t i=0; i<m_dimension; ++i)
203 if (m_coloring_vector[i]==idx)
215 #endif // HAVE_EIGEN3
216 #endif // HAVE_COLPACK
float distance(CJLCoverTreePoint p1, CJLCoverTreePoint p2, float64_t upper_bound)
float64_t std_normal_distrib() const
all of classes and functions are contained in the shogun namespace