25 #include <boost/make_shared.hpp> 38 template class Conditional<DecisionTreeFactor, DiscreteConditional> ;
41 DiscreteConditional::DiscreteConditional(
const size_t nrFrontals,
52 if (
ISDEBUG(
"DiscreteConditional::DiscreteConditional"))
61 keys_.insert(
keys_.end(), orderedKeys.begin(), orderedKeys.end());
66 :
BaseFactor(signature.discreteKeys(), signature.cpt()),
90 if (!dynamic_cast<const DecisionTreeFactor*>(&other))
94 static_cast<const DecisionTreeFactor&>(other));
106 value = parentsValues.at(j);
107 pFS = pFS.
choose(j, value);
108 }
catch (exception&) {
109 cout <<
"Key: " << j <<
" Value: " << value << endl;
110 parentsValues.
print(
"parentsValues: ");
112 throw runtime_error(
"DiscreteConditional::choose: parent value missing");
137 for(
Values& frontalVals: allPosbValues) {
138 double pValueS = pFS(frontalVals);
140 if (pValueS > maxP) {
156 size_t sampled =
sample(values);
175 double pValueS = pFS(frontals);
177 if (pValueS > maxP) {
187 static mt19937
rng(2);
196 vector<double>
p(nj);
200 p[
value] = pFS(frontals);
201 if (p[
value] == 1.0) {
205 std::discrete_distribution<size_t> distribution(p.begin(), p.end());
206 return distribution(rng);
std::vector< Assignment< L > > cartesianProduct(const std::vector< std::pair< L, size_t > > &keys)
Get Cartesian product consisting all possible configurations.
Concept check for values that can be used in unit tests.
signatures for conditional densities
DecisionTreeFactor::const_iterator endParents() const
Frontals frontals() const
void solveInPlace(Values &parentsValues) const
solve a conditional, in place
KeyVector keys_
The keys involved in this factor.
DecisionTree choose(const L &label, size_t index) const
size_t nrFrontals() const
Key firstFrontalKey() const
const KeyFormatter & formatter
size_t solve(const Values &parentsValues) const
DecisionTreeFactor::const_iterator beginParents() const
void print(const std::string &s="Assignment: ") const
std::pair< Key, size_t > DiscreteKey
DecisionTreeFactor::const_iterator endFrontals() const
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
ADT choose(const Assignment< Key > &parentsValues) const
size_t cardinality(Key j) const
const mpreal sum(const mpreal tab[], const unsigned long int n, int &status, mp_rnd_t mode=mpreal::get_default_rnd())
DecisionTreeFactor::const_iterator beginFrontals() const
void sampleInPlace(Values &parentsValues) const
sample in place, stores result in partial solution
const KeyVector & keys() const
Access the factor's involved variable keys.
bool equals(const DiscreteFactor &other, double tol=1e-9) const override
GTSAM-style equals.
GTSAM_EXPORT void print(const std::string &s="Potentials: ", const KeyFormatter &formatter=DefaultKeyFormatter) const
bool equals(const DiscreteFactor &other, double tol=1e-9) const override
equality
KeyVector::const_iterator const_iterator
Const iterator over keys.
std::uint64_t Key
Integer nonlinear key type.
void print(const std::string &s="Discrete Conditional: ", const KeyFormatter &formatter=DefaultKeyFormatter) const override
GTSAM-style print.
size_t sample(const Values &parentsValues) const
DiscreteKeys is a set of keys that can be assembled using the & operator.