Loading...
Searching...
No Matches
DiscreteBayesNet.h
Go to the documentation of this file.
/* ----------------------------------------------------------------------------
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
* Atlanta, Georgia 30332-0415
* All Rights Reserved
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
* See LICENSE for the license information
* -------------------------------------------------------------------------- */
#pragma once
#include <gtsam/discrete/DiscreteConditional.h>
#include <gtsam/discrete/DiscreteDistribution.h>
#include <gtsam/inference/BayesNet.h>
#include <gtsam/inference/FactorGraph.h>
#include <boost/shared_ptr.hpp>
#include <map>
#include <string>
#include <utility>
#include <vector>
namespace gtsam {
class GTSAM_EXPORT DiscreteBayesNet: public BayesNet<DiscreteConditional> {
public:
typedef BayesNet<DiscreteConditional> Base;
typedef DiscreteBayesNet This;
typedef DiscreteConditional ConditionalType;
typedef boost::shared_ptr<This> shared_ptr;
typedef boost::shared_ptr<ConditionalType> sharedConditional;
DiscreteBayesNet() {}
template <typename ITERATOR>
DiscreteBayesNet(ITERATOR firstConditional, ITERATOR lastConditional)
: Base(firstConditional, lastConditional) {}
template <class CONTAINER>
explicit DiscreteBayesNet(const CONTAINER& conditionals)
: Base(conditionals) {}
template <class DERIVEDCONDITIONAL>
DiscreteBayesNet(const FactorGraph<DERIVEDCONDITIONAL>& graph)
: Base(graph) {}
virtual ~DiscreteBayesNet() {}
bool equals(const This& bn, double tol = 1e-9) const;
// Add inherited versions of add.
using Base::add;
void add(const DiscreteKey& key, const std::string& spec) {
emplace_shared<DiscreteDistribution>(key, spec);
}
template <typename... Args>
void add(Args&&... args) {
emplace_shared<DiscreteConditional>(std::forward<Args>(args)...);
}
//** evaluate for given DiscreteValues */
double evaluate(const DiscreteValues & values) const;
//** (Preferred) sugar for the above for given DiscreteValues */
double operator()(const DiscreteValues & values) const {
return evaluate(values);
}
//** log(evaluate(values)) for given DiscreteValues */
double logProbability(const DiscreteValues & values) const;
DiscreteValues sample() const;
DiscreteValues sample(DiscreteValues given) const;
std::string markdown(const KeyFormatter& keyFormatter = DefaultKeyFormatter,
const DiscreteFactor::Names& names = {}) const;
std::string html(const KeyFormatter& keyFormatter = DefaultKeyFormatter,
const DiscreteFactor::Names& names = {}) const;
using Base::error; // Expose error(const HybridValues&) method..
using Base::evaluate; // Expose evaluate(const HybridValues&) method..
using Base::logProbability; // Expose logProbability(const HybridValues&)
#ifdef GTSAM_ALLOW_DEPRECATED_SINCE_V42
DiscreteValues GTSAM_DEPRECATED optimize() const;
DiscreteValues GTSAM_DEPRECATED optimize(DiscreteValues given) const;
#endif
private:
friend class boost::serialization::access;
template<class ARCHIVE>
void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
}
};
// traits
template<> struct traits<DiscreteBayesNet> : public Testable<DiscreteBayesNet> {};
} // \ namespace gtsam
DiscreteConditional.h
DiscreteDistribution.h
FactorGraph.h
Factor Graph Base Class.
BayesNet.h
Bayes network.
gtsam::DiscreteKey
std::pair< Key, size_t > DiscreteKey
Key type for discrete variables.
Definition DiscreteKey.h:36
gtsam
Global functions in a separate testing namespace.
Definition chartTesting.h:28
gtsam::html
string html(const DiscreteValues &values, const KeyFormatter &keyFormatter, const DiscreteValues::Names &names)
Free version of html.
Definition DiscreteValues.cpp:134
gtsam::optimize
Point3 optimize(const NonlinearFactorGraph &graph, const Values &values, Key landmarkKey)
Optimize for triangulation.
Definition triangulation.cpp:155
gtsam::traits
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition concepts.h:30
gtsam::equals
Template to create a binary predicate.
Definition Testable.h:111
gtsam::Testable
A helper that implements the traits interface for GTSAM types.
Definition Testable.h:151
gtsam::DiscreteBayesNet
A Bayes net made from discrete conditional distributions.
Definition DiscreteBayesNet.h:38
gtsam::DiscreteBayesNet::DiscreteBayesNet
DiscreteBayesNet(ITERATOR firstConditional, ITERATOR lastConditional)
Construct from iterator over conditionals.
Definition DiscreteBayesNet.h:54
gtsam::DiscreteBayesNet::DiscreteBayesNet
DiscreteBayesNet(const FactorGraph< DERIVEDCONDITIONAL > &graph)
Implicit copy/downcast constructor to override explicit template container constructor.
Definition DiscreteBayesNet.h:65
gtsam::DiscreteBayesNet::DiscreteBayesNet
DiscreteBayesNet(const CONTAINER &conditionals)
Construct from container of factors (shared_ptr or plain objects).
Definition DiscreteBayesNet.h:59
gtsam::DiscreteBayesNet::DiscreteBayesNet
DiscreteBayesNet()
Construct empty Bayes net.
Definition DiscreteBayesNet.h:50
gtsam::DiscreteBayesNet::~DiscreteBayesNet
virtual ~DiscreteBayesNet()
Destructor.
Definition DiscreteBayesNet.h:69
gtsam::DiscreteBayesNet::add
void add(Args &&... args)
Add a DiscreteCondtional.
Definition DiscreteBayesNet.h:94
gtsam::DiscreteBayesNet::add
void add(const DiscreteKey &key, const std::string &spec)
Add a DiscreteDistribution using a table or a string.
Definition DiscreteBayesNet.h:88
gtsam::DiscreteConditional
Discrete Conditional Density Derives from DecisionTreeFactor.
Definition DiscreteConditional.h:40
gtsam::DiscreteValues
A map from keys to values.
Definition DiscreteValues.h:34
gtsam::BayesNet< DiscreteConditional >::BayesNet
BayesNet()
Definition BayesNet.h:48
gtsam::FactorGraph
A factor graph is a bipartite graph with factor nodes connected to variable nodes.
Definition FactorGraph.h:97
gtsam::FactorGraph::emplace_shared
IsDerived< DERIVEDFACTOR > emplace_shared(Args &&... args)
Emplace a shared pointer to factor of given type.
Definition FactorGraph.h:192
DiscreteValues
The Factor::error simply extracts the.