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>
35 #include <dai/properties.h>
44 std::vector
<Factor
> _Qa
;
45 std::vector
<Factor
> _Qb
;
47 std::vector
<size_t> _a
; // _Qa[alpha] <-> superTree._Qa[_a[alpha]]
48 std::vector
<size_t> _b
; // _Qb[beta] <-> superTree._Qb[_b[beta]]
49 // _Qb[beta] <-> _RTree[beta]
57 TreeEPSubTree() : _Qa(), _Qb(), _RTree(), _a(), _b(), _I(NULL
), _ns(), _nsrem(), _logZ(0.0) {}
58 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
) {}
59 TreeEPSubTree
& operator=( const TreeEPSubTree
& x
) {
74 TreeEPSubTree( const DEdgeVec
&subRTree
, const DEdgeVec
&jt_RTree
, const std::vector
<Factor
> &jt_Qa
, const std::vector
<Factor
> &jt_Qb
, const Factor
*I
);
76 void InvertAndMultiply( const std::vector
<Factor
> &Qa
, const std::vector
<Factor
> &Qb
);
77 void HUGIN_with_I( std::vector
<Factor
> &Qa
, std::vector
<Factor
> &Qb
);
78 double logZ( const std::vector
<Factor
> &Qa
, const std::vector
<Factor
> &Qb
) const;
79 const Factor
*& I() { return _I
; }
83 class TreeEP
: public JTree
{
85 std::map
<size_t, TreeEPSubTree
> _Q
;
92 DAI_ENUM(TypeType
,ORG
,ALT
)
98 /// Default constructor
99 TreeEP() : JTree(), _Q(), props(), maxdiff() {};
101 TreeEP( const TreeEP
& x
) : JTree(x
), _Q(x
._Q
), props(x
.props
), maxdiff(x
.maxdiff
) {
102 for( size_t I
= 0; I
< nrFactors(); I
++ )
104 _Q
[I
].I() = &factor(I
);
106 TreeEP
* clone() const { return new TreeEP(*this); }
107 TreeEP
& operator=( const TreeEP
& x
) {
111 for( size_t I
= 0; I
< nrFactors(); I
++ )
113 _Q
[I
].I() = &factor(I
);
119 TreeEP( const FactorGraph
&fg
, const PropertySet
&opts
);
120 void ConstructRG( const DEdgeVec
&tree
);
122 static const char *Name
;
123 std::string
identify() const;
128 bool offtree( size_t I
) const { return (fac2OR
[I
] == -1U); }
130 void init( const VarSet
&/*ns*/ ) { init(); }
131 void undoProbs( const VarSet
&ns
) { RegionGraph::undoProbs( ns
); init( ns
); }
133 void setProperties( const PropertySet
&opts
);
134 PropertySet
getProperties() const;
135 double maxDiff() const { return maxdiff
; }
139 } // end of namespace dai