#include <dai/regiongraph.h>
Input/output | |
virtual void | ReadFromFile (const char *) |
Reads a region graph from a file. | |
virtual void | WriteToFile (const char *, size_t=15) const |
Writes a factor graph to a file. | |
virtual void | printDot (std::ostream &) const |
Writes a region graph to a GraphViz .dot file. | |
std::ostream & | operator<< (std::ostream &os, const RegionGraph &rg) |
Writes a RegionGraph to an output stream. | |
Public Member Functions | |
Constructors and destructors | |
RegionGraph () | |
Default constructor. | |
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 and a vector of edges. | |
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). | |
virtual RegionGraph * | clone () const |
Clone *this (virtual copy constructor). | |
Accessors and mutators | |
size_t | nrORs () const |
Returns number of outer regions. | |
size_t | nrIRs () const |
Returns number of inner regions. | |
const FRegion & | OR (size_t alpha) const |
Returns constant reference to outer region alpha. | |
FRegion & | OR (size_t alpha) |
Returns reference to outer region alpha. | |
const Region & | IR (size_t beta) const |
Returns constant reference to inner region beta. | |
Region & | IR (size_t beta) |
Returns reference to inner region beta. | |
size_t | fac2OR (size_t I) const |
Returns the index of the outer region to which the I 'th factor corresponds. | |
const Neighbors & | nbOR (size_t alpha) const |
Returns constant reference to the neighbors of outer region alpha. | |
const Neighbors & | nbIR (size_t beta) const |
Returns constant reference to the neighbors of inner region beta. | |
const BipartiteGraph & | DAG () const |
Returns DAG structure of the region graph. | |
Queries | |
bool | checkCountingNumbers () const |
Check whether the counting numbers are valid. | |
Operations | |
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 . | |
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 == true . | |
Protected Member Functions | |
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. | |
void | constructCVM (const FactorGraph &fg, const std::vector< VarSet > &cl, size_t verbose=0) |
Helper function for constructors (CVM style). | |
void | recomputeORs () |
Recompute all outer regions. | |
void | recomputeORs (const VarSet &vs) |
Recompute all outer regions involving the variables in vs. | |
void | recomputeOR (size_t I) |
Recompute all outer regions involving factor I. | |
void | calcCVMCountingNumbers () |
Calculates counting numbers of inner regions based upon counting numbers of outer regions. | |
Protected Attributes | |
BipartiteGraph | _G |
Stores the neighborhood structure. | |
std::vector< FRegion > | _ORs |
The outer regions (corresponding to nodes of type 1). | |
std::vector< Region > | _IRs |
The inner regions (corresponding to nodes of type 2). | |
std::vector< size_t > | _fac2OR |
Stores for each factor index the index of the outer region it belongs to. |
A RegionGraph inherits from a FactorGraph and adds additional structure in the form of a "region graph". Our definition of region graph is inspired by [HAK03], which is less general than the definition given in [YFW05].
The extra structure described by a RegionGraph compared with that described by a FactorGraph is:
Each factor in the factor graph belongs to an outer region; normally, the factor contents of an outer region would be the product of all the factors that belong to that region.
dai::RegionGraph::RegionGraph | ( | ) | [inline] |
Default constructor.
dai::RegionGraph::RegionGraph | ( | const FactorGraph & | fg, | |
const std::vector< VarSet > & | ors, | |||
const std::vector< Region > & | irs, | |||
const std::vector< std::pair< size_t, size_t > > & | edges | |||
) | [inline] |
Constructs a region graph from a factor graph, a vector of outer regions, a vector of inner regions and a vector of edges.
The counting numbers for the outer regions are set to 1.
dai::RegionGraph::RegionGraph | ( | const FactorGraph & | fg, | |
const std::vector< VarSet > & | cl | |||
) | [inline] |
Constructs a region graph from a factor graph and a vector of outer clusters (CVM style).
The region graph is constructed as in the Cluster Variation Method.
The outer regions have as variable subsets the clusters specified in cl. Each factor in the factor graph fg is assigned to one of the outer regions. Each outer region gets counting number 1.
The inner regions are (repeated) intersections of outer regions. An inner and an outer region are connected if the variables in the inner region form a subset of the variables in the outer region. The counting numbers for the inner regions are calculated by calcCountingNumbers() and satisfy the Moebius formula.
virtual RegionGraph* dai::RegionGraph::clone | ( | ) | const [inline, virtual] |
size_t dai::RegionGraph::nrORs | ( | ) | const [inline] |
Returns number of outer regions.
size_t dai::RegionGraph::nrIRs | ( | ) | const [inline] |
Returns number of inner regions.
const FRegion& dai::RegionGraph::OR | ( | size_t | alpha | ) | const [inline] |
Returns constant reference to outer region alpha.
FRegion& dai::RegionGraph::OR | ( | size_t | alpha | ) | [inline] |
Returns reference to outer region alpha.
const Region& dai::RegionGraph::IR | ( | size_t | beta | ) | const [inline] |
Returns constant reference to inner region beta.
Region& dai::RegionGraph::IR | ( | size_t | beta | ) | [inline] |
Returns reference to inner region beta.
size_t dai::RegionGraph::fac2OR | ( | size_t | I | ) | const [inline] |
Returns the index of the outer region to which the I 'th factor corresponds.
const Neighbors& dai::RegionGraph::nbOR | ( | size_t | alpha | ) | const [inline] |
Returns constant reference to the neighbors of outer region alpha.
const Neighbors& dai::RegionGraph::nbIR | ( | size_t | beta | ) | const [inline] |
Returns constant reference to the neighbors of inner region beta.
const BipartiteGraph& dai::RegionGraph::DAG | ( | ) | const [inline] |
Returns DAG structure of the region graph.
bool dai::RegionGraph::checkCountingNumbers | ( | ) | const |
Check whether the counting numbers are valid.
Counting numbers are said to be (variable) valid if for each variable ,
or in words, if the sum of the counting numbers of the regions that contain the variable equals one.
virtual void dai::RegionGraph::setFactor | ( | size_t | I, | |
const Factor & | newFactor, | |||
bool | backup = false | |||
) | [inline, virtual] |
Set the content of the I 'th factor and make a backup of its old content if backup == true
.
Reimplemented from dai::FactorGraph.
virtual void dai::RegionGraph::setFactors | ( | const std::map< size_t, Factor > & | facs, | |
bool | backup = false | |||
) | [inline, virtual] |
Set the contents of all factors as specified by facs and make a backup of the old contents if backup == true
.
Reimplemented from dai::FactorGraph.
virtual void dai::RegionGraph::ReadFromFile | ( | const char * | ) | [inline, virtual] |
virtual void dai::RegionGraph::WriteToFile | ( | const char * | , | |
size_t | = 15 | |||
) | const [inline, virtual] |
virtual void dai::RegionGraph::printDot | ( | std::ostream & | ) | const [inline, virtual] |
Writes a region graph to a GraphViz .dot file.
Reimplemented from dai::FactorGraph.
void dai::RegionGraph::construct | ( | const FactorGraph & | fg, | |
const std::vector< VarSet > & | ors, | |||
const std::vector< Region > & | irs, | |||
const std::vector< std::pair< size_t, size_t > > & | edges | |||
) | [protected] |
Helper function for constructors.
void dai::RegionGraph::constructCVM | ( | const FactorGraph & | fg, | |
const std::vector< VarSet > & | cl, | |||
size_t | verbose = 0 | |||
) | [protected] |
Helper function for constructors (CVM style).
void dai::RegionGraph::recomputeORs | ( | ) | [protected] |
Recompute all outer regions.
The factor contents of each outer region is set to the product of the factors belonging to that region.
void dai::RegionGraph::recomputeORs | ( | const VarSet & | vs | ) | [protected] |
Recompute all outer regions involving the variables in vs.
The factor contents of each outer region involving at least one of the variables in vs is set to the product of the factors belonging to that region.
void dai::RegionGraph::recomputeOR | ( | size_t | I | ) | [protected] |
Recompute all outer regions involving factor I.
The factor contents of each outer region involving the I 'th factor is set to the product of the factors belonging to that region.
void dai::RegionGraph::calcCVMCountingNumbers | ( | ) | [protected] |
Calculates counting numbers of inner regions based upon counting numbers of outer regions.
The counting numbers of the inner regions are set using the Moebius inversion formula:
where are the ancestors of inner region
according to the partial ordering induced by the subset relation (i.e., a region is a child of another region if its variables are a subset of the variables of its parent region).
std::ostream& operator<< | ( | std::ostream & | os, | |
const RegionGraph & | rg | |||
) | [friend] |
Writes a RegionGraph to an output stream.
BipartiteGraph dai::RegionGraph::_G [protected] |
std::vector<FRegion> dai::RegionGraph::_ORs [protected] |
The outer regions (corresponding to nodes of type 1).
std::vector<Region> dai::RegionGraph::_IRs [protected] |
The inner regions (corresponding to nodes of type 2).
std::vector<size_t> dai::RegionGraph::_fac2OR [protected] |
Stores for each factor index the index of the outer region it belongs to.