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>
30 #include <dai/exceptions.h>
36 class LC
: public DAIAlgFG
{
38 std::vector
<Factor
> _pancakes
; // used by all LC types (psi_I is stored in the pancake)
39 std::vector
<Factor
> _cavitydists
; // used by all LC types to store the approximate cavity distribution
40 /// _phis[i][_I] corresponds to \f$ \phi^{\setminus i}_I(x_{I \setminus i}) \f$
41 std::vector
<std::vector
<Factor
> > _phis
;
43 /// Single variable beliefs
44 std::vector
<Factor
> _beliefs
;
47 ENUM6(CavityType
,FULL
,PAIR
,PAIR2
,PAIRINT
,PAIRCUM
,UNIFORM
)
48 ENUM3(UpdateType
,SEQFIX
,SEQRND
,NONE
)
50 CavityType
Cavity() const { return GetPropertyAs
<CavityType
>("cavity"); }
51 UpdateType
Updates() const { return GetPropertyAs
<UpdateType
>("updates"); }
52 bool reInit() const { return GetPropertyAs
<bool>("reinit"); }
54 /// Default constructor
57 LC(const LC
& x
) : DAIAlgFG(x
), _pancakes(x
._pancakes
), _cavitydists(x
._cavitydists
), _phis(x
._phis
), _beliefs(x
._beliefs
) {};
59 LC
* clone() const { return new LC(*this); }
60 /// Construct LC object from a FactorGraph and parameters
61 LC(const FactorGraph
& fg
, const Properties
&opts
);
62 /// Assignment operator
63 LC
& operator=(const LC
& x
) {
65 DAIAlgFG::operator=(x
);
66 _pancakes
= x
._pancakes
;
67 _cavitydists
= x
._cavitydists
;
69 _beliefs
= x
._beliefs
;
74 static const char *Name
;
75 double CalcCavityDist( size_t i
, const std::string
&name
, const Properties
&opts
);
76 double InitCavityDists( const std::string
&name
, const Properties
&opts
);
77 long SetCavityDists( std::vector
<Factor
> &Q
);
80 Factor
NewPancake (size_t i
, size_t _I
, bool & hasNaNs
);
83 std::string
identify() const;
84 Factor
belief (const Var
&n
) const { return( _beliefs
[findVar(n
)] ); }
85 Factor
belief (const VarSet
&/*ns*/) const {
86 DAI_THROW(NOT_IMPLEMENTED
);
89 std::vector
<Factor
> beliefs() const { return _beliefs
; }
91 DAI_THROW(NOT_IMPLEMENTED
);
94 void CalcBelief (size_t i
);
95 const Factor
& belief (size_t i
) const { return _beliefs
[i
]; };
96 const Factor
& pancake (size_t i
) const { return _pancakes
[i
]; };
97 const Factor
& cavitydist (size_t i
) const { return _cavitydists
[i
]; };
99 void clamp( const Var
&/*n*/, size_t /*i*/ ) {
100 DAI_THROW(NOT_IMPLEMENTED
);
102 void undoProbs( const VarSet
&/*ns*/ ) {
103 DAI_THROW(NOT_IMPLEMENTED
);
105 void saveProbs( const VarSet
&/*ns*/ ) {
106 DAI_THROW(NOT_IMPLEMENTED
);
108 virtual void makeCavity(const Var
& /*n*/) {
109 DAI_THROW(NOT_IMPLEMENTED
);
111 bool checkProperties();
115 } // end of namespace dai