51 std::string
name()
const;
54 template<
class VISITOR>
58 typename GM::ValueType
bound()
const;
59 typename GM::ValueType
value()
const;
65 const GraphicalModelType&
gm_;
100 throw std::runtime_error(
"Error: Tables are not proportional");
104 gm_.numberOfVariables(),
105 gm_.numberOfLabels(0),
150 EmptyVisitorType visitor;
151 return this->
infer(visitor);
155 template<
class VISITOR>
157 visitor.begin(*
this);
162 std::vector<LabelType> result;
174 arg.resize(
gm_.numberOfVariables());
175 for(
IndexType i = 0; i <
gm_.numberOfVariables(); i++) {
192 std::vector<IndexType> factorId2pwId(
gm_.numberOfFactors(),std::numeric_limits<IndexType>::max());
193 for (
IndexType factorId=0;factorId<
gm_.numberOfFactors();++factorId)
194 if (
gm_[factorId].numberOfVariables()==2)
195 factorId2pwId[factorId]=pwId++;
197 for (
IndexType factorId=0;factorId<
gm_.numberOfFactors();++factorId)
199 const typename GM::FactorType& f=
gm_[factorId];
200 ValueType res=std::numeric_limits<ValueType>::infinity(), res1;
201 if (f.numberOfVariables()==1)
204 for (
LabelType label=0;label<
gm_.numberOfLabels(varId);++label)
210 if (
gm_[fId].numberOfVariables()==2)
212 OPENGM_ASSERT(factorId2pwId[fId]<std::numeric_limits<IndexType>::max());
213 if (
gm_[fId].variableIndex(0)==varId)
219 res=std::min(res,res1);
221 }
else if (f.numberOfVariables()==2)
223 pwId=factorId2pwId[factorId];
225 IndexType varId0=f.variableIndex(0),varId1=f.variableIndex(1);
226 for (
LabelType label0=0;label0<
gm_.numberOfLabels(varId0);++label0)
227 for (
LabelType label1=0;label1<
gm_.numberOfLabels(varId1);++label1)
229 std::vector<LabelType> labels(2); labels[0]=label0; labels[1]=label1;
231 res=std::min(res,res1);
253 for(
IndexType i = 1; i <
gm_.numberOfVariables(); i++) {
254 if(
gm_.numberOfLabels(i) != numLabels) {
263 labelCosts_ =
new fastPDLib::CV_Fast_PD::Real[
gm_.numberOfVariables() *
gm_.numberOfLabels(0)];
264 for(
IndexType i = 0; i <
gm_.numberOfVariables() *
gm_.numberOfLabels(0); i++) {
268 for(
IndexType i = 0; i <
gm_.numberOfVariables(); i++) {
271 if(
gm_.numberOfVariables(gmFactorIndex) == 1) {
283 if(
gm_.numberOfVariables(i) == 2) {
294 if(
gm_.numberOfVariables(i) == 2) {
295 pairs_[currentPair * 2] =
gm_[i].variableIndex(0);
296 pairs_[(currentPair * 2) + 1] =
gm_[i].variableIndex(1);
304 distance_ =
new fastPDLib::CV_Fast_PD::Real[
gm_.numberOfLabels(0) *
gm_.numberOfLabels(0)];
311 if(
gm_.numberOfVariables(i) == 2) {
328 if(
gm_.numberOfVariables(i) == 2) {
331 for(k = 0; k <
gm_.numberOfLabels(0); k++) {
333 for(l = 0; l <
gm_.numberOfLabels(0); l++) {
335 if((
gm_[i](index) != 0) && (
distance_[(l *
gm_.numberOfLabels(0)) + k] != 0)) {
336 double currentWeight =
static_cast<double>(
gm_[i](index)) /
static_cast<double>(
distance_[(l *
gm_.numberOfLabels(0)) + k]);
337 weights_[currentPair] =
static_cast<fastPDLib::CV_Fast_PD::Real
>(currentWeight);
345 if(l !=
gm_.numberOfLabels(0)) {
349 if(k ==
gm_.numberOfLabels(0)) {
362 if(
gm_.numberOfVariables(i) == 2) {
383 ReparametrizerType lpreparametrizer(
gm_);
385 typedef typename ReparametrizerType::RepaStorageType::uIterator uIterator;
389 for (
IndexType factorId=0;factorId<
gm_.numberOfFactors();++factorId)
390 if (
gm_[factorId].numberOfVariables()==2) ++pwNum;
395 for (
IndexType factorId=0;factorId<
gm_.numberOfFactors();++factorId)
397 if (
gm_[factorId].numberOfVariables()!=2)
continue;
400 std::pair<uIterator,uIterator> iter=reparametrization.getIterators(factorId,i);
403 for (;iter.first!=iter.second;++iter.first)
405 *iter.first=-mul*y[label*pwNum+pwId];
414 return pReparametrizer;
InferenceTermination arg(std::vector< LabelType > &, const size_t &=1) const
const GraphicalModelType & graphicalModel() const
fastPDLib::CV_Fast_PD * pdInference_
visitors::TimingVisitor< FastPD< GM > > TimingVisitorType
FastPD(const GraphicalModelType &gm, const Parameter ¶=Parameter())
GM::ValueType bound() const
return a bound on the solution
#define OPENGM_ASSERT(expression)
GM::ValueType value() const
return the solution (value)
LPReparametrisationStorage< GM > RepaStorageType
const GraphicalModelType & gm_
GraphicalModelType::IndexType IndexType
LPReparametrizer< GM, opengm::Minimizer > ReparametrizerType
FastPD FastPD inference algorithm class.
visitors::VerboseVisitor< FastPD< GM > > VerboseVisitorType
ReparametrizerType * getReparametrizer(const typename ReparametrizerType::Parameter ¶ms=typename ReparametrizerType::Parameter()) const
GraphicalModelType::ValueType ValueType
static T ineutral()
inverse neutral element (with return)
Inference algorithm interface.
opengm::Minimizer AccumulationType
InferenceTermination infer()
bool sameNumberOfLabels() const
static T neutral()
neutral element (with return)
size_t numberOfIterations_
number of iterations
visitors::EmptyVisitor< FastPD< GM > > EmptyVisitorType
fastPDLib::CV_Fast_PD::Real * labelCosts_
RepaStorageType & Reparametrization()
GraphicalModelType::LabelType LabelType
Minimization as a unary accumulation.
fastPDLib::CV_Fast_PD::Real * weights_
fastPDLib::CV_Fast_PD::Real * distance_