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>
38 template<
class _GM,
class _ACC>
56 std::string
name()
const;
59 template<
class VISITOR>
62 void setStartingPoint(
typename std::vector<LabelType>::const_iterator begin );
64 const GraphicalModelType& gm_;
66 HigherOrderEnergy<ValueType, 10> hoe_;
67 std::vector<LabelType> conf_;
71 template<
class GM,
class ACC>
77 for (
size_t i=0; i<gm_.numberOfVariables(); ++i)
78 conf_[i] = *(begin+i);
81 template<
class GM,
class ACC>
87 : gm_(gm), constV_(0.0), conf_(std::vector<LabelType>(gm.numberOfVariables(),0))
89 hoe_.AddVars(gm_.numberOfVariables());
90 for (
IndexType f = 0; f < gm_.numberOfFactors(); ++f)
92 IndexType size = gm_[f].numberOfVariables();
97 constV_ += gm_[f](&l0);
105 hoe_.AddUnaryTerm(var, e1 - e0);
109 unsigned int numAssignments = 1 << size;
112 for (
unsigned int subset = 1; subset < numAssignments; ++subset)
120 for (
unsigned int assignment = 0; assignment < numAssignments; ++assignment)
122 for (
unsigned int i = 0; i < size; ++i)
124 if (assignment & (1 << i))
126 cliqueLabels[i] = l1;
130 cliqueLabels[i] = l0;
134 for (
unsigned int subset = 1; subset < numAssignments; ++subset)
136 if (assignment & ~subset)
143 for (
unsigned int b = 0; b < size; ++b)
145 parity ^= (((assignment ^ subset) & (1 << b)) != 0);
147 coeffs[subset] += parity ? -energy : energy;
151 typename HigherOrderEnergy<ValueType, 10>::VarId vars[10];
152 for (
unsigned int subset = 1; subset < numAssignments; ++subset)
155 for (
unsigned int b = 0; b < size; ++b)
157 if (subset & (1 << b))
159 vars[degree++] = gm_[f].variableIndex(b);
162 std::sort(vars, vars + degree);
163 hoe_.AddTerm(coeffs[subset], degree, vars);
169 template<
class GM,
class ACC>
176 template<
class GM,
class ACC>
183 template<
class GM,
class ACC>
190 template<
class GM,
class ACC>
191 template<
class VISITOR>
195 visitor.begin(*
this);
196 kolmogorov::qpbo::QPBO<ValueType> qr(gm_.numberOfVariables(), 0);
197 hoe_.ToQuadratic(qr);
200 for (
IndexType i = 0; i < gm_.numberOfVariables(); ++i)
202 int label = qr.GetLabel(i);
216 bound_ = constV_ + 0.5 * qr.ComputeTwiceLowerBound();
221 template<
class GM,
class ACC>
225 std::vector<LabelType>&
arg,
233 arg.resize(gm_.numberOfVariables());
234 for (
IndexType i = 0; i < gm_.numberOfVariables(); ++i)
243 #endif // #ifndef OPENGM_HQPBO_HXX
visitors::VerboseVisitor< HQPBO< GM, ACC > > VerboseVisitorType
void setStartingPoint(typename std::vector< LabelType >::const_iterator begin)
const GraphicalModelType & graphicalModel() const
GraphicalModelType::IndexType IndexType
visitors::TimingVisitor< HQPBO< GM, ACC > > TimingVisitorType
InferenceTermination arg(std::vector< LabelType > &, const size_t &=1) const
GraphicalModelType::ValueType ValueType
Inference algorithm interface.
HQPBO(const GraphicalModelType &, Parameter=Parameter())
GraphicalModelType::LabelType LabelType
visitors::EmptyVisitor< HQPBO< GM, ACC > > EmptyVisitorType
InferenceTermination infer()