Go to the documentation of this file.
36 using std::stringstream;
43 return sparse_table / sparse_table.
sum();
54 const std::vector<double>& potentials)
62 const std::string& potentials)
127 double maxValue = 0.0;
131 for (
SparseIt it(sparseTable); it; ++it) {
132 if (it.value() > maxValue) {
134 maxValue = it.value();
148 static mt19937
rng(2);
151 for (
auto&& [
key,
_] : parentsValues) {
160 throw std::invalid_argument(
161 "TableDistribution::sample can only be called on single variable "
166 vector<double>
p(nj);
175 std::discrete_distribution<size_t> distribution(
p.begin(),
p.end());
176 return distribution(
rng);
size_t sample() const
Zero parent version.
DiscreteFactor::shared_ptr sum(size_t nrFrontals) const override
Create new factor by summing all values with the same separator values.
DiscreteValues argmax() const
Return assignment that maximizes value.
bool equals(const This &c, double tol=1e-9) const
Concept check for values that can be used in unit tests.
const KeyFormatter & formatter
DiscreteKeys is a set of keys that can be assembled using the & operator.
DecisionTreeFactor ::const_iterator endFrontals() const
TableDistribution()
Default constructor needed for serialization.
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
double max() const override
Find the maximum value in the factor.
DiscreteValues findAssignments(const uint64_t idx) const
Find DiscreteValues for corresponding index.
signatures for conditional densities
TableFactor prune(size_t maxNrAssignments) const
Prune the decision tree of discrete variables.
Eigen::SparseVector< double > sparseTable() const
Getter for the underlying sparse vector.
DecisionTreeFactor ::const_iterator beginFrontals() const
size_t nrFrontals() const
double sum() const
Compute sum of all values.
const gtsam::Symbol key('X', 0)
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
size_t cardinality(Key j) const
Key firstFrontalKey() const
KeyVector::const_iterator const_iterator
Const iterator over keys.
std::shared_ptr< DiscreteFactor > shared_ptr
shared_ptr to this class
DiscreteFactor::shared_ptr operator*(double s) const override
Multiply by scalar s.
const KeyVector & keys() const
Access the factor's involved variable keys.
virtual void prune(size_t maxNrAssignments) override
Prune the conditional.
TableFactor choose(const DiscreteValues parentAssignments, DiscreteKeys parent_keys) const
Create a TableFactor that is a subset of this TableFactor.
DiscreteFactor::shared_ptr operator/(const DiscreteFactor::shared_ptr &f) const override
divide by DiscreteFactor::shared_ptr f (safely)
double max() const override
Find the maximum value in the factor.
bool equals(const DiscreteFactor &other, double tol=1e-9) const override
equality
void print(const std::string &s="TableFactor:\n", const KeyFormatter &formatter=DefaultKeyFormatter) const override
print
unsigned __int64 uint64_t
std::uint64_t Key
Integer nonlinear key type.
constexpr descr< N - 1 > _(char const (&text)[N])
Frontals frontals() const
void print(const std::string &s="Table Distribution: ", const KeyFormatter &formatter=DefaultKeyFormatter) const override
GTSAM-style print.
static Eigen::SparseVector< double > normalizeSparseTable(const Eigen::SparseVector< double > &sparse_table)
Normalize sparse_table.
bool equals(const DiscreteFactor &other, double tol=1e-9) const override
GTSAM-style equals.
gtsam
Author(s):
autogenerated on Wed Mar 19 2025 03:04:38