22 template<
class GM,
class INF>
27 typedef typename INF::AccumulationType
ACC;
53 std::string
name()
const;
57 template<
class VisitorType>
66 const GraphicalModelType& gm_;
70 std::vector<LabelType> arg_;
73 template<
class GM,
class INF>
77 const GraphicalModelType& gm,
83 arg_(gm.numberOfVariables(), 0) {
89 template<
class GM,
class INF>
96 template<
class GM,
class INF>
104 template<
class GM,
class INF>
111 template<
class GM,
class INF>
118 template<
class GM,
class INF>
127 template<
class GM,
class INF>
128 template<
class VisitorType>
135 visitor.begin(*
this);
143 for(
size_t fi=0; fi< gm_.numberOfFactors(); ++fi){
144 if(gm_[fi].numberOfVariables()==2){
146 const ValueType val00 = gm_[fi](lAA);
147 const ValueType val01 = gm_[fi](lAB);
148 const ValueType weight = val01 - val00;
150 if(weight>param_.threshold_){
151 const size_t vi0 = gm_[fi].variableIndex(0);
152 const size_t vi1 = gm_[fi].variableIndex(1);
161 if(ufd.numberOfSets() == 1){
164 typedef typename INF:: template rebind<GM,ACC>::type OrgInf;
165 typename OrgInf::Parameter orgInfParam(param_.infParam_);
166 OrgInf orgInf(gm_, orgInfParam);
169 value_ = gm_.evaluate(arg_);
173 std::map<LabelType, LabelType> repr;
174 ufd.representativeLabeling(repr);
178 std::vector< std::vector< LabelType> > subVar(ufd.numberOfSets());
180 for(
size_t vi=0; vi<gm_.numberOfVariables(); ++vi){
181 subVar[repr[ufd.find(vi)]].push_back(vi);
184 const size_t nSubProb = subVar.size();
186 std::vector<unsigned char> usedFactors_(gm_.numberOfFactors(),0);
190 for(
size_t fi=0; fi< gm_.numberOfFactors(); ++fi){
192 ufd.find(gm_[fi].variableIndex(0))
194 ufd.find(gm_[fi].variableIndex(1))
197 usedFactors_[fi] = 1;
201 std::vector<IndexType> globalToLocal(gm_.numberOfVariables(), gm_.numberOfVariables()+1);
204 for(
size_t subProb = 0; subProb<nSubProb; ++subProb){
207 const IndexType nSubVar = subVar[subProb].size();
213 Space space(nSubVar, nSubVar);
216 for(
IndexType lvi=0; lvi<nSubVar; ++lvi){
217 const IndexType gvi = subVar[subProb][lvi];
218 globalToLocal[gvi] = lvi;
223 const IndexType gvi = subVar[subProb][0];
227 const IndexType gvi0 = subVar[subProb][0];
228 const IndexType gvi1 = subVar[subProb][1];
234 for(
IndexType lvi=0; lvi<nSubVar; ++lvi){
235 const IndexType gvi = subVar[subProb][lvi];
238 const size_t nf = gm_.numberOfFactors(gvi);
240 for(
size_t f=0; f<nf; ++f){
241 const IndexType nfi = gm_.factorOfVariable(gvi, f);
242 if(usedFactors_[nfi] != 1){
243 usedFactors_[nfi] = 1;
246 const ValueType val00 = gm_[nfi](lAA);
247 const ValueType val01 = gm_[nfi](lAB);
248 const ValueType weight = val01 - val00;
249 const IndexType vi0 = gm_[nfi].variableIndex(0);
250 const IndexType vi1 = gm_[nfi].variableIndex(1);
252 if( ufd.find(vi0) != ufd.find(vi1)){
257 std::min(globalToLocal[vi0],globalToLocal[vi1]),
258 std::max(globalToLocal[vi0],globalToLocal[vi1])
260 const Pf pf(nSubVar, nSubVar, 0.0, weight);
261 subGm.addFactor(subGm.addFunction(pf), lvis, lvis+2);
267 typedef typename INF:: template rebind<Model,ACC>::type SubInf;
268 typename SubInf::Parameter subInfParam(param_.infParam_);
269 SubInf subInf(subGm, subInfParam);
272 std::vector<LabelType> subArg(subGm.numberOfVariables());
275 for(
IndexType lvi=0; lvi<nSubVar; ++lvi){
276 const IndexType gvi = subVar[subProb][lvi];
277 arg_[gvi] = subArg[lvi] + offset;
283 value_ = gm_.evaluate(arg_);
290 template<
class GM,
class INF>
294 std::vector<LabelType>& x,
299 x.resize(gm_.numberOfVariables());
300 for(
size_t j=0; j<x.size(); ++j) {
312 #endif // #ifndef OPENGM_DMC_HXX
INF::AccumulationType ACC
opengm::visitors::VerboseVisitor< DMC< GM, INF > > VerboseVisitorType
void merge(value_type, value_type)
Merge two sets.
Discrete space in which all variables have the same number of labels.
virtual ValueType value() const
return the solution (value)
Parameter(const ValueType threshold=ValueType(-0.000000001), const InfParam infParam=InfParam())
GraphicalModelType::IndexType IndexType
opengm::visitors::EmptyVisitor< DMC< GM, INF > > EmptyVisitorType
const GraphicalModelType & graphicalModel() const
InferenceTermination infer()
GraphicalModelType::ValueType ValueType
opengm::visitors::TimingVisitor< DMC< GM, INF > > TimingVisitorType
Inference algorithm interface.
virtual InferenceTermination arg(std::vector< LabelType > &, const size_t=1) const
output a solution
#define OPENGM_CHECK_OP(A, OP, B, TXT)
Potts function for two variables.
void setStartingPoint(typename std::vector< LabelType >::const_iterator)
set initial labeling
Disjoint set data structure with path compression.
GraphicalModelType::LabelType LabelType
DMC(const GraphicalModelType &, const Parameter &)