22 template<
class GM,
class INF>
27 typedef typename INF::AccumulationType
ACC;
53 std::string
name()
const;
57 template<
class VisitorType>
67 const GraphicalModelType& gm_;
71 std::vector<LabelType> arg_;
74 template<
class GM,
class INF>
78 const GraphicalModelType& gm,
84 arg_(gm.numberOfVariables(), 0) {
90 template<
class GM,
class INF>
97 template<
class GM,
class INF>
105 template<
class GM,
class INF>
112 template<
class GM,
class INF>
119 template<
class GM,
class INF>
128 template<
class GM,
class INF>
129 template<
class VisitorType>
136 visitor.begin(*
this);
144 for(
size_t fi=0; fi< gm_.numberOfFactors(); ++fi){
145 if(gm_[fi].numberOfVariables()==2){
151 if(weight>param_.threshold_){
152 const size_t vi0 = gm_[fi].variableIndex(0);
153 const size_t vi1 = gm_[fi].variableIndex(1);
162 if(ufd.numberOfSets() == 1){
165 typedef typename INF:: template rebind<GM,ACC>::type OrgInf;
166 typename OrgInf::Parameter orgInfParam(param_.infParam_);
167 OrgInf orgInf(gm_, orgInfParam);
170 value_ = gm_.evaluate(arg_);
174 std::map<LabelType, LabelType> repr;
175 ufd.representativeLabeling(repr);
179 std::vector< std::vector< LabelType> > subVar(ufd.numberOfSets());
181 for(
size_t vi=0; vi<gm_.numberOfVariables(); ++vi){
182 subVar[repr[ufd.find(vi)]].push_back(vi);
185 const size_t nSubProb = subVar.size();
187 std::vector<unsigned char> usedFactors_(gm_.numberOfFactors(),0);
191 for(
size_t fi=0; fi< gm_.numberOfFactors(); ++fi){
193 ufd.find(gm_[fi].variableIndex(0))
195 ufd.find(gm_[fi].variableIndex(1))
198 usedFactors_[fi] = 1;
202 std::vector<IndexType> globalToLocal(gm_.numberOfVariables(), gm_.numberOfVariables()+1);
205 for(
size_t subProb = 0; subProb<nSubProb; ++subProb){
208 const IndexType nSubVar = subVar[subProb].size();
214 Space space(nSubVar, nSubVar);
217 for(
IndexType lvi=0; lvi<nSubVar; ++lvi){
218 const IndexType gvi = subVar[subProb][lvi];
219 globalToLocal[gvi] = lvi;
224 const IndexType gvi = subVar[subProb][0];
228 const IndexType gvi0 = subVar[subProb][0];
229 const IndexType gvi1 = subVar[subProb][1];
235 for(
IndexType lvi=0; lvi<nSubVar; ++lvi){
236 const IndexType gvi = subVar[subProb][lvi];
239 const size_t nf = gm_.numberOfFactors(gvi);
241 for(
size_t f=0; f<nf; ++f){
242 const IndexType nfi = gm_.factorOfVariable(gvi, f);
243 if(usedFactors_[nfi] != 1){
244 usedFactors_[nfi] = 1;
250 const IndexType vi0 = gm_[nfi].variableIndex(0);
251 const IndexType vi1 = gm_[nfi].variableIndex(1);
253 if( ufd.find(vi0) != ufd.find(vi1)){
258 std::min(globalToLocal[vi0],globalToLocal[vi1]),
259 std::max(globalToLocal[vi0],globalToLocal[vi1])
261 const Pf pf(nSubVar, nSubVar, 0.0, weight);
262 subGm.addFactor(subGm.addFunction(pf), lvis, lvis+2);
268 typedef typename INF:: template rebind<Model,ACC>::type SubInf;
269 typename SubInf::Parameter subInfParam(param_.infParam_);
270 SubInf subInf(subGm, subInfParam);
273 std::vector<LabelType> subArg(subGm.numberOfVariables());
276 for(
IndexType lvi=0; lvi<nSubVar; ++lvi){
277 const IndexType gvi = subVar[subProb][lvi];
278 arg_[gvi] = subArg[lvi] + offset;
284 value_ = gm_.evaluate(arg_);
291 template<
class GM,
class INF>
295 std::vector<LabelType>& x,
300 x.resize(gm_.numberOfVariables());
301 for(
size_t j=0; j<x.size(); ++j) {
313 #endif // #ifndef OPENGM_DMC_HXX
virtual ValueType value() const
return the solution (value)
INF::AccumulationType ACC
opengm::visitors::VerboseVisitor< DMC< GM, INF > > VerboseVisitorType
Discrete space in which all variables have the same number of labels.
const GraphicalModelType & graphicalModel() const
Parameter(const ValueType threshold=ValueType(-0.000000001), const InfParam infParam=InfParam())
GraphicalModelType::IndexType IndexType
opengm::visitors::EmptyVisitor< DMC< GM, INF > > EmptyVisitorType
virtual InferenceTermination arg(std::vector< LabelType > &, const size_t=1) const
InferenceTermination infer()
GraphicalModelType::ValueType ValueType
opengm::visitors::TimingVisitor< DMC< GM, INF > > TimingVisitorType
Inference algorithm interface.
#define OPENGM_CHECK_OP(A, OP, B, TXT)
Potts function for two variables.
void setStartingPoint(typename std::vector< LabelType >::const_iterator)
Disjoint set data structure with path compression.
GraphicalModelType::LabelType LabelType
DMC(const GraphicalModelType &, const Parameter &)