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 typedef struct { size_t i
; size_t I
; } _iI_type
;
39 std::vector
<Factor
> _pancakes
; // used by all LC types (psi_I is stored in the pancake)
40 std::vector
<Factor
> _cavitydists
; // used by all LC types to store the approximate cavity distribution
41 /// _phis[VV2E(i,I)] corresponds to \f$ \phi^{\setminus i}_I(x_{I \setminus i}) \f$
42 std::vector
<Factor
> _phis
;
44 /// Single variable beliefs
45 std::vector
<Factor
> _beliefs
;
47 /// For each pair (i,j) with j in delta(i), store i and the common factor I
48 std::vector
<_iI_type
> _iI
;
51 ENUM6(CavityType
,FULL
,PAIR
,PAIR2
,PAIRINT
,PAIRCUM
,UNIFORM
)
52 ENUM3(UpdateType
,SEQFIX
,SEQRND
,NONE
)
54 CavityType
Cavity() const { return GetPropertyAs
<CavityType
>("cavity"); }
55 UpdateType
Updates() const { return GetPropertyAs
<UpdateType
>("updates"); }
56 bool reInit() const { return GetPropertyAs
<bool>("reinit"); }
58 /// Default constructor
61 LC(const LC
& x
) : DAIAlgFG(x
), _pancakes(x
._pancakes
), _cavitydists(x
._cavitydists
), _phis(x
._phis
), _beliefs(x
._beliefs
), _iI(x
._iI
) {};
63 LC
* clone() const { return new LC(*this); }
64 /// Construct LC object from a FactorGraph and parameters
65 LC(const FactorGraph
& fg
, const Properties
&opts
);
66 /// Assignment operator
67 LC
& operator=(const LC
& x
) {
69 DAIAlgFG::operator=(x
);
70 _pancakes
= x
._pancakes
;
71 _cavitydists
= x
._cavitydists
;
73 _beliefs
= x
._beliefs
;
79 static const char *Name
;
80 double CalcCavityDist( size_t i
, const std::string
&name
, const Properties
&opts
);
81 double InitCavityDists( const std::string
&name
, const Properties
&opts
);
82 long SetCavityDists( std::vector
<Factor
> &Q
);
85 Factor
NewPancake (size_t iI
, bool & hasNaNs
);
88 std::string
identify() const;
89 Factor
belief (const Var
&n
) const { return( _beliefs
[findVar(n
)] ); }
90 Factor
belief (const VarSet
&/*ns*/) const { assert( 0 == 1 ); }
91 std::vector
<Factor
> beliefs() const { return _beliefs
; }
92 Complex
logZ() const { return NAN
; }
93 void CalcBelief (size_t i
);
94 const Factor
& belief (size_t i
) const { return _beliefs
[i
]; };
95 const Factor
& pancake (size_t i
) const { return _pancakes
[i
]; };
96 const Factor
& cavitydist (size_t i
) const { return _cavitydists
[i
]; };
97 size_t nr_iI() const { return _iI
.size(); };
99 void clamp( const Var
&/*n*/, size_t /*i*/ ) { assert( 0 == 1 ); }
100 void undoProbs( const VarSet
&/*ns*/ ) { assert( 0 == 1 ); }
101 void saveProbs( const VarSet
&/*ns*/ ) { assert( 0 == 1 ); }
102 void makeFactorCavity(size_t /*I*/) { assert( 0 == 1 ); }
103 virtual void makeCavity(const Var
& /*n*/) { assert( 0 == 1 ); }
104 bool checkProperties();
108 } // end of namespace dai