iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
nrt::GaussianPDF< StateDef > Class Template Reference

#include <nrt/Probabilistic/Types/GaussianPDF.H>

template<class StateDef>
class nrt::GaussianPDF< StateDef >

A Gaussian representation of a given StateDefinition.

  A GaussianPDF represents the set of variables in a StateDefinition with a mean vector and a covariance matrix
Template Parameters
StateDefThe StateDefinition which defines the fields of the mean and covariance
NRT_STATE_FIELD_GROUP(Position2D,(x)(y));
NRT_STATE_FIELD_GROUP(Velocity2D,(x)(y));
// Access a single field of the mean
mygaussian.mean<Position2D::x>() = 1.1;
// Access a field group of the mean
mygaussian.mean<Velocity2D>() = Eigen::Vector2d(3.3, 4.4);
// Access the entire mean
mygaussian.mean<>() = Eigen::Vector4d(1.1, 2.2, 3.3, 4.4);
// Access the covariance between two fields
mygaussian.covariance<Position2D::x, Velocity2D::y>() = 0.00001;
// Access the variance of a field
mygaussian.covariance<Position2D::x>() = 0.00001;
// Access the covariance block of a field
mygaussian.covariance<Position2D>() = Eigen::Matrix2d(0.01, 0.02, 0.02, 0.03);
// Accessthe entire covariance matrix
mygaussian.covariance<>() = Eigen::Matrix4d::Identity() * 0.01;
Warning
When editing covariance values manually, you must ensure that you maintain the symmetry of the matrix! For example, if you assign mygaussian.covariance<Position2D::x, Position2D::y>() = 2.2, you must also assign mygaussian.covariance<Position2D::y, Position2D::x>() = 2.2

One shortcut is to just set the upper triangular part, and then make it symmetric, e.g. mygaussian.covariance<>() = mygaussian.covariance<>().selfadjointView<Eigen::Upper>();

See Also
probabalistic
Examples:
tests/test-GaussianPDF.C, tests/test-State.C, and tests/test-UKF.C.

Definition at line 91 of file GaussianPDF.H.

Public Types

typedef Eigen::Matrix< double,
StateDef::num_fields,
StateDef::num_fields > 
CovarianceType
 The statically sized matrix type for the covariance.
 

Public Member Functions

 GaussianPDF ()
 Default constructor. More...
 
 GaussianPDF (MeanType const &mean, CovarianceType const &covariance)
 Construct a Gaussian with a mean and covariance.
 
template<class Field >
std::enable_if< is_state_field
< Field >), double & >::type 
mean ()
 Access the mean of a single field. More...
 
template<class Field >
std::enable_if< is_state_field
< Field >), double >::type 
mean () const
 Access the mean of a single field (const version)
 
template<class FieldGroup >
std::enable_if
< is_state_field_group
< FieldGroup >), Eigen::Block
< MeanType,
FieldGroup::num_fields, 1 >
>::type 
mean ()
 Access the mean of an entire field group. More...
 
template<class FieldGroup >
std::enable_if
< is_state_field_group
< FieldGroup >), Eigen::Block
< MeanType const,
FieldGroup::num_fields, 1 >
>::type 
mean () const
 Access the mean of an entire field group (const version)
 
template<typename Void = void>
std::enable_if< std::is_void
< Void >::value, MeanType & >
::type 
mean ()
 Access the entire mean vector. More...
 
template<typename Void = void>
std::enable_if< std::is_void
< Void >::value, MeanType >
::type 
mean () const
 Access the entire mean vector (const version)
 
template<class Field1 , class Field2 >
std::enable_if
< are_state_fields< Field1,
Field2 >), double & >::type 
covariance ()
 Access the covariance between two state fields. More...
 
template<class Field1 , class Field2 >
std::enable_if
< are_state_fields< Field1,
Field2 >), double >::type 
covariance () const
 Access the covariance between two state fields (const version)
 
template<class Field >
std::enable_if< is_state_field
< Field >), double & >::type 
covariance ()
 Access the variance of a single state field. More...
 
template<class Field >
std::enable_if< is_state_field
< Field >), double >::type 
covariance () const
 Access the variance of a single state field (const version)
 
