7f7a671efe4e08810fc051615c8cb828db466022
1 /* This file is part of libDAI - http://www.libdai.org/
3 * Copyright (c) 2006-2011, The libDAI authors. All rights reserved.
5 * Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
10 /// \brief Defines class DecMAP, which constructs a MAP state by decimation
13 #ifndef __defined_libdai_decmap_h
14 #define __defined_libdai_decmap_h
17 #include <dai/daialg.h>
23 /// Approximate inference algorithm DecMAP, which constructs a MAP state by decimation
24 /** Decimation involves repeating the following two steps until no free variables remain:
25 * - run an approximate inference algorithm,
26 * - clamp the factor with the lowest entropy to its most probable state
28 class DecMAP
: public DAIAlgFG
{
30 /// Stores the final MAP state
31 std::vector
<size_t> _state
;
32 /// Stores the log probability of the MAP state
34 /// Maximum difference encountered so far
36 /// Number of iterations needed
40 /// Parameters for DecMAP
42 /// Verbosity (amount of output sent to stderr)
45 /// Complete or partial reinitialization of clamped subgraphs?
48 /// Name of the algorithm used to calculate the beliefs on clamped subgraphs
51 /// Parameters for the algorithm used to calculate the beliefs on clamped subgraphs
56 /// Default constructor
57 DecMAP() : DAIAlgFG(), _state(), _logp(), _maxdiff(), _iters(), props() {}
59 /// Construct from FactorGraph \a fg and PropertySet \a opts
60 /** \param fg Factor graph.
61 * \param opts Parameters @see Properties
63 DecMAP( const FactorGraph
&fg
, const PropertySet
&opts
);
66 /// \name General InfAlg interface
68 virtual DecMAP
* clone() const { return new DecMAP(*this); }
69 virtual DecMAP
* construct( const FactorGraph
&fg
, const PropertySet
&opts
) const { return new DecMAP( fg
, opts
); }
70 virtual std::string
name() const { return "DECMAP"; }
71 virtual Factor
belief( const Var
&v
) const { return beliefV( findVar( v
) ); }
72 virtual Factor
belief( const VarSet
&/*vs*/ ) const;
73 virtual Factor
beliefV( size_t i
) const;
74 virtual Factor
beliefF( size_t I
) const { return belief( factor(I
).vars() ); }
75 virtual std::vector
<Factor
> beliefs() const;
76 virtual Real
logZ() const { return _logp
; }
77 virtual std::vector
<size_t> findMaximum() const { return _state
; }
78 virtual void init() { _maxdiff
= 0.0; _iters
= 0; }
79 virtual void init( const VarSet
&/*ns*/ ) { init(); }
81 virtual Real
maxDiff() const { return _maxdiff
; }
82 virtual size_t Iterations() const { return _iters
; }
83 virtual void setProperties( const PropertySet
&opts
);
84 virtual PropertySet
getProperties() const;
85 virtual std::string
printProperties() const;
90 } // end of namespace dai