28 #include "drwnVarUniverse.h"
32 using namespace Eigen;
42 #ifdef DRWN_FACTOR_DEBUG_STATISTICS
43 static unsigned _dbStatsRefCount;
44 static unsigned _dbStatsProductCount;
45 static unsigned _dbStatsDivideCount;
46 static unsigned _dbStatsAdditionCount;
47 static unsigned _dbStatsSubtractionCount;
48 static unsigned _dbStatsMarginalCount;
49 static unsigned _dbStatsMaxMinCount;
50 static unsigned _dbStatsReductionCount;
51 static unsigned _dbStatsNormalizeCount;
52 static unsigned _dbStatsNormalizeErrors;
53 static unsigned _dbStatsLargestFactorSize;
54 static unsigned _dbStatsCurrentMem;
55 static unsigned _dbStatsMaxMem;
56 static unsigned _dbStatsMaxTable;
57 static unsigned _dbStatsTotalMem;
76 bool empty()
const {
return _variables.empty(); }
78 size_t size()
const {
return _variables.size(); }
80 virtual size_t memory()
const {
return 0; }
87 bool hasVariable(
int var)
const {
return (_varIndex.find(var) != _varIndex.end()); }
89 int varId(
int indx)
const {
return _variables[indx]; }
91 int varCard(
int indx)
const {
return _pUniverse->varCardinality(_variables[indx]); }
94 virtual void addVariable(
int var);
96 void addVariable(
const char *name);
98 void addVariables(
const char *name, ...);
99 void addVariables(
const vector<int>& c);
109 bool save(drwnXMLNode& xml)
const;
110 bool load(drwnXMLNode& xml);
128 #ifdef DRWN_FACTOR_DEBUG_STATISTICS
129 static void updateMemoryStats(
int nSize,
int previousSize = 0);
160 const char *
type()
const {
return "drwnTableFactor"; }
163 size_t memory()
const {
return _nSize *
sizeof(double); }
164 size_t entries()
const {
return _nSize; }
165 bool isShared()
const {
return (_storage != NULL); }
169 void addVariable(
int var);
174 int indexOf(
int var,
int val,
int indx = 0)
const;
181 int valueOf(
int var,
int indx)
const;
189 int indexOfMin()
const;
190 int indexOfMax()
const;
191 pair<int, int> indexOfMinAndMax()
const;
202 bool save(drwnXMLNode& xml)
const;
203 bool load(drwnXMLNode& xml);
206 return _data[indexOf(y)];
210 _data[indexOf(y)] = val;
218 inline double& operator[](
unsigned index) {
return _data[index]; }
219 inline const double& operator[](
unsigned index)
const {
return _data[index]; }
248 void reserve(
int nSize);
251 inline void zero(
int nSize = -1) { fill(0.0, nSize); }
253 void fill(
double v,
int nSize = -1);
255 void copy(
const double *p,
int nSize = -1);
260 inline double& operator[](
unsigned index) {
return _data[index]; }
261 inline const double& operator[](
unsigned index)
const {
return _data[index]; }
const char * type() const
returns object type as a string (e.g., Foo::type() { return "Foo"; })
Definition: drwnTableFactor.h:160
int varId(int indx) const
returns variable at given index
Definition: drwnTableFactor.h:89
void setValueOf(const drwnPartialAssignment &y, double val)
Sets the value of the factor for a given partial assignment. The variables in the scope of this facto...
Definition: drwnTableFactor.h:123
virtual void addVariable(int var)
add variable by id
Definition: drwnTableFactor.cpp:98
bool empty() const
true if the factor contains no variables
Definition: drwnTableFactor.h:76
void fill(double v, int nSize=-1)
set nSize (or all) entries to the value v
Definition: drwnTableFactor.cpp:613
int varCard(int indx) const
return cardinality of variable at given index
Definition: drwnTableFactor.h:91
drwnTableFactorStorage * _storage
pointer to shared storage (updates _data member)
Definition: drwnTableFactor.h:152
drwnClique getClique() const
returns the set of variables over which this factor is defined
Definition: drwnTableFactor.h:106
void zero(int nSize=-1)
set nSize (or all) entries to zero
Definition: drwnTableFactor.h:251
size_t memory() const
number of bytes comsumed by the factor data (excludes variables lists, etc)
Definition: drwnTableFactor.h:163
size_t size() const
number of variables in this factor
Definition: drwnTableFactor.h:78
void copy(const double *p, int nSize=-1)
copy nSize (or all) entries from array p
Definition: drwnTableFactor.cpp:628
Data structure for definining the random variables (name and cardinality) for a given problem instanc...
Definition: drwnVarUniverse.h:29
const vector< int > & getOrderedVars() const
returns the ordered set of variables over which this factor is defined
Definition: drwnTableFactor.h:104
void setValueOf(const drwnFullAssignment &y, double val)
Sets the value of the factor for a given (full) assignment.
Definition: drwnTableFactor.h:209
int _nSize
total size of factor (or 1 for singular factors)
Definition: drwnTableFactor.h:150
int capacity() const
return the total capacity of the storage
Definition: drwnTableFactor.h:246
Factor which stores the value of each assignment explicitly in table form.
Definition: drwnTableFactor.h:144
std::set< int > drwnClique
variable clique
Definition: drwnGraphUtils.h:37
std::vector< int > drwnFullAssignment
defines a complete assignment to all variables in the universe
Definition: drwnVarAssignment.h:36
int _dataSize
amount of memory allocated
Definition: drwnTableFactor.h:236
drwnVarUniversePtr _pUniverse
all variables in the universe
Definition: drwnTableFactor.h:61
defines an assignment to a subset of the variables
Definition: drwnVarAssignment.h:41
map< int, int > _varIndex
index of variable in factor (by variable id)
Definition: drwnTableFactor.h:63
Shared memory for table factors.
Definition: drwnTableFactor.h:232
Generic interface for a factor. Currently only inherited by drwnTableFactor.
Definition: drwnTableFactor.h:40
double * _data
data is stored as (a0, b0, ...), (a1, b0, ...), ...
Definition: drwnTableFactor.h:151
Data structures and utilities for encoding assignments to variables.
vector< int > _variables
list of variables in factor (by index in factor)
Definition: drwnTableFactor.h:62
bool hasVariable(int var) const
returns true if the variable is included in this factor
Definition: drwnTableFactor.h:87
double getValueOf(const drwnPartialAssignment &y) const
Returns the value of the factor for a given partial assignment. The variables in the scope of this fa...
Definition: drwnTableFactor.h:116
set< drwnTableFactor * > _tables
tables using this storage
Definition: drwnTableFactor.h:239
double * _data
memory allocation
Definition: drwnTableFactor.h:237
drwnTableFactor * clone() const
returns a copy of the class usually implemented as virtual Foo* clone() { return new Foo(*this); } ...
Definition: drwnTableFactor.h:161
double getValueOf(const drwnFullAssignment &y) const
Returns the value of the factor for a given (full) assignment.
Definition: drwnTableFactor.h:205
standard Darwin object interface (cloneable and writeable)
Definition: drwnInterfaces.h:72
virtual size_t memory() const
number of bytes comsumed by the factor data (excludes variables lists, etc)
Definition: drwnTableFactor.h:80
void initialize(drwnNNGraph &graph, const DistanceMetric &M)
randomly initialize edges (matched) for all active images (keeps existing matches unless an improveme...
Definition: drwnNNGraphMoves.h:159
const drwnVarUniversePtr & getUniverse() const
returns the variable universe
Definition: drwnTableFactor.h:83
std::vector< int > _stride
stride of variable in table (by index)
Definition: drwnTableFactor.h:148