Repository navigation
Expand file tree
/
Copy pathvariable.h
More file actions
89 lines (68 loc) · 2.9 KB
/
Copy pathvariable.h
File metadata and controls
89 lines (68 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <vector>
#ifndef _VARIABLE_H_
#define _VARIABLE_H_
#define DTYPE_BOOLEAN 0x00
#define DTYPE_REAL 0x01
#define DTYPE_MULTINOMIAL 0x04
namespace dd{
typedef int VariableValue;
typedef long VariableIndex;
typedef long FactorIndex;
/**
* A variable in factor graph
*/
class Variable {
public:
long id; // variable id
int domain_type; // variable domain type, can be DTYPE_BOOLEAN or
// DTYPE_MULTINOMIAL
bool is_evid; // whether the variable is evidence
VariableValue lower_bound; // lower bound
VariableValue upper_bound; // upper bound
VariableValue assignment_evid; // assignment, while keeping evidence variables unchanged
VariableValue assignment_free; // assignment, free to change any variable
int n_factors; // number of factors the variable connects to
long n_start_i_factors; // id of the first factor
// the values of multinomial variables are stored in an array like this
// [v11 v12 ... v1m v21 ... v2n ...]
// where v1, v2 are two multinomial variables, with domain 1-m, and 1-n respectively.
// n_start_i_tally is the start position for the variable values in the array
long n_start_i_tally;
std::vector<long> tmp_factor_ids; // factor ids the variable connects to
Variable();
/**
* Constructs a variable with id, domain type, is evidence, lower bound,
* upper bound, initial value, current value, number of factors
*/
Variable(const long & _id, const int & _domain_type,
const bool & _is_evid, const VariableValue & _lower_bound,
const VariableValue & _upper_bound, const VariableValue & _init_value,
const VariableValue & _current_value, const int & _n_factors);
};
/**
* Encapsulates a variable inside a factor
*/
class VariableInFactor {
public:
long vid; // variable id
int n_position; // position of the variable inside factor
bool is_positive; // whether the variable is positive or negated
// the variable's predicate value. A variable is "satisfied" if its value equals equal_to
VariableValue equal_to;
int dimension;
/**
* Returns whether the variable's predicate is satisfied using the given value
*/
bool satisfiedUsing(int value) const;
VariableInFactor();
VariableInFactor(int dummy,
const int & _dimension,
const long & _vid, const int & _n_position,
const bool & _is_positive);
VariableInFactor(const long & _vid, const int & _n_position,
const bool & _is_positive);
VariableInFactor(const long & _vid, const int & _n_position,
const bool & _is_positive, const VariableValue & _equal_to);
};
}
#endif