128 template <
typename T>
134 std::cout <<
" WITH LINEAR FIDELITY" <<
std::endl;
138 }
else if (mode == 1) {
140 std::cout <<
" WITH L2 FIDELITY" <<
std::endl;
144 }
else if (mode > 0 && mode < 1) {
146 std::cout <<
" WITH KULLBACK-LEIBLER FIDELITY SMOOTHING : " << mode
152 }
else if (mode == -1) {
154 std::cout <<
" WITH ALTERNATE L2 NORM : " << mode <<
std::endl;
159 }
else if (mode == 2) {
161 std::cout <<
" PARTITION MODE WITH SPATIAL INFORMATION : " << mode
168 std::cout <<
" UNKNOWN MODE, SWICTHING TO L2 FIDELITY" <<
std::endl;
180 template <
typename T>
182 const uint32_t n_edges,
184 std::vector<std::vector<T>>& observation,
185 const std::vector<uint32_t>& Eu,
186 const std::vector<uint32_t>& Ev,
187 const std::vector<T>& edgeWeight,
188 const std::vector<T>& nodeWeight,
189 std::vector<std::vector<T>>& solution,
191 const uint32_t cutoff,
194 const T weight_decay,
195 const float verbose) {
198 std::cout <<
"L0-CUT PURSUIT";
202 set_speed(cp, speed, weight_decay, verbose);
203 set_up_CP(cp, n_nodes, n_edges, nObs, observation, Eu, Ev, edgeWeight,
211 boost::get(boost::vertex_bundle, cp->
main_graph);
213 for (uint32_t ind_nod = 0; ind_nod < n_nodes; ind_nod++) {
214 for (uint32_t ind_dim = 0; ind_dim < nObs; ind_dim++) {
215 solution[ind_nod][ind_dim] =
216 vertex_attribute_map[*ite_nod].value[ind_dim];
227 template <
typename T>
229 const uint32_t n_edges,
231 std::vector<std::vector<T>>& observation,
232 const std::vector<uint32_t>& Eu,
233 const std::vector<uint32_t>& Ev,
234 const std::vector<T>& edgeWeight,
235 const std::vector<T>& nodeWeight,
236 std::vector<std::vector<T>>& solution,
237 std::vector<uint32_t>& in_component,
238 std::vector<std::vector<uint32_t>>& components,
240 const uint32_t cutoff,
243 const T weight_decay,
244 const float verbose) {
248 std::cout <<
"L0-CUT PURSUIT";
253 set_speed(cp, speed, weight_decay, verbose);
254 set_up_CP(cp, n_nodes, n_edges, nObs, observation, Eu, Ev, edgeWeight,
262 uint32_t n_nodes_red =
263 static_cast<uint32_t
>(boost::num_vertices(cp->
reduced_graph));
264 in_component.resize(n_nodes);
265 components.resize(n_nodes_red);
268 boost::get(boost::vertex_bundle, cp->
main_graph);
270 for (uint32_t ind_nod = 0; ind_nod < n_nodes; ind_nod++) {
271 for (uint32_t ind_dim = 0; ind_dim < nObs; ind_dim++) {
272 solution[ind_nod][ind_dim] =
273 vertex_attribute_map[*ite_nod].value[ind_dim];
280 for (uint32_t ind_nod_red = 0; ind_nod_red < n_nodes_red; ind_nod_red++) {
281 size_t component_size = cp->
components[ind_nod_red].size();
282 components[ind_nod_red] = std::vector<uint32_t>(component_size, 0);
283 for (
size_t ind_nod = 0; ind_nod < component_size; ind_nod++) {
284 components[ind_nod_red][ind_nod] =
static_cast<uint32_t
>(
285 vertex_index_map(cp->
components[ind_nod_red][ind_nod]));
288 ite_nod = boost::vertices(cp->
main_graph).first;
289 for (uint32_t ind_nod = 0; ind_nod < n_nodes; ind_nod++) {
290 in_component[ind_nod] = vertex_attribute_map[*ite_nod].in_component;
299 template <
typename T>
301 const uint32_t n_nodes,
302 const uint32_t n_edges,
304 const std::vector<std::vector<T>> observation,
305 const std::vector<uint32_t> Eu,
306 const std::vector<uint32_t> Ev,
307 const std::vector<T> edgeWeight,
308 const std::vector<T> nodeWeight) {
313 boost::get(boost::vertex_bundle, cp->
main_graph);
316 for (uint32_t ind_nod = 0; ind_nod < n_nodes; ind_nod++) {
318 for (uint32_t i_dim = 0; i_dim < nObs;
320 v_attribute.
observation[i_dim] = observation[ind_nod][i_dim];
322 v_attribute.
weight = nodeWeight[ind_nod];
324 vertex_attribute_map[*ite_nod++] = v_attribute;
328 boost::get(boost::edge_bundle, cp->
main_graph);
329 uint32_t true_ind_edg =
331 for (uint32_t ind_edg = 0; ind_edg < n_edges;
336 edgeWeight[ind_edg], true_ind_edg, edge_attribute_map)) {
345 template <
typename T>
348 const T weight_decay,
349 const float verbose) {
352 std::cout <<
"PARAMETERIZATION = SPECIAL SUPERPOINTGRAPH"
356 cp->
parameter.weight_decay = weight_decay;
365 std::cout <<
"PARAMETERIZATION = LUDICROUS SPEED" <<
std::endl;
368 cp->
parameter.weight_decay = weight_decay;
377 std::cout <<
"PARAMETERIZATION = FAST" <<
std::endl;
380 cp->
parameter.weight_decay = weight_decay;
386 }
else if (speed == 0) {
388 std::cout <<
"PARAMETERIZATION = SLOW" <<
std::endl;
391 cp->
parameter.weight_decay = weight_decay;
397 }
else if (speed == 1) {
399 std::cout <<
"PARAMETERIZATION = STANDARD" <<
std::endl;
402 cp->
parameter.weight_decay = weight_decay;
bool addDoubledge(Graph< T > &g, const VertexDescriptor< T > &source, const VertexDescriptor< T > &target, const T weight, uint32_t eIndex, EdgeAttributeMap< T > &edge_attribute_map, bool real=true)
void set_speed(CP::CutPursuit< T > *cp, const T speed, const T weight_decay, const float verbose)
boost::vec_adj_list_vertex_property_map< Graph< T >, Graph< T > *, VertexAttribute< T >, VertexAttribute< T > &, boost::vertex_bundle_t > VertexAttributeMap
typename boost::graph_traits< Graph< T > >::vertex_iterator VertexIterator
void cut_pursuit(const uint32_t n_nodes, const uint32_t n_edges, const uint32_t nObs, std::vector< std::vector< T >> &observation, const std::vector< uint32_t > &Eu, const std::vector< uint32_t > &Ev, const std::vector< T > &edgeWeight, const std::vector< T > &nodeWeight, std::vector< std::vector< T >> &solution, const T lambda, const uint32_t cutoff, const T mode, const T speed, const T weight_decay, const float verbose)
void set_up_CP(CP::CutPursuit< T > *cp, const uint32_t n_nodes, const uint32_t n_edges, const uint32_t nObs, const std::vector< std::vector< T >> observation, const std::vector< uint32_t > Eu, const std::vector< uint32_t > Ev, const std::vector< T > edgeWeight, const std::vector< T > nodeWeight)
typename boost::adjacency_list< boost::vecS, boost::vecS, boost::directedS, VertexAttribute< T >, EdgeAttribute< T > > Graph
typename boost::property_map< Graph< T >, boost::vertex_index_t >::type VertexIndexMap
boost::adj_list_edge_property_map< boost::directed_tag, EdgeAttribute< T >, EdgeAttribute< T > &, uint64_t, CP::EdgeAttribute< T >, boost::edge_bundle_t > EdgeAttributeMap
CP::CutPursuit< T > * create_CP(const T mode, const float verbose)
QTextStream & endl(QTextStream &stream)
CPparameter< T > parameter
std::vector< std::vector< VertexDescriptor< T > > > components
void compute_reduced_graph()
std::pair< std::vector< T >, std::vector< T > > run()
std::vector< T > observation