43 template<
class _GM,
class _ACC>
58 : numberOfIterations_(p.numberOfIterations_){
67 std::string
name()
const;
70 template<
class VISITOR>
74 typename GM::ValueType
bound()
const;
75 typename GM::ValueType
value()
const;
81 const GraphicalModelType&
gm_;
116 throw std::runtime_error(
"Error: Tables are not proportional");
120 gm_.numberOfVariables(),
121 gm_.numberOfLabels(0),
166 EmptyVisitorType visitor;
167 return this->
infer(visitor);
171 template<
class VISITOR>
173 visitor.begin(*
this);
178 std::vector<LabelType> result;
190 arg.resize(
gm_.numberOfVariables());
191 for(
IndexType i = 0; i <
gm_.numberOfVariables(); i++) {
208 std::vector<IndexType> factorId2pwId(
gm_.numberOfFactors(),std::numeric_limits<IndexType>::max());
209 for (
IndexType factorId=0;factorId<
gm_.numberOfFactors();++factorId)
210 if (
gm_[factorId].numberOfVariables()==2)
211 factorId2pwId[factorId]=pwId++;
213 for (
IndexType factorId=0;factorId<
gm_.numberOfFactors();++factorId)
215 const typename GM::FactorType& f=
gm_[factorId];
216 ValueType res=std::numeric_limits<ValueType>::infinity(), res1;
217 if (f.numberOfVariables()==1)
220 for (
LabelType label=0;label<
gm_.numberOfLabels(varId);++label)
226 if (
gm_[fId].numberOfVariables()==2)
228 OPENGM_ASSERT(factorId2pwId[fId]<std::numeric_limits<IndexType>::max());
229 if (
gm_[fId].variableIndex(0)==varId)
235 res=std::min(res,res1);
237 }
else if (f.numberOfVariables()==2)
239 pwId=factorId2pwId[factorId];
241 IndexType varId0=f.variableIndex(0),varId1=f.variableIndex(1);
242 for (
LabelType label0=0;label0<
gm_.numberOfLabels(varId0);++label0)
243 for (
LabelType label1=0;label1<
gm_.numberOfLabels(varId1);++label1)
245 std::vector<LabelType> labels(2); labels[0]=label0; labels[1]=label1;
247 res=std::min(res,res1);
269 for(
IndexType i = 1; i <
gm_.numberOfVariables(); i++) {
270 if(
gm_.numberOfLabels(i) != numLabels) {
279 labelCosts_ =
new fastPDLib::CV_Fast_PD::Real[
gm_.numberOfVariables() *
gm_.numberOfLabels(0)];
280 for(
IndexType i = 0; i <
gm_.numberOfVariables() *
gm_.numberOfLabels(0); i++) {
284 for(
IndexType i = 0; i <
gm_.numberOfVariables(); i++) {
287 if(
gm_.numberOfVariables(gmFactorIndex) == 1) {
299 if(
gm_.numberOfVariables(i) == 2) {
310 if(
gm_.numberOfVariables(i) == 2) {
311 pairs_[currentPair * 2] =
gm_[i].variableIndex(0);
312 pairs_[(currentPair * 2) + 1] =
gm_[i].variableIndex(1);
320 distance_ =
new fastPDLib::CV_Fast_PD::Real[
gm_.numberOfLabels(0) *
gm_.numberOfLabels(0)];
327 if(
gm_.numberOfVariables(i) == 2) {
344 if(
gm_.numberOfVariables(i) == 2) {
347 for(k = 0; k <
gm_.numberOfLabels(0); k++) {
349 for(l = 0; l <
gm_.numberOfLabels(0); l++) {
351 if((
gm_[i](index) != 0) && (
distance_[(l *
gm_.numberOfLabels(0)) + k] != 0)) {
352 double currentWeight =
static_cast<double>(
gm_[i](index)) /
static_cast<double>(
distance_[(l *
gm_.numberOfLabels(0)) + k]);
353 weights_[currentPair] =
static_cast<fastPDLib::CV_Fast_PD::Real
>(currentWeight);
361 if(l !=
gm_.numberOfLabels(0)) {
365 if(k ==
gm_.numberOfLabels(0)) {
378 if(
gm_.numberOfVariables(i) == 2) {
399 ReparametrizerType lpreparametrizer(
gm_);
401 typedef typename ReparametrizerType::RepaStorageType::uIterator uIterator;
405 for (
IndexType factorId=0;factorId<
gm_.numberOfFactors();++factorId)
406 if (
gm_[factorId].numberOfVariables()==2) ++pwNum;
411 for (
IndexType factorId=0;factorId<
gm_.numberOfFactors();++factorId)
413 if (
gm_[factorId].numberOfVariables()!=2)
continue;
416 std::pair<uIterator,uIterator> iter=reparametrization.getIterators(factorId,i);
419 for (;iter.first!=iter.second;++iter.first)
421 *iter.first=-mul*y[label*pwNum+pwId];
430 return pReparametrizer;
fastPDLib::CV_Fast_PD * pdInference_
visitors::TimingVisitor< FastPD< GM > > TimingVisitorType
const GraphicalModelType & graphicalModel() const
GM::ValueType value() const
return the solution (value)
FastPD(const GraphicalModelType &gm, const Parameter ¶=Parameter())
#define OPENGM_ASSERT(expression)
LPReparametrisationStorage< GM > RepaStorageType
ReparametrizerType * getReparametrizer(const typename ReparametrizerType::Parameter ¶ms=typename ReparametrizerType::Parameter()) const
const GraphicalModelType & gm_
GraphicalModelType::IndexType IndexType
bool sameNumberOfLabels() const
LPReparametrizer< GM, opengm::Minimizer > ReparametrizerType
FastPD FastPD inference algorithm class.
visitors::VerboseVisitor< FastPD< GM > > VerboseVisitorType
GraphicalModelType::ValueType ValueType
static T ineutral()
inverse neutral element (with return)
Inference algorithm interface.
opengm::Minimizer AccumulationType
InferenceTermination infer()
static T neutral()
neutral element (with return)
size_t numberOfIterations_
number of iterations
visitors::EmptyVisitor< FastPD< GM > > EmptyVisitorType
fastPDLib::CV_Fast_PD::Real * labelCosts_
GM::ValueType bound() const
return a bound on the solution
RepaStorageType & Reparametrization()
Minimization as a unary accumulation.
InferenceTermination arg(std::vector< LabelType > &, const size_t &=1) const
fastPDLib::CV_Fast_PD::Real * weights_
fastPDLib::CV_Fast_PD::Real * distance_