template<class FieldGroup >
std::enable_if
< is_state_field_group
< FieldGroup >), Eigen::Block
< CovarianceType,
FieldGroup::num_fields,
FieldGroup::num_fields >
>::type 
covariance ()
 Access the covariance sub-matrix of a field group. More...
 
template<class FieldGroup >
std::enable_if
< is_state_field_group
< FieldGroup >), Eigen::Block
< CovarianceType const,
FieldGroup::num_fields,
FieldGroup::num_fields >
>::type 
covariance () const
 Access the covariance sub-matrix of a field group (const version)
 
template<class FieldGroup1 , class FieldGroup2 >
std::enable_if
< are_state_field_groups
< FieldGroup1, FieldGroup2 >
), Eigen::Block
< CovarianceType,
FieldGroup1::num_fields,
FieldGroup2::num_fields >
>::type 
covariance ()
 Access the covariance sub-matrix between two field groups. More...
 
template<class FieldGroup1 , class FieldGroup2 >
std::enable_if
< are_state_field_groups
< FieldGroup1, FieldGroup2 >
), Eigen::Block
< CovarianceType const,
FieldGroup1::num_fields,
FieldGroup2::num_fields >
>::type 
covariance () const
 Access the covariance sub-matrix between two field groups (const version)
 
template<typename Void = void>
std::enable_if< std::is_void
< Void >::value,
CovarianceType & >::type 
covariance ()
 Access the entire covariance matrix. More...
 
template<typename Void = void>
std::enable_if< std::is_void
< Void >::value,
CovarianceType >::type 
covariance () const
 Access the entire covariance matrix (const version)
 
template<class Field1 , class Field2 >
nrt::Polygon< double > covarianceEllipse (size_t numpoints=30) const
 Generate an ellipse showing 1 standard deviation around the covariance of the two given fields.
 
template<class Field >
auto mean () -> typename std::enable_if< is_state_field< Field >(), double & >::type
 
template<class Field >
auto mean () const -> typename std::enable_if< is_state_field< Field >(), double >::type
 
template<class Field1 , class Field2 >
auto covariance () -> typename std::enable_if< are_state_fields< Field1, Field2 >(), double & >::type
 
template<class Field1 , class Field2 >
auto covariance () const -> typename std::enable_if< are_state_fields< Field1, Field2 >(), double >::type
 
template<class Field >
auto covariance () -> typename std::enable_if< is_state_field< Field >(), double & >::type
 
template<class Field >
auto covariance () const -> typename std::enable_if< is_state_field< Field >(), double >::type
 

Public Attributes

EIGEN_MAKE_ALIGNED_OPERATOR_NEW
typedef Eigen::Matrix< double,
StateDef::num_fields, 1 > 
MeanType
 The statically sized vector type for the mean.
 

Protected Member Functions

template<class Archive >
void serialize (Archive &ar)
 Serialization.
 

Friends

class cereal::access
 

Constructor & Destructor Documentation

template<class StateDef >
nrt::GaussianPDF< StateDef >::GaussianPDF ( )

Default constructor.

The internal means and covariances are all set to 0

Definition at line 39 of file GaussianPDFImpl.H.

Member Function Documentation

template<class StateDef>
template<class Field >
std::enable_if< is_state_field<Field>), double & >::type nrt::GaussianPDF< StateDef >::mean ( )

Access the mean of a single field.

Template Parameters
FieldThe single field to access, e.g. Position2D::x
Returns
A reference to the scalar field
NRT_STATE_FIELD_GROUP(Position2D,(x)(y));
NRT_STATE_FIELD_GROUP(Velocity2D,(x)(y));
mypdf.mean<Velocity2D::x>() = 1;
double velocity_x = mypdf.mean<Velocity2D::x>();
template<class StateDef>
template<class FieldGroup >
std::enable_if< is_state_field_group<FieldGroup>), Eigen::Block<MeanType, FieldGroup::num_fields, 1> >::type nrt::GaussianPDF< StateDef >::mean ( )

Access the mean of an entire field group.

