libDAI
decmap.h
Go to the documentation of this file.
1 /* This file is part of libDAI - http://www.libdai.org/
2  *
3  * Copyright (c) 2006-2011, The libDAI authors. All rights reserved.
4  *
5  * Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
6  */
7 
8 
11 
12 
13 #ifndef __defined_libdai_decmap_h
14 #define __defined_libdai_decmap_h
15 
16 
17 #include <dai/dai_config.h>
18 #ifdef DAI_WITH_DECMAP
19 
20 
21 #include <dai/daialg.h>
22 
23 
24 namespace dai {
25 
26 
28 
32 class DecMAP : public DAIAlgFG {
33  private:
35  std::vector<size_t> _state;
37  Real _logp;
39  Real _maxdiff;
41  size_t _iters;
42 
43  public:
45  struct Properties {
47  size_t verbose;
48 
50  bool reinit;
51 
53  std::string ianame;
54 
56  PropertySet iaopts;
57  } props;
58 
59  public:
61  DecMAP() : DAIAlgFG(), _state(), _logp(), _maxdiff(), _iters(), props() {}
62 
64 
67  DecMAP( const FactorGraph &fg, const PropertySet &opts );
68 
69 
71 
72  virtual DecMAP* clone() const { return new DecMAP(*this); }
73  virtual DecMAP* construct( const FactorGraph &fg, const PropertySet &opts ) const { return new DecMAP( fg, opts ); }
74  virtual std::string name() const { return "DECMAP"; }
75  virtual Factor belief( const Var &v ) const { return beliefV( findVar( v ) ); }
76  virtual Factor belief( const VarSet &/*vs*/ ) const;
77  virtual Factor beliefV( size_t i ) const;
78  virtual Factor beliefF( size_t I ) const { return belief( factor(I).vars() ); }
79  virtual std::vector<Factor> beliefs() const;
80  virtual Real logZ() const { return _logp; }
81  virtual std::vector<size_t> findMaximum() const { return _state; }
82  virtual void init() { _maxdiff = 0.0; _iters = 0; }
83  virtual void init( const VarSet &/*ns*/ ) { init(); }
84  virtual Real run();
85  virtual Real maxDiff() const { return _maxdiff; }
86  virtual size_t Iterations() const { return _iters; }
87  virtual void setProperties( const PropertySet &opts );
88  virtual PropertySet getProperties() const;
89  virtual std::string printProperties() const;
91 };
92 
93 
94 } // end of namespace dai
95 
96 
97 #endif
98 
99 
100 #endif
TFactor< Real > Factor
Represents a factor with values of type dai::Real.
Definition: factor.h:640
double Real
Real number (alias for double, which could be changed to long double if necessary) ...
Definition: util.h:98
std::vector< size_t > findMaximum(const InfAlg &obj)
Calculates the joint state of all variables that has maximum probability, according to the inference ...
Definition: daialg.cpp:211
DAIAlg< FactorGraph > DAIAlgFG
Base class for inference algorithms that operate on a FactorGraph.
Definition: daialg.h:263
Namespace for libDAI.
Definition: alldai.cpp:16
Defines the general interface for inference methods in libDAI (classes InfAlg, DaiAlg<>, DaiAlgFG and DaiAlgRG).
Allows the user to specify which algorithms will be built into libDAI.