24 #include <ColPack/ColPackHeaders.h>
26 using namespace Eigen;
27 using namespace ColPack;
32 CProbingSampler::CProbingSampler() : CTraceSampler()
37 CProbingSampler::CProbingSampler(
38 CSparseMatrixOperator<float64_t>* matrix_operator, int64_t power,
39 EOrderingVariant ordering, EColoringVariant coloring)
40 : CTraceSampler(matrix_operator->get_dimension())
45 m_matrix_operator=matrix_operator;
52 void CProbingSampler::init()
54 m_matrix_operator=NULL;
57 m_coloring=DISTANCE_TWO;
58 m_is_precomputed=
false;
60 SG_ADD(&m_coloring_vector,
"coloring_vector",
"the coloring vector generated"
63 SG_ADD(&m_power,
"matrix_power",
"power of the sparse-matrix for coloring",
66 SG_ADD(&m_is_precomputed,
"is_precomputed",
69 SG_ADD((CSGObject**)&m_matrix_operator,
"matrix_operator",
73 CProbingSampler::~CProbingSampler()
78 void CProbingSampler::set_coloring_vector(SGVector<int32_t> coloring_vector)
80 m_coloring_vector=coloring_vector;
81 m_is_precomputed=
true;
84 SGVector<int32_t> CProbingSampler::get_coloring_vector()
const
86 return m_coloring_vector;
89 void CProbingSampler::precompute()
96 SG_DEBUG(
"Coloring vector already computed! Exiting!\n");
101 SparsityStructure* sp_str=m_matrix_operator->get_sparsity_structure(m_power);
103 GraphColoringInterface* Color
104 =
new GraphColoringInterface(SRC_MEM_ADOLC, sp_str->m_ptr, sp_str->m_num_rows);
106 std::string str_ordering;
110 str_ordering=
"NATURAL";
113 str_ordering=
"LARGEST_FIRST";
115 case DYNAMIC_LARGEST_FIRST:
116 str_ordering=
"DYNAMIC_LARGEST_FIRST";
118 case DISTANCE_TWO_LARGEST_FIRST:
119 str_ordering=
"DISTANCE_TWO_LARGEST_FIRST";
122 str_ordering=
"SMALLEST_LAST";
124 case DISTANCE_TWO_SMALLEST_LAST:
125 str_ordering=
"DISTANCE_TWO_SMALLEST_LAST";
127 case INCIDENCE_DEGREE:
128 str_ordering=
"INCIDENCE_DEGREE";
130 case DISTANCE_TWO_INCIDENCE_DEGREE:
131 str_ordering=
"DISTANCE_TWO_INCIDENCE_DEGREE";
134 str_ordering=
"RANDOM";
138 std::string str_coloring;
142 str_coloring=
"DISTANCE_ONE";
145 str_coloring=
"ACYCLIC";
147 case ACYCLIC_FOR_INDIRECT_RECOVERY:
148 str_coloring=
"ACYCLIC_FOR_INDIRECT_RECOVERY";
153 case RESTRICTED_STAR:
154 str_coloring=
"RESTRICTED_STAR";
157 str_coloring=
"DISTANCE_TWO";
161 Color->Coloring(str_ordering, str_coloring);
163 std::vector<int32_t> vi_VertexColors;
164 Color->GetVertexColors(vi_VertexColors);
166 REQUIRE(vi_VertexColors.size()==
static_cast<uint32_t
>(m_dimension),
167 "dimension mismatch, %d vs %d!\n", vi_VertexColors.size(), m_dimension);
169 m_coloring_vector=SGVector<int32_t>(vi_VertexColors.size());
171 for (std::vector<int32_t>::iterator it=vi_VertexColors.begin();
172 it!=vi_VertexColors.end(); it++)
175 m_coloring_vector[i]=*it;
178 Map<VectorXi> colors(m_coloring_vector.vector, m_coloring_vector.vlen);
179 m_num_samples=colors.maxCoeff()+1;
180 SG_DEBUG(
"Using %d samples (aka colours) for probing trace sampler\n",
187 m_is_precomputed=
true;
192 SGVector<float64_t> CProbingSampler::sample(
index_t idx)
const
194 REQUIRE(idx<m_num_samples,
"Given index (%d) must be smaller than "
195 "number of samples to draw (%d)\n", idx, m_num_samples);
197 SGVector<float64_t> s(m_dimension);
200 for (
index_t i=0; i<m_dimension; ++i)
202 if (m_coloring_vector[i]==idx)
214 #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