Template Parameters
FieldGroupThe field group to access, e.g. Position2D
Returns
An Eigen::Block, which acts like a reference to the vector of the field group.
NRT_STATE_FIELD_GROUP(Position2D,(x)(y));
NRT_STATE_FIELD_GROUP(Velocity2D,(x)(y));
mypdf.mean<Velocity2D>() << 1, 2;
Eigen::Vector2d velocity = mypdf.mean<Velocity2D>();
template<class StateDef>
template<typename Void = void>
std::enable_if< std::is_void<Void>::value, MeanType & >::type nrt::GaussianPDF< StateDef >::mean ( )

Access the entire mean vector.

Template Parameters
VoidLeave this template parameter empty to specify you want the entire mean vector.
Returns
A reference to the entire mean vector.
NRT_STATE_FIELD_GROUP(Position2D,(x)(y));
NRT_STATE_FIELD_GROUP(Velocity2D,(x)(y));
mypdf.mean<>() << 1, 2, 3, 4;
Eigen::Vector4d mean = mypdf.mean<>();
template<class StateDef>
template<class Field1 , class Field2 >
std::enable_if< are_state_fields<Field1, Field2>), double & >::type nrt::GaussianPDF< StateDef >::covariance ( )

Access the covariance between two state fields.

Template Parameters
Field1The first state field
Field2The second state field
Returns
A reference to the covariance between Field1 and Field2
NRT_STATE_FIELD_GROUP(Position2D,(x)(y));
NRT_STATE_FIELD_GROUP(Velocity2D,(x)(y));
mypdf.covariance<Position2D::x, Velocity2D::y>() = 3.3;
mypdf.covariance<Velocity2D::y, Position2D::x>() = 3.3;
template<class StateDef>
template<class Field >
std::enable_if< is_state_field<Field>), double& >::type nrt::GaussianPDF< StateDef >::covariance ( )

Access the variance of a single state field.

Template Parameters
FieldThe state field
Returns
A reference to the variance of Field
NRT_STATE_FIELD_GROUP(Position2D,(x)(y));
NRT_STATE_FIELD_GROUP(Velocity2D,(x)(y));
mypdf.covariance<Position2D::y>() = 10;
assert(mypdf.covariance<Position2D::y, Position2D::y>() == 10);
template<class StateDef>
template<class FieldGroup >
std::enable_if< is_state_field_group<FieldGroup>), Eigen::Block<CovarianceType, FieldGroup::num_fields, FieldGroup::num_fields> >::type nrt::GaussianPDF< StateDef >::covariance ( )

Access the covariance sub-matrix of a field group.

Template Parameters
FieldThe state field
Returns
An Eigen::Block, which acts like a reference to the specified covariance sub-matrix
NRT_STATE_FIELD_GROUP(Position2D,(x)(y));
NRT_STATE_FIELD_GROUP(Velocity2D,(x)(y));
Eigen::Matrix2d pos_variance = mypdf.covariance<Position2D>();
template<class StateDef>
template<class FieldGroup1 , class FieldGroup2 >
std::enable_if< are_state_field_groups<FieldGroup1, FieldGroup2>), Eigen::Block<CovarianceType, FieldGroup1::num_fields, FieldGroup2::num_fields> >::type nrt::GaussianPDF< StateDef >::covariance ( )

Access the covariance sub-matrix between two field groups.

Template Parameters
FieldGroup1The first State Field Group
FieldGroup2The second State Field Group
Returns
The covariance matrix between FieldGroup1 and FieldGroup2
NRT_STATE_FIELD_GROUP(Position2D,(x)(y));
NRT_STATE_FIELD_GROUP(Velocity2D,(x)(y));
Eigen::Matrix4d covariance = mypdf.covariance<Position2D, Velocity2D>();
template<class StateDef>
template<typename Void = void>
std::enable_if< std::is_void<Void>::value, CovarianceType & >::type nrt::GaussianPDF< StateDef >::covariance ( )

Access the entire covariance matrix.

Template Parameters
VoidLeave this template parameter empty to specify you want the entire covariance matrix.
Returns
A reference to the entire covariance matrix.
NRT_STATE_FIELD_GROUP(Position2D,(x)(y));
NRT_STATE_FIELD_GROUP(Velocity2D,(x)(y));
Eigen::Matrix4d covariance = mypdf.covariance<>();

The documentation for this class was generated from the following files: