13 #ifndef __defined_libdai_regiongraph_h
14 #define __defined_libdai_regiongraph_h
115 RegionGraph(
const FactorGraph& fg,
const std::vector<VarSet>& ors,
const std::vector<Region>& irs,
const std::vector<std::pair<size_t,size_t> >& edges ) :
FactorGraph(), _G(), _ORs(), _IRs(), _fac2OR() {
151 size_t nrORs()
const {
return _ORs.size(); }
154 size_t nrIRs()
const {
return _IRs.size(); }
212 virtual void setFactor(
size_t I,
const Factor& newFactor,
bool backup =
false ) {
219 virtual void setFactors(
const std::map<size_t, Factor>& facs,
bool backup =
false ) {
222 for( std::map<size_t, Factor>::const_iterator fac = facs.begin(); fac != facs.end(); fac++ )
223 ns |= fac->second.vars();
234 DAI_THROW(NOT_IMPLEMENTED);
241 DAI_THROW(NOT_IMPLEMENTED);
249 std::stringstream ss;
258 DAI_THROW(NOT_IMPLEMENTED);
264 void construct(
const FactorGraph& fg,
const std::vector<VarSet>& ors,
const std::vector<Region>& irs,
const std::vector<std::pair<size_t,size_t> >& edges );
A RegionGraph combines a bipartite graph consisting of outer regions (type FRegion) and inner regions...
Definition: regiongraph.h:91
std::vector< Neighbor > Neighbors
Describes the set of neighbors of some node in a graph.
Definition: graph.h:92
std::vector< size_t > _fac2OR
Stores for each factor index the index of the outer region it belongs to.
Definition: regiongraph.h:103
const Neighbors & nbIR(size_t beta) const
Returns constant reference to the neighbors of inner region beta.
Definition: regiongraph.h:189
A Region is a set of variables with a counting number.
Definition: regiongraph.h:27
const Real & c() const
Returns constant reference to counting number.
Definition: regiongraph.h:40
const Region & IR(size_t beta) const
Returns constant reference to inner region beta.
Definition: regiongraph.h:168
virtual void ReadFromFile(const char *)
Reads a region graph from a file.
Definition: regiongraph.h:233
friend std::ostream & operator<<(std::ostream &os, const RegionGraph &rg)
Writes a region graph to an output stream.
Definition: regiongraph.cpp:218
const Neighbor & nb1(size_t i1, size_t _i2) const
Returns constant reference to the _i2 'th neighbor of node i1 of type 1.
Definition: bipgraph.h:87
Defines some utility functions for (weighted) undirected graphs, trees and rooted trees...
Represents a factor graph.
Definition: factorgraph.h:65
Region & IR(size_t beta)
Returns reference to inner region beta.
Definition: regiongraph.h:173
std::vector< FRegion > _ORs
The outer regions (corresponding to nodes of type 1)
Definition: regiongraph.h:97
double Real
Real number (alias for double, which could be changed to long double if necessary) ...
Definition: util.h:98
virtual RegionGraph * clone() const
Clone *this (virtual copy constructor)
Definition: regiongraph.h:146
RegionGraph(const FactorGraph &fg, const std::vector< VarSet > &ors, const std::vector< Region > &irs, const std::vector< std::pair< size_t, size_t > > &edges)
Constructs a region graph from a factor graph, a vector of outer regions, a vector of inner regions a...
Definition: regiongraph.h:115
const BipartiteGraph & DAG() const
Returns DAG structure of the region graph.
Definition: regiongraph.h:196
Represents the neighborhood structure of nodes in an undirected, bipartite graph. ...
Definition: bipgraph.h:45
size_t fac2OR(size_t I) const
Returns the index of the outer region to which the I 'th factor corresponds.
Definition: regiongraph.h:179
FRegion(const Factor &x, Real c)
Constructs from a factor and a counting number.
Definition: regiongraph.h:58
void constructCVM(const FactorGraph &fg, const std::vector< VarSet > &cl, size_t verbose=0)
Helper function for constructors (CVM style)
Definition: regiongraph.cpp:56
FRegion()
Default constructor.
Definition: regiongraph.h:55
Real & c()
Returns reference to counting number.
Definition: regiongraph.h:43
size_t nrORs() const
Returns number of outer regions.
Definition: regiongraph.h:152
RegionGraph()
Default constructor.
Definition: regiongraph.h:110
RegionGraph(const FactorGraph &fg, const std::vector< VarSet > &cl)
Constructs a region graph from a factor graph and a vector of outer clusters (CVM style) ...
Definition: regiongraph.h:136
const Neighbor & nb2(size_t i2, size_t _i1) const
Returns constant reference to the _i1 'th neighbor of node i2 of type 2.
Definition: bipgraph.h:100
Represents a set of variables.
Definition: varset.h:94
Region()
Default constructor.
Definition: regiongraph.h:34
std::vector< Region > _IRs
The inner regions (corresponding to nodes of type 2)
Definition: regiongraph.h:100
std::string toString() const
Formats a region graph as a string.
Definition: regiongraph.h:248
virtual void setFactors(const std::map< size_t, Factor > &facs, bool backup=false)
Set the contents of all factors as specified by facs and make a backup of the old contents if backup ...
Definition: regiongraph.h:219
void recomputeOR(size_t I)
Recompute all outer regions involving factor I.
Definition: regiongraph.cpp:205
Real _c
Counting number.
Definition: regiongraph.h:30
virtual void setFactor(size_t I, const Factor &newFactor, bool backup=false)
Set the content of the I 'th factor and make a backup of its old content if backup == true...
Definition: regiongraph.h:213
Real _c
Counting number.
Definition: regiongraph.h:51
size_t nrIRs() const
Returns number of inner regions.
Definition: regiongraph.h:154
const FRegion & OR(size_t alpha) const
Returns constant reference to outer region alpha.
Definition: regiongraph.h:157
Region(const VarSet &x, Real c)
Construct from a set of variables and a counting number.
Definition: regiongraph.h:37
FRegion & OR(size_t alpha)
Returns reference to outer region alpha.
Definition: regiongraph.h:162
void calcCVMCountingNumbers()
Calculates counting numbers of inner regions based upon counting numbers of outer regions...
Definition: regiongraph.cpp:126
Namespace for libDAI.
Definition: alldai.cpp:16
Defines the FactorGraph class, which represents factor graphs (e.g., Bayesian networks or Markov rand...
#define DAI_DEBASSERT(x)
Assertion mechanism similar to DAI_ASSERT which is only active if DAI_DEBUG is defined.
Definition: exceptions.h:65
virtual void setFactors(const std::map< size_t, Factor > &facs, bool backup=false)
Set the contents of all factors as specified by facs and make a backup of the old contents if backup ...
Definition: factorgraph.h:261
An FRegion is a factor with a counting number.
Definition: regiongraph.h:48
Real & c()
Returns reference to counting number.
Definition: regiongraph.h:64
Defines the BipartiteGraph class, which represents a bipartite graph.
virtual void setFactor(size_t I, const Factor &newFactor, bool backup=false)
Set the content of the I 'th factor and make a backup of its old content if backup == true...
Definition: factorgraph.h:253
size_t nrFactors() const
Returns number of factors.
Definition: factorgraph.h:136
BipartiteGraph _G
Stores the neighborhood structure.
Definition: regiongraph.h:94
virtual void WriteToFile(const char *, size_t=15) const
Writes a region graph to a file.
Definition: regiongraph.h:240
void recomputeORs()
Recompute all outer regions.
Definition: regiongraph.cpp:185
const Neighbors & nbOR(size_t alpha) const
Returns constant reference to the neighbors of outer region alpha.
Definition: regiongraph.h:186
void construct(const FactorGraph &fg, const std::vector< VarSet > &ors, const std::vector< Region > &irs, const std::vector< std::pair< size_t, size_t > > &edges)
Helper function for constructors.
Definition: regiongraph.cpp:23
virtual void printDot(std::ostream &) const
Writes a region graph to a GraphViz .dot file.
Definition: regiongraph.h:257
bool checkCountingNumbers() const
Check whether the counting numbers are valid.
Definition: regiongraph.cpp:163
const Real & c() const
Returns constant reference to counting number.
Definition: regiongraph.h:61