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 {
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
gtsam::DiscreteDistribution::operator()
double operator()(size_t value) const
Evaluate given a single value.
Definition: DiscreteDistribution.cpp:29
array
int array[24]
Definition: Map_general_stride.cpp:1
s
RealScalar s
Definition: level1_cplx_impl.h:126
gtsam::DiscreteFactor::cardinalities_
std::map< Key, size_t > cardinalities_
Map of Keys and their cardinalities.
Definition: DiscreteFactor.h:51
formatter
const KeyFormatter & formatter
Definition: treeTraversal-inst.h:204
different_sigmas::values
HybridValues values
Definition: testHybridBayesNet.cpp:245
gtsam::DiscreteConditional::print
void print(const std::string &s="Discrete Conditional: ", const KeyFormatter &formatter=DefaultKeyFormatter) const override
GTSAM-style print.
Definition: DiscreteConditional.cpp:131
gtsam::DiscreteDistribution::pmf
std::vector< double > pmf() const
We also want to keep the Base version, taking DiscreteValues:
Definition: DiscreteDistribution.cpp:39
gtsam::KeyFormatter
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
gtsam::DecisionTreeFactor::operator()
double operator()(const DiscreteValues &values) const override
Evaluate probability distribution, sugar.
Definition: DecisionTreeFactor.h:139
gtsam::Conditional< DecisionTreeFactor, DiscreteConditional >::nrFrontals
size_t nrFrontals() const
Definition: Conditional.h:131
array
Definition: numpy.h:821
gtsam
traits
Definition: SFMdata.h:40
gtsam::Factor::keys_
KeyVector keys_
The keys involved in this factor.
Definition: Factor.h:88
gtsam::DiscreteValues
Definition: DiscreteValues.h:34
DiscreteDistribution.h
v
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
test_callbacks.value
value
Definition: test_callbacks.py:160
gtsam::DiscreteDistribution::print
void print(const std::string &s="Discrete Prior: ", const KeyFormatter &formatter=DefaultKeyFormatter) const override
GTSAM-style print.
Definition: DiscreteDistribution.cpp:24


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:02:13