2 #ifndef OPENGM_HQPBO_HXX
3 #define OPENGM_HQPBO_HXX
13 #include "opengm/inference/fix-fusion/fusion-move.hpp"
21 template<
class GM,
class ACC>
35 std::string
name()
const;
38 template<
class VISITOR>
41 void setStartingPoint(
typename std::vector<LabelType>::const_iterator begin );
43 const GraphicalModelType& gm_;
45 HigherOrderEnergy<ValueType, 10> hoe_;
46 std::vector<LabelType> conf_;
50 template<
class GM,
class ACC>
56 for (
size_t i=0; i<gm_.numberOfVariables(); ++i)
57 conf_[i] = *(begin+i);
60 template<
class GM,
class ACC>
66 : gm_(gm), constV_(0.0), conf_(std::vector<LabelType>(gm.numberOfVariables(),0))
68 hoe_.AddVars(gm_.numberOfVariables());
69 for (
IndexType f = 0; f < gm_.numberOfFactors(); ++f)
71 IndexType size = gm_[f].numberOfVariables();
76 constV_ += gm_[f](&l0);
84 hoe_.AddUnaryTerm(var, e1 - e0);
88 unsigned int numAssignments = 1 << size;
90 for (
unsigned int subset = 1; subset < numAssignments; ++subset)
97 for (
unsigned int assignment = 0; assignment < numAssignments; ++assignment)
99 for (
unsigned int i = 0; i < size; ++i)
101 if (assignment & (1 << i))
103 cliqueLabels[i] = l1;
107 cliqueLabels[i] = l0;
111 for (
unsigned int subset = 1; subset < numAssignments; ++subset)
113 if (assignment & ~subset)
120 for (
unsigned int b = 0; b < size; ++b)
122 parity ^= (((assignment ^ subset) & (1 << b)) != 0);
124 coeffs[subset] += parity ? -energy : energy;
128 typename HigherOrderEnergy<ValueType, 10>::VarId vars[10];
129 for (
unsigned int subset = 1; subset < numAssignments; ++subset)
132 for (
unsigned int b = 0; b < size; ++b)
134 if (subset & (1 << b))
136 vars[degree++] = gm_[f].variableIndex(b);
139 std::sort(vars, vars + degree);
140 hoe_.AddTerm(coeffs[subset], degree, vars);
146 template<
class GM,
class ACC>
153 template<
class GM,
class ACC>
160 template<
class GM,
class ACC>
167 template<
class GM,
class ACC>
168 template<
class VISITOR>
172 visitor.begin(*
this);
173 kolmogorov::qpbo::QPBO<ValueType> qr(gm_.numberOfVariables(), 0);
174 hoe_.ToQuadratic(qr);
177 for (
IndexType i = 0; i < gm_.numberOfVariables(); ++i)
179 int label = qr.GetLabel(i);
193 bound_ = constV_ + 0.5 * qr.ComputeTwiceLowerBound();
198 template<
class GM,
class ACC>
202 std::vector<LabelType>& arg,
210 arg.resize(gm_.numberOfVariables());
211 for (
IndexType i = 0; i < gm_.numberOfVariables(); ++i)
220 #endif // #ifndef OPENGM_HQPBO_HXX
const GraphicalModelType & graphicalModel() const
visitors::VerboseVisitor< HQPBO< GM, ACC > > VerboseVisitorType
void setStartingPoint(typename std::vector< LabelType >::const_iterator begin)
set initial labeling
InferenceTermination arg(std::vector< LabelType > &, const size_t &=1) const
GraphicalModelType::IndexType IndexType
visitors::TimingVisitor< HQPBO< GM, ACC > > TimingVisitorType
GraphicalModelType::ValueType ValueType
Inference algorithm interface.
HQPBO(const GraphicalModelType &, Parameter=Parameter())
GraphicalModelType::LabelType LabelType
visitors::EmptyVisitor< HQPBO< GM, ACC > > EmptyVisitorType
InferenceTermination infer()