gtsam 4.2.0
gtsam
|
A conditional of gaussian mixtures indexed by discrete variables, as part of a Bayes Network.
a density over continuous variables given discrete/continuous parents.
This is the result of the elimination of a continuous variable in a hybrid scheme, such that the remaining variables are discrete+continuous.
Represents the conditional density P(X | M, Z) where X is the set of continuous random variables, M is the selection of discrete variables corresponding to a subset of the Gaussian variables and Z is parent of this node .
The probability P(x|y,z,...) is proportional to \( \sum_i k_i \exp - \frac{1}{2} |R_i x - (d_i - S_i y - T_i z - ...)|^2 \) where i indexes the components and k_i is a component-wise normalization constant.
Public Member Functions | |
Constructors | |
GaussianMixture ()=default | |
Default constructor, mainly for serialization. | |
GaussianMixture (const KeyVector &continuousFrontals, const KeyVector &continuousParents, const DiscreteKeys &discreteParents, const Conditionals &conditionals) | |
Construct a new GaussianMixture object. More... | |
GaussianMixture (KeyVector &&continuousFrontals, KeyVector &&continuousParents, DiscreteKeys &&discreteParents, std::vector< GaussianConditional::shared_ptr > &&conditionals) | |
Make a Gaussian Mixture from a list of Gaussian conditionals. More... | |
GaussianMixture (const KeyVector &continuousFrontals, const KeyVector &continuousParents, const DiscreteKeys &discreteParents, const std::vector< GaussianConditional::shared_ptr > &conditionals) | |
Make a Gaussian Mixture from a list of Gaussian conditionals. More... | |
Testable | |
bool | equals (const HybridFactor &lf, double tol=1e-9) const override |
Test equality with base HybridFactor. More... | |
void | print (const std::string &s="GaussianMixture\n", const KeyFormatter &formatter=DefaultKeyFormatter) const override |
Print utility. More... | |
Standard API | |
GaussianConditional::shared_ptr | operator() (const DiscreteValues &discreteValues) const |
Return the conditional Gaussian for the given discrete assignment. | |
size_t | nrComponents () const |
Returns the total number of continuous components. | |
KeyVector | continuousParents () const |
Returns the continuous keys among the parents. | |
double | logNormalizationConstant () const override |
The log normalization constant is max of the the individual log-normalization constants. More... | |
boost::shared_ptr< GaussianMixtureFactor > | likelihood (const VectorValues &given) const |
Create a likelihood factor for a Gaussian mixture, return a Mixture factor on the parents. | |
const Conditionals & | conditionals () const |
Getter for the underlying Conditionals DecisionTree. | |
AlgebraicDecisionTree< Key > | logProbability (const VectorValues &continuousValues) const |
Compute logProbability of the GaussianMixture as a tree. More... | |
double | error (const HybridValues &values) const override |
Compute the error of this Gaussian Mixture. More... | |
AlgebraicDecisionTree< Key > | error (const VectorValues &continuousValues) const |
Compute error of the GaussianMixture as a tree. More... | |
double | logProbability (const HybridValues &values) const override |
Compute the logProbability of this Gaussian Mixture. More... | |
double | evaluate (const HybridValues &values) const override |
Calculate probability density for given values . More... | |
double | operator() (const HybridValues &values) const |
Evaluate probability density, sugar. | |
void | prune (const DecisionTreeFactor &decisionTree) |
Prune the decision tree of Gaussian factors as per the discrete decisionTree . More... | |
GaussianFactorGraphTree | add (const GaussianFactorGraphTree &sum) const |
Merge the Gaussian Factor Graphs in this and sum while maintaining the decision tree structure. More... | |
![]() | |
HybridFactor ()=default | |
Default constructor creates empty factor. | |
HybridFactor (const KeyVector &keys) | |
Construct hybrid factor from continuous keys. More... | |
HybridFactor (const DiscreteKeys &discreteKeys) | |
Construct hybrid factor from discrete keys. More... | |
HybridFactor (const KeyVector &continuousKeys, const DiscreteKeys &discreteKeys) | |
Construct a new Hybrid Factor object. More... | |
virtual | ~HybridFactor ()=default |
Virtual destructor. | |
void | print (const std::string &s="HybridFactor\n", const KeyFormatter &formatter=DefaultKeyFormatter) const override |
print More... | |
bool | isDiscrete () const |
True if this is a factor of discrete variables only. | |
bool | isContinuous () const |
True if this is a factor of continuous variables only. | |
bool | isHybrid () const |
True is this is a Discrete-Continuous factor. | |
size_t | nrContinuous () const |
Return the number of continuous variables in this factor. | |
const DiscreteKeys & | discreteKeys () const |
Return the discrete keys for this factor. | |
const KeyVector & | continuousKeys () const |
Return only the continuous keys for this factor. | |
![]() | |
virtual | ~Factor ()=default |
Default destructor. | |
bool | empty () const |
Whether the factor is empty (involves zero variables). | |
Key | front () const |
First key. | |
Key | back () const |
Last key. | |
const_iterator | find (Key key) const |
find | |
const KeyVector & | keys () const |
Access the factor's involved variable keys. | |
const_iterator | begin () const |
Iterator at beginning of involved variable keys. | |
const_iterator | end () const |
Iterator at end of involved variable keys. | |
size_t | size () const |
virtual void | printKeys (const std::string &s="Factor", const KeyFormatter &formatter=DefaultKeyFormatter) const |
print only keys More... | |
bool | equals (const This &other, double tol=1e-9) const |
check equality | |
KeyVector & | keys () |
iterator | begin () |
Iterator at beginning of involved variable keys. | |
iterator | end () |
Iterator at end of involved variable keys. | |
![]() | |
void | print (const std::string &s="Conditional", const KeyFormatter &formatter=DefaultKeyFormatter) const |
print with optional formatter | |
bool | equals (const This &c, double tol=1e-9) const |
check equality | |
virtual | ~Conditional () |
size_t | nrFrontals () const |
return the number of frontals | |
size_t | nrParents () const |
return the number of parents | |
Key | firstFrontalKey () const |
Convenience function to get the first frontal key. | |
Frontals | frontals () const |
return a view of the frontal keys | |
Parents | parents () const |
return a view of the parent keys | |
double | operator() (const HybridValues &x) const |
Evaluate probability density, sugar. | |
double | normalizationConstant () const |
Non-virtual, exponentiate logNormalizationConstant. | |
size_t & | nrFrontals () |
Mutable version of nrFrontals. | |
FACTOR::const_iterator | beginFrontals () const |
Iterator pointing to first frontal key. | |
FACTOR::iterator | beginFrontals () |
Mutable iterator pointing to first frontal key. | |
FACTOR::const_iterator | endFrontals () const |
Iterator pointing past the last frontal key. | |
FACTOR::iterator | endFrontals () |
Mutable iterator pointing past the last frontal key. | |
FACTOR::const_iterator | beginParents () const |
Iterator pointing to the first parent key. | |
FACTOR::iterator | beginParents () |
Mutable iterator pointing to the first parent key. | |
FACTOR::const_iterator | endParents () const |
Iterator pointing past the last parent key. | |
FACTOR::iterator | endParents () |
Mutable iterator pointing past the last parent key. | |
Public Types | |
using | This = GaussianMixture |
using | shared_ptr = boost::shared_ptr< GaussianMixture > |
using | BaseFactor = HybridFactor |
using | BaseConditional = Conditional< HybridFactor, GaussianMixture > |
using | Conditionals = DecisionTree< Key, GaussianConditional::shared_ptr > |
typedef for Decision Tree of Gaussian Conditionals | |
![]() | |
typedef HybridFactor | This |
This class. | |
typedef boost::shared_ptr< HybridFactor > | shared_ptr |
shared_ptr to this class | |
typedef Factor | Base |
Our base class. | |
![]() | |
typedef KeyVector::iterator | iterator |
Iterator over keys. | |
typedef KeyVector::const_iterator | const_iterator |
Const iterator over keys. | |
![]() | |
typedef boost::iterator_range< typename FACTOR::const_iterator > | Frontals |
View of the frontal keys (call frontals()) | |
typedef boost::iterator_range< typename FACTOR::const_iterator > | Parents |
View of the separator keys (call parents()) | |
Friends | |
class | boost::serialization::access |
Serialization function. | |
Additional Inherited Members | |
![]() | |
static bool | CheckInvariants (const GaussianMixture &conditional, const VALUES &x) |
Check invariants of this conditional, given the values x . More... | |
![]() | |
Factor () | |
Default constructor for I/O. | |
template<typename CONTAINER > | |
Factor (const CONTAINER &keys) | |
Construct factor from container of keys. More... | |
template<typename ITERATOR > | |
Factor (ITERATOR first, ITERATOR last) | |
Construct factor from iterator keys. More... | |
![]() | |
Conditional () | |
Empty Constructor to make serialization possible. | |
Conditional (size_t nrFrontals) | |
Constructor. | |
![]() | |
template<typename CONTAINER > | |
static Factor | FromKeys (const CONTAINER &keys) |
Construct factor from container of keys. More... | |
template<typename ITERATOR > | |
static Factor | FromIterators (ITERATOR first, ITERATOR last) |
Construct factor from iterator keys. More... | |
![]() | |
DiscreteKeys | discreteKeys_ |
KeyVector | continuousKeys_ |
Record continuous keys for book-keeping. | |
![]() | |
KeyVector | keys_ |
The keys involved in this factor. | |
![]() | |
size_t | nrFrontals_ |
The first nrFrontal variables are frontal and the rest are parents. | |
gtsam::GaussianMixture::GaussianMixture | ( | const KeyVector & | continuousFrontals, |
const KeyVector & | continuousParents, | ||
const DiscreteKeys & | discreteParents, | ||
const Conditionals & | conditionals | ||
) |
Construct a new GaussianMixture object.
continuousFrontals | the continuous frontals. |
continuousParents | the continuous parents. |
discreteParents | the discrete parents. Will be placed last. |
conditionals | a decision tree of GaussianConditionals. The number of conditionals should be C^(number of discrete parents), where C is the cardinality of the DiscreteKeys in discreteParents, since the discreteParents will be used as the labels in the decision tree. |
gtsam::GaussianMixture::GaussianMixture | ( | KeyVector && | continuousFrontals, |
KeyVector && | continuousParents, | ||
DiscreteKeys && | discreteParents, | ||
std::vector< GaussianConditional::shared_ptr > && | conditionals | ||
) |
Make a Gaussian Mixture from a list of Gaussian conditionals.
continuousFrontals | The continuous frontal variables |
continuousParents | The continuous parent variables |
discreteParents | Discrete parents variables |
conditionals | List of conditionals |
gtsam::GaussianMixture::GaussianMixture | ( | const KeyVector & | continuousFrontals, |
const KeyVector & | continuousParents, | ||
const DiscreteKeys & | discreteParents, | ||
const std::vector< GaussianConditional::shared_ptr > & | conditionals | ||
) |
Make a Gaussian Mixture from a list of Gaussian conditionals.
continuousFrontals | The continuous frontal variables |
continuousParents | The continuous parent variables |
discreteParents | Discrete parents variables |
conditionals | List of conditionals |
GaussianFactorGraphTree gtsam::GaussianMixture::add | ( | const GaussianFactorGraphTree & | sum | ) | const |
|
overridevirtual |
Test equality with base HybridFactor.
Reimplemented from gtsam::HybridFactor.
|
overridevirtual |
Compute the error of this Gaussian Mixture.
This requires some care, as different mixture components may have different normalization constants. Let's consider p(x|y,m), where m is discrete. We need the error to satisfy the invariant:
error(x;y,m) = K - log(probability(x;y,m))
For all x,y,m. But note that K, the (log) normalization constant defined in Conditional.h, should not depend on x, y, or m, only on the parameters of the density. Hence, we delegate to the underlying Gaussian conditionals, indexed by m, which do satisfy:
log(probability_m(x;y)) = K_m - error_m(x;y)
We resolve by having K == max(K_m) and
error(x;y,m) = error_m(x;y) + K - K_m
which also makes error(x;y,m) >= 0 for all x,y,m.
values | Continuous values and discrete assignment. |
Reimplemented from gtsam::Factor.
AlgebraicDecisionTree< Key > gtsam::GaussianMixture::error | ( | const VectorValues & | continuousValues | ) | const |
Compute error of the GaussianMixture as a tree.
continuousValues | The continuous VectorValues. |
|
overridevirtual |
Calculate probability density for given values
.
Reimplemented from gtsam::Conditional< HybridFactor, GaussianMixture >.
|
inlineoverridevirtual |
The log normalization constant is max of the the individual log-normalization constants.
Reimplemented from gtsam::Conditional< HybridFactor, GaussianMixture >.
|
overridevirtual |
Compute the logProbability of this Gaussian Mixture.
values | Continuous values and discrete assignment. |
Reimplemented from gtsam::Conditional< HybridFactor, GaussianMixture >.
AlgebraicDecisionTree< Key > gtsam::GaussianMixture::logProbability | ( | const VectorValues & | continuousValues | ) | const |
Compute logProbability of the GaussianMixture as a tree.
continuousValues | The continuous VectorValues. |
|
overridevirtual |
Print utility.
Reimplemented from gtsam::Factor.
void gtsam::GaussianMixture::prune | ( | const DecisionTreeFactor & | decisionTree | ) |
Prune the decision tree of Gaussian factors as per the discrete decisionTree
.
decisionTree | A pruned decision tree of discrete keys where the leaves are probabilities. |