forked from dbtsai/libDAI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
... of examples/example.cpp, examples/example_bipgraph.cpp, include/dai/prob.h, include/dai/smallset.h, include/dai/var.h, include/dai/varset.h Some small additional changes: - Replaced TProb<T>::log0() by TProb<T>::log(true) and TProb<T>::takeLog0() by TProb<T>::takeLog(true) - Replaced TFactor<T>::log0() by TFactor<T>::log(true) - Removed TProb<T>::hasNonPositives() - Added examples/example_varset.cpp - Renamed smallSet<T> to SmallSet<T> - Changed operator<< for Var and VarSet
- Loading branch information
Joris Mooij
committed
Oct 9, 2008
1 parent
077347c
commit 51e268b
Showing
19 changed files
with
1,266 additions
and
1,107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include <dai/varset.h> | ||
#include <iostream> | ||
|
||
using namespace std; | ||
using namespace dai; | ||
|
||
int main() { | ||
Var x0(0, 2); // Define binary variable x0 (with label 0) | ||
Var x1(1, 3); // Define ternary variable x1 (with label 1) | ||
|
||
// Define set X = {x0, x1} | ||
VarSet X; // empty | ||
X |= x1; // X = {x1} | ||
X |= x0; // X = {x1, x0} | ||
cout << "X = " << X << endl << endl; // Note that the elements of X are ordered according to their labels | ||
|
||
// Output some information about x0, x1 and X | ||
cout << "Var " << x0 << " has " << x0.states() << " states (possible values)." << endl; | ||
cout << "Var " << x1 << " has " << x1.states() << " states." << endl << endl; | ||
cout << "VarSet " << X << " has " << X.nrStates() << " states (joint assignments of its variables)." << endl << endl; | ||
|
||
cout << "States of VarSets correspond to states of their constituent Vars:" << endl; | ||
cout << " state of x0: state of x1: state of X:" << endl; | ||
for( size_t s1 = 0; s1 < x1.states(); s1++ ) // for all states s1 of x1 | ||
for( size_t s0 = 0; s0 < x0.states(); s0++ ) { // for all states s0 of x0 | ||
// store s0 and s1 in a map "states" | ||
map<Var,size_t> states; | ||
states[x0] = s0; | ||
states[x1] = s1; | ||
|
||
// output states of x0, x1 and corresponding state of X | ||
cout << " " << s0 << " " << s1 << " " << X.calcState(states) << endl; | ||
|
||
// VarSet::calcStates is the inverse of VarSet::calcState | ||
assert( X.calcStates(X.calcState(states)) == states ); | ||
} | ||
|
||
cout << endl << "And vice versa:" << endl; | ||
cout << " state of x0: state of x1: state of X:" << endl; | ||
for( size_t S = 0; S < X.nrStates(); S++ ) { // for all (joint) states of X | ||
// calculate states of x0 and x1 corresponding to state S of X | ||
map<Var,size_t> states = X.calcStates(S); | ||
|
||
// output state of X and corresponding states of x0, x1 | ||
cout << " " << states[x0] << " " << states[x1] << " " << S << endl; | ||
|
||
// VarSet::calcState is the inverse of VarSet::calcStates | ||
assert( X.calcState(X.calcStates(S)) == S ); | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
X = {x0,x1} | ||
|
||
Var x0 has 2 states (possible values). | ||
Var x1 has 3 states. | ||
|
||
VarSet {x0,x1} has 6 states (joint assignments of its variables). | ||
|
||
States of VarSets correspond to states of their constituent Vars: | ||
state of x0: state of x1: state of X: | ||
0 0 0 | ||
1 0 1 | ||
0 1 2 | ||
1 1 3 | ||
0 2 4 | ||
1 2 5 | ||
|
||
And vice versa: | ||
state of x0: state of x1: state of X: | ||
0 0 0 | ||
1 0 1 | ||
0 1 2 | ||
1 1 3 | ||
0 2 4 | ||
1 2 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.