1 /* Copyright (C) 2006-2008 Joris Mooij [j dot mooij at science dot ru dot nl]
2 Radboud University Nijmegen, The Netherlands
4 This file is part of libDAI.
6 libDAI is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 libDAI is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with libDAI; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #ifndef __defined_libdai_lc_h
23 #define __defined_libdai_lc_h
27 #include <dai/daialg.h>
29 #include <dai/factorgraph.h>
35 class LC
: public DAIAlgFG
{
37 std::vector
<Factor
> _pancakes
; // used by all LC types (psi_I is stored in the pancake)
38 std::vector
<Factor
> _cavitydists
; // used by all LC types to store the approximate cavity distribution
39 /// _phis[i][_I] corresponds to \f$ \phi^{\setminus i}_I(x_{I \setminus i}) \f$
40 std::vector
<std::vector
<Factor
> > _phis
;
42 /// Single variable beliefs
43 std::vector
<Factor
> _beliefs
;
46 ENUM6(CavityType
,FULL
,PAIR
,PAIR2
,PAIRINT
,PAIRCUM
,UNIFORM
)
47 ENUM3(UpdateType
,SEQFIX
,SEQRND
,NONE
)
49 CavityType
Cavity() const { return GetPropertyAs
<CavityType
>("cavity"); }
50 UpdateType
Updates() const { return GetPropertyAs
<UpdateType
>("updates"); }
51 bool reInit() const { return GetPropertyAs
<bool>("reinit"); }
53 /// Default constructor
56 LC(const LC
& x
) : DAIAlgFG(x
), _pancakes(x
._pancakes
), _cavitydists(x
._cavitydists
), _phis(x
._phis
), _beliefs(x
._beliefs
) {};
58 LC
* clone() const { return new LC(*this); }
59 /// Construct LC object from a FactorGraph and parameters
60 LC(const FactorGraph
& fg
, const Properties
&opts
);
61 /// Assignment operator
62 LC
& operator=(const LC
& x
) {
64 DAIAlgFG::operator=(x
);
65 _pancakes
= x
._pancakes
;
66 _cavitydists
= x
._cavitydists
;
68 _beliefs
= x
._beliefs
;
73 static const char *Name
;
74 double CalcCavityDist( size_t i
, const std::string
&name
, const Properties
&opts
);
75 double InitCavityDists( const std::string
&name
, const Properties
&opts
);
76 long SetCavityDists( std::vector
<Factor
> &Q
);
79 Factor
NewPancake (size_t i
, size_t _I
, bool & hasNaNs
);
82 std::string
identify() const;
83 Factor
belief (const Var
&n
) const { return( _beliefs
[findVar(n
)] ); }
84 Factor
belief (const VarSet
&/*ns*/) const { assert( 0 == 1 ); return Factor(); }
85 std::vector
<Factor
> beliefs() const { return _beliefs
; }
86 Complex
logZ() const { /*assert( 0 == 1 );*/ return 0.0; }
87 void CalcBelief (size_t i
);
88 const Factor
& belief (size_t i
) const { return _beliefs
[i
]; };
89 const Factor
& pancake (size_t i
) const { return _pancakes
[i
]; };
90 const Factor
& cavitydist (size_t i
) const { return _cavitydists
[i
]; };
92 void clamp( const Var
&/*n*/, size_t /*i*/ ) { assert( 0 == 1 ); }
93 void undoProbs( const VarSet
&/*ns*/ ) { assert( 0 == 1 ); }
94 void saveProbs( const VarSet
&/*ns*/ ) { assert( 0 == 1 ); }
95 virtual void makeCavity(const Var
& /*n*/) { assert( 0 == 1 ); }
96 bool checkProperties();
100 } // end of namespace dai