Go to the documentation of this file.
37 using std::stringstream;
44 return sparse_table / sparse_table.
sum();
55 const std::vector<double>& potentials)
63 const std::string& potentials)
128 double maxValue = 0.0;
132 for (
SparseIt it(sparseTable); it; ++it) {
133 if (it.value() > maxValue) {
135 maxValue = it.value();
149 std::mt19937_64*
rng)
const {
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);
179 std::discrete_distribution<size_t> distribution(
p.begin(),
p.end());
180 return distribution(*
rng);
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.
virtual size_t sample(const DiscreteValues &parentsValues, std::mt19937_64 *rng=nullptr) const override
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
static std::mt19937_64 kRandomNumberGenerator(42)
Global default pseudo-random number generator object. In wrappers we can access std::mt19937_64 via g...
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 May 28 2025 03:04:19