13 #ifndef __defined_libdai_cobwebgraph_h
14 #define __defined_libdai_cobwebgraph_h
55 std::vector<size_t>
fc;
67 DAI_ENUM(NeighborType,ALL,TOP,CLOSEST);
71 std::vector<SmallSet<size_t> >
_INRs;
73 std::vector<SmallSet<size_t> >
_EXRs;
75 std::vector<SmallSet<size_t> >
_Rfs;
77 std::vector<SmallSet<size_t> >
_Rifs;
79 std::vector<SmallSet<size_t> >
_Rxfs;
81 std::vector<std::vector<VarSet> >
_outM;
83 std::vector<std::vector<Connection> >
_M;
86 std::vector<std::vector<size_t> >
_var2CW;
92 std::vector<std::map<VarSet, std::pair<int,std::vector<size_t> > > >
_cn;
100 CobwebGraph() :
FactorGraph(), _INRs(), _EXRs(),_Rfs(),_Rifs(),_Rxfs(), _M(), _var2CW(), _cn(), isPartition(true) {}
106 FactorGraph::operator=( fg );
115 size_t nrCWs()
const {
return _INRs.size(); }
119 const std::map<VarSet, std::pair<int,std::vector<size_t> > >&
cn(
size_t R )
const {
125 std::map<VarSet, std::pair<int,std::vector<size_t> > >&
cn(
size_t R ) {
131 const std::vector<VarSet>&
outM(
size_t R )
const {
137 std::vector<VarSet>&
outM(
size_t R ) {
209 const std::vector<Connection>&
M(
size_t R )
const {
215 std::vector<Connection>&
M(
size_t R ) {
return _M[R]; }
218 const std::vector<size_t>&
var2CW(
size_t i )
const {
return _var2CW[i]; }
233 DAI_THROW(NOT_IMPLEMENTED);
240 DAI_THROW(NOT_IMPLEMENTED);
245 DAI_THROW(NOT_IMPLEMENTED);
250 std::stringstream ss;
259 DAI_THROW(NOT_IMPLEMENTED);
275 void setMSGs( NeighborType neighbors );
size_t dual
Index of the mirror of this connection in the connections of the second region. (reference of this me...
Definition: cobwebgraph.h:45
const std::vector< Connection > & M(size_t R) const
Returns constant reference to the vector of connection structure from region R to all its neighbours...
Definition: cobwebgraph.h:209
const VarSet & outM(size_t R, size_t j) const
Returns constant reference to the variables in the outgoing message from region R to its j'th neighbo...
Definition: cobwebgraph.h:145
const Connection & M(size_t R, size_t i) const
Returns constant reference to the connection structure from region R to its i'th neighbour.
Definition: cobwebgraph.h:197
std::vector< SmallSet< size_t > > _Rifs
Index of factors internal to each region, i.e., all its variables are internal to the region...
Definition: cobwebgraph.h:77
void setCountingNumbers(bool debugging=false)
Sets _cn.
Definition: cobwebgraph.cpp:65
void eraseNonMaximal(std::vector< SmallSet< size_t > > ®ions)
For the given set of variables for each region, removes the regions that are non-maximal.
Definition: cobwebgraph.cpp:48
const std::vector< VarSet > & outM(size_t R) const
Returns constant reference the vector of domain of all outgoing messages from region R...
Definition: cobwebgraph.h:131
const SmallSet< size_t > & Rfs(size_t R) const
Returns constant reference to the index of factors of region R.
Definition: cobwebgraph.h:161
void setExtnFact()
Setup the _INRs, _EXRs and all the factor indices (e.g. Rifs)
Definition: cobwebgraph.cpp:239
const std::map< VarSet, std::pair< int, std::vector< size_t > > > & cn(size_t R) const
Returns constant reference to the _cn for region R.
Definition: cobwebgraph.h:119
Defines some utility functions for (weighted) undirected graphs, trees and rooted trees...
Represents a factor graph.
Definition: factorgraph.h:65
std::vector< SmallSet< size_t > > _EXRs
Vector of variable indices on the boundary of each region ( r)
Definition: cobwebgraph.h:73
std::vector< SmallSet< size_t > > _INRs
Vector of variable indices internal to each region (r)
Definition: cobwebgraph.h:71
std::vector< std::map< VarSet, std::pair< int, std::vector< size_t > > > > _cn
Definition: cobwebgraph.h:92
virtual CobwebGraph * clone() const
Clone *this (virtual copy constructor)
Definition: cobwebgraph.h:110
size_t iter
Index of this connection in the connections of the first region.
Definition: cobwebgraph.h:43
std::vector< VarSet > & outM(size_t R)
Returns reference the vector of domain of all outgoing messages from region R.
Definition: cobwebgraph.h:137
std::vector< std::vector< size_t > > _var2CW
For each i the index of (cobweb) regions that contain variable i.
Definition: cobwebgraph.h:86
Defines the DAI_ENUM macro, which can be used to define an enum with additional functionality.
std::vector< std::vector< VarSet > > _outM
The vector of domain of messages leaving each region ( r_{p,q})
Definition: cobwebgraph.h:81
DAI_ENUM(NeighborType, ALL, TOP, CLOSEST)
Represents a set of variables.
Definition: varset.h:94
void setMSGs(NeighborType neighbors)
Helper function that setups the msgs (_M, _outM) using the values in _INRs and _EXRs.
Definition: cobwebgraph.cpp:177
std::vector< SmallSet< size_t > > _Rfs
Index of factors in each region.
Definition: cobwebgraph.h:75
SmallSet< size_t > & EXRs(size_t R)
Returns reference to the index of variables on the boundary of region R ( r)
Definition: cobwebgraph.h:179
std::vector< SmallSet< size_t > > _Rxfs
Index of factors that bridge each region, i.e., not all its variables are internal to the region...
Definition: cobwebgraph.h:79
size_t my
Index of the first region (p)
Definition: cobwebgraph.h:39
bool checkPartition(const std::vector< SmallSet< size_t > > ®ions) const
The function to check for partitioning.
Definition: cobwebgraph.cpp:154
size_t his
Index of the second region (q)
Definition: cobwebgraph.h:41
std::vector< std::vector< Connection > > _M
Vector of all connections to each region.
Definition: cobwebgraph.h:83
Factor msg
The message sent from region q (his) to p (my)
Definition: cobwebgraph.h:47
friend std::ostream & operator<<(std::ostream &, const CobwebGraph &)
Writes a cobweb graph to an output stream.
Definition: cobwebgraph.h:244
void setVar2CW()
Helper function that sets the regions containing each variable using the values in _INRs...
Definition: cobwebgraph.cpp:166
std::vector< Connection > & M(size_t R)
Returns vector of all connections to region R.
Definition: cobwebgraph.h:215
Factor newmsg
Used as a temporary factor only.
Definition: cobwebgraph.h:53
Defines the SmallSet<> class, which represents a set (optimized for a small number of elements)...
A CobwebGraph is a special type of region graph used by the GLC algorithm.
Definition: cobwebgraph.h:34
SmallSet< size_t > & INRs(size_t R)
Returns reference to the index of variables inside region R (r)
Definition: cobwebgraph.h:191
VarSet & outM(size_t R, size_t j)
Returns a reference to the variables in the outgoing message from region R to its j'th neighbor...
Definition: cobwebgraph.h:154
virtual void WriteToFile(const char *, size_t=15) const
Writes a cobweb graph to a file.
Definition: cobwebgraph.h:239
bool isPartition
Whether a given set of region vars makes a partitioning or not.
Definition: cobwebgraph.h:95
std::vector< VarSet > subregions
Regions rho that are descendents of msg from q to p in p's msg-region graph (not used in partitioning...
Definition: cobwebgraph.h:57
virtual void ReadFromFile(const char *)
Reads a cobweb graph from a file.
Definition: cobwebgraph.h:232
void setRgn(std::vector< SmallSet< size_t > > regions, NeighborType neighbors, bool debugging=false)
Sets up all the regions and messages.
Definition: cobwebgraph.cpp:21
Namespace for libDAI.
Definition: alldai.cpp:16
const std::vector< size_t > & var2CW(size_t i) const
Returns the vector of region indices that contain i as internal variable.
Definition: cobwebgraph.h:218
Defines the FactorGraph class, which represents factor graphs (e.g., Bayesian networks or Markov rand...
std::vector< size_t > fc
Index of factors in common.
Definition: cobwebgraph.h:55
size_t nrCWs() const
Returns the number of regions.
Definition: cobwebgraph.h:116
std::vector< size_t > varinds
"Index" of variables in the message
Definition: cobwebgraph.h:49
CobwebGraph(const FactorGraph &fg)
Constructs a cobweb graph from a factor graph.
Definition: cobwebgraph.h:104
#define DAI_DEBASSERT(x)
Assertion mechanism similar to DAI_ASSERT which is only active if DAI_DEBUG is defined.
Definition: exceptions.h:65
std::string toString() const
Formats a cobweb graph as a string.
Definition: cobwebgraph.h:249
SmallSet< size_t > & Rfs(size_t R)
Returns reference to the index of factors of region R.
Definition: cobwebgraph.h:167
Connection & M(size_t R, size_t i)
Returns reference to the connection structure from region R to its i'th neighbour.
Definition: cobwebgraph.h:203
std::map< VarSet, std::pair< int, std::vector< size_t > > > & cn(size_t R)
Returns a reference to the _cn for region R.
Definition: cobwebgraph.h:125
const SmallSet< size_t > & INRs(size_t R) const
Returns constant reference to the index of variables inside region R (r)
Definition: cobwebgraph.h:185
const SmallSet< size_t > & EXRs(size_t R) const
Returns constant reference to the index of variables on the boundary of region R ( r) ...
Definition: cobwebgraph.h:173
The information in connection between two regions.
Definition: cobwebgraph.h:37
virtual void printDot(std::ostream &) const
Writes a cobweb graph to a GraphViz .dot file.
Definition: cobwebgraph.h:258
CobwebGraph()
Default constructor.
Definition: cobwebgraph.h:101