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_treeep_h
23 #define __defined_libdai_treeep_h
28 #include <dai/daialg.h>
29 #include <dai/varset.h>
30 #include <dai/regiongraph.h>
31 #include <dai/factorgraph.h>
32 #include <dai/clustergraph.h>
33 #include <dai/weightedgraph.h>
34 #include <dai/jtree.h>
43 std::vector
<Factor
> _Qa
;
44 std::vector
<Factor
> _Qb
;
46 std::vector
<size_t> _a
; // _Qa[alpha] <-> superTree._Qa[_a[alpha]]
47 std::vector
<size_t> _b
; // _Qb[beta] <-> superTree._Qb[_b[beta]]
48 // _Qb[beta] <-> _RTree[beta]
56 TreeEPSubTree() : _Qa(), _Qb(), _RTree(), _a(), _b(), _I(NULL
), _ns(), _nsrem(), _logZ(0.0) {}
57 TreeEPSubTree( const TreeEPSubTree
&x
) : _Qa(x
._Qa
), _Qb(x
._Qb
), _RTree(x
._RTree
), _a(x
._a
), _b(x
._b
), _I(x
._I
), _ns(x
._ns
), _nsrem(x
._nsrem
), _logZ(x
._logZ
) {}
58 TreeEPSubTree
& operator=( const TreeEPSubTree
& x
) {
73 TreeEPSubTree( const DEdgeVec
&subRTree
, const DEdgeVec
&jt_RTree
, const std::vector
<Factor
> &jt_Qa
, const std::vector
<Factor
> &jt_Qb
, const Factor
*I
);
75 void InvertAndMultiply( const std::vector
<Factor
> &Qa
, const std::vector
<Factor
> &Qb
);
76 void HUGIN_with_I( std::vector
<Factor
> &Qa
, std::vector
<Factor
> &Qb
);
77 double logZ( const std::vector
<Factor
> &Qa
, const std::vector
<Factor
> &Qb
) const;
78 const Factor
*& I() { return _I
; }
82 class TreeEP
: public JTree
{
84 std::map
<size_t, TreeEPSubTree
> _Q
;
87 ENUM2(TypeType
,ORG
,ALT
)
88 TypeType
Type() const { return GetPropertyAs
<TypeType
>("type"); }
90 TreeEP() : JTree(), _Q() {};
91 TreeEP( const TreeEP
& x
) : JTree(x
), _Q(x
._Q
) {
92 for( size_t I
= 0; I
< nrFactors(); I
++ )
94 _Q
[I
].I() = &factor(I
);
96 TreeEP
* clone() const { return new TreeEP(*this); }
97 TreeEP
& operator=( const TreeEP
& x
) {
101 for( size_t I
= 0; I
< nrFactors(); I
++ )
103 _Q
[I
].I() = &factor(I
);
107 TreeEP( const FactorGraph
&fg
, const Properties
&opts
);
108 void ConstructRG( const DEdgeVec
&tree
);
110 static const char *Name
;
111 std::string
identify() const;
114 Complex
logZ() const;
116 bool offtree(size_t I
) const { return !_fac2OR
.count(I
); }
118 void init( const VarSet
&/*ns*/ ) { init(); }
119 void undoProbs( const VarSet
&ns
) { RegionGraph::undoProbs( ns
); init( ns
); }
120 bool checkProperties();
124 } // end of namespace dai