OpenGM  2.3.x
Discrete Graphical Model Library
generate_starting_point.hxx
Go to the documentation of this file.
1 #include <vector>
2 
3 #include <opengm/opengm.hxx>
5 
6 namespace opengm{
7 
15  template<class GM>
17  const GM & gm,
18  std::vector<typename GM::ValueType> & lambdas,
19  std::vector<typename GM::LabelType> & resultArg,
20  const typename GM::ValueType threshold=0.0
21  ){
22  typedef typename GM::IndexType IndexType;
23  typedef typename GM::LabelType LabelType;
24  typedef typename GM::ValueType ValueType;
25 
26  resultArg.resize(gm.numberOfVariables());
27 
28 
29 
30  Partition<IndexType> ufd(gm.numberOfVariables());
31 
32  for(IndexType fi=0;fi<gm.numberOfFactors();++fi){
33  OPENGM_CHECK_OP(gm[fi].numberOfVariables(),==,2,"");
34 
35  const IndexType vi0 =gm[fi].variableIndex(0);
36  const IndexType vi1 =gm[fi].variableIndex(1);
37  if(lambdas[fi]>threshold){
38  ufd.merge(vi0,vi1);
39  }
40  }
41 
42  std::map<IndexType,IndexType> representativeLabeling;
43 
44  ufd.representativeLabeling(representativeLabeling);
45 
46  for(IndexType vi=0;vi<gm.numberOfVariables();++vi){
47  const IndexType find=ufd.find(vi);
48  const IndexType dense=representativeLabeling[find];
49  resultArg[vi]=dense;
50  }
51 
52  }
53 
54 }
55 
56 // kate: space-indent on; indent-width 4; replace-tabs on; indent-mode cstyle; remove-trailing-space; replace-trailing-spaces-save;
The OpenGM namespace.
Definition: config.hxx:43
#define OPENGM_CHECK_OP(A, OP, B, TXT)
Definition: submodel2.hxx:24
Disjoint set data structure with path compression.
Definition: partition.hxx:13
void startFromThreshold(const GM &gm, std::vector< typename GM::ValueType > &lambdas, std::vector< typename GM::LabelType > &resultArg, const typename GM::ValueType threshold=0.0)