DiscreteDistribution.cpp
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2 
3  * GTSAM Copyright 2010, Georgia Tech Research Corporation,
4  * Atlanta, Georgia 30332-0415
5  * All Rights Reserved
6  * Authors: Frank Dellaert, et al. (see THANKS for the full author list)
7 
8  * See LICENSE for the license information
9 
10  * -------------------------------------------------------------------------- */
11 
19 
20 #include <vector>
21 
22 namespace gtsam {
23 
24 void DiscreteDistribution::print(const std::string& s,
25  const KeyFormatter& formatter) const {
26  Base::print(s, formatter);
27 }
28 
30  if (nrFrontals() != 1)
31  throw std::invalid_argument(
32  "Single value operator can only be invoked on single-variable "
33  "priors");
35  values.emplace(keys_[0], value);
36  return Base::operator()(values);
37 }
38 
39 std::vector<double> DiscreteDistribution::pmf() const {
40  if (nrFrontals() != 1)
41  throw std::invalid_argument(
42  "DiscreteDistribution::pmf only defined for single-variable priors");
43  const size_t nrValues = cardinalities_.at(keys_[0]);
44  std::vector<double> array;
45  array.reserve(nrValues);
46  for (size_t v = 0; v < nrValues; v++) {
47  array.push_back(operator()(v));
48  }
49  return array;
50 }
51 
52 } // namespace gtsam
int array[24]
leaf::MyValues values
KeyVector keys_
The keys involved in this factor.
Definition: Factor.h:87
const KeyFormatter & formatter
std::vector< double > pmf() const
We also want to keep the Base version, taking DiscreteValues:
double operator()(const DiscreteValues &values) const override
Evaluate probability distribution, sugar.
Array< int, Dynamic, 1 > v
std::map< Key, size_t > cardinalities_
RealScalar s
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: Key.h:35
traits
Definition: chartTesting.h:28
void print(const std::string &s="Discrete Conditional: ", const KeyFormatter &formatter=DefaultKeyFormatter) const override
GTSAM-style print.
void print(const std::string &s="Discrete Prior: ", const KeyFormatter &formatter=DefaultKeyFormatter) const override
GTSAM-style print.
double operator()(size_t value) const
Evaluate given a single value.


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:10