Drake
Drake C++ Documentation
Loading...
Searching...
No Matches
BarycentricMesh< T > Class Template Reference

Detailed Description

template<typename T>
class drake::math::BarycentricMesh< T >

Represents a multi-linear function (from vector inputs to vector outputs) by interpolating between points on a mesh using (triangular) barycentric interpolation.

For a technical description of barycentric interpolation, see e.g. Remi Munos and Andrew Moore, "Barycentric Interpolators for Continuous Space and Time Reinforcement Learning", NIPS 1998

Template Parameters
TThe scalar type, which must be double.

#include <drake/math/barycentric.h>

Public Types

typedef std::set< doubleCoordinates
 The mesh is represented by a std::set (to ensure uniqueness and provide logarithmic lookups) of coordinates in each input dimension.
typedef std::vector< CoordinatesMeshGrid

Public Member Functions

 BarycentricMesh (MeshGrid input_grid)
 Constructs the mesh.
const MeshGridget_input_grid () const
int get_input_size () const
int get_num_mesh_points () const
int get_num_interpolants () const
void get_mesh_point (int index, EigenPtr< Eigen::VectorXd > point) const
 Writes the position of a mesh point in the input space referenced by its scalar index to point.
VectorX< T > get_mesh_point (int index) const
 Returns the position of a mesh point in the input space referenced by its scalar index to point.
MatrixX< T > get_all_mesh_points () const
 Returns a matrix with all of the mesh points, one per column.
void EvalBarycentricWeights (const Eigen::Ref< const VectorX< T > > &input, EigenPtr< Eigen::VectorXi > mesh_indices, EigenPtr< VectorX< T > > weights) const
 Writes the mesh indices used for interpolation to mesh_indices, and the interpolating coefficients to weights.
void Eval (const Eigen::Ref< const MatrixX< T > > &mesh_values, const Eigen::Ref< const VectorX< T > > &input, EigenPtr< VectorX< T > > output) const
 Evaluates the function at the input values, by interpolating between the values at mesh_values.
VectorX< T > Eval (const Eigen::Ref< const MatrixX< T > > &mesh_values, const Eigen::Ref< const VectorX< T > > &input) const
 Returns the function evaluated at input.
template<typename ValueT = T>
void EvalWithMixedScalars (const Eigen::Ref< const MatrixX< ValueT > > &mesh_values, const Eigen::Ref< const VectorX< T > > &input, EigenPtr< VectorX< ValueT > > output) const
 Performs Eval, but with the possibility of the values on the mesh having a different scalar type than the values defining the mesh (symbolic::Expression containing decision variables for an optimization problem is an important example)
template<typename ValueT = T>
VectorX< ValueT > EvalWithMixedScalars (const Eigen::Ref< const MatrixX< ValueT > > &mesh_values, const Eigen::Ref< const VectorX< T > > &input) const
 Returns the function evaluated at input.
MatrixX< T > MeshValuesFrom (const std::function< VectorX< T >(const Eigen::Ref< const VectorX< T > > &)> &vector_func) const
 Evaluates vector_func at all input mesh points and extracts the mesh value matrix that should be used to approximate the function with this barycentric interpolation.
Implements CopyConstructible, CopyAssignable, MoveConstructible, MoveAssignable
 BarycentricMesh (const BarycentricMesh &)=default
BarycentricMeshoperator= (const BarycentricMesh &)=default
 BarycentricMesh (BarycentricMesh &&)=default
BarycentricMeshoperator= (BarycentricMesh &&)=default

Member Typedef Documentation

◆ Coordinates

template<typename T>
typedef std::set<double> Coordinates

The mesh is represented by a std::set (to ensure uniqueness and provide logarithmic lookups) of coordinates in each input dimension.

Note: The values are type double, not T (We do not plan to take gradients, etc w/ respect to them).

◆ MeshGrid

template<typename T>
typedef std::vector<Coordinates> MeshGrid

Constructor & Destructor Documentation

◆ BarycentricMesh() [1/3]

template<typename T>
BarycentricMesh ( const BarycentricMesh< T > & )
default

◆ BarycentricMesh() [2/3]

template<typename T>
BarycentricMesh ( BarycentricMesh< T > && )
default

◆ BarycentricMesh() [3/3]

template<typename T>
BarycentricMesh ( MeshGrid input_grid)
explicit

Constructs the mesh.

Member Function Documentation

◆ Eval() [1/2]

template<typename T>
VectorX< T > Eval ( const Eigen::Ref< const MatrixX< T > > & mesh_values,
const Eigen::Ref< const VectorX< T > > & input ) const

Returns the function evaluated at input.

◆ Eval() [2/2]

template<typename T>
void Eval ( const Eigen::Ref< const MatrixX< T > > & mesh_values,
const Eigen::Ref< const VectorX< T > > & input,
EigenPtr< VectorX< T > > output ) const

Evaluates the function at the input values, by interpolating between the values at mesh_values.

Inputs that are outside the bounding box of the input_grid are interpolated as though they were projected (elementwise) to the closest face of the defined mesh.

Note that the dimension of the output vector is completely defined by the mesh_values argument. This class does not maintain any information related to the size of the output.

Parameters
mesh_valuesis a num_outputs by get_num_mesh_points() matrix containing the points to interpolate between. The order of the columns must be consistent with the mesh indices curated by this class, as exposed by get_mesh_point().
inputmust be a vector of length get_num_inputs().
outputis the interpolated vector of length num_outputs

◆ EvalBarycentricWeights()

template<typename T>
void EvalBarycentricWeights ( const Eigen::Ref< const VectorX< T > > & input,
EigenPtr< Eigen::VectorXi > mesh_indices,
EigenPtr< VectorX< T > > weights ) const

Writes the mesh indices used for interpolation to mesh_indices, and the interpolating coefficients to weights.

Inputs that are outside the bounding box of the input_grid are interpolated as though they were projected (elementwise) to the closest face of the defined mesh.

Parameters
inputmust be a vector of length get_num_inputs().
mesh_indicesis a pointer to a vector of length get_num_interpolants().
weightsis a vector of coefficients (which sum to 1) of length get_num_interpolants().

◆ EvalWithMixedScalars() [1/2]

template<typename T>
template<typename ValueT = T>
VectorX< ValueT > EvalWithMixedScalars ( const Eigen::Ref< const MatrixX< ValueT > > & mesh_values,
const Eigen::Ref< const VectorX< T > > & input ) const

Returns the function evaluated at input.

◆ EvalWithMixedScalars() [2/2]

template<typename T>
template<typename ValueT = T>
void EvalWithMixedScalars ( const Eigen::Ref< const MatrixX< ValueT > > & mesh_values,
const Eigen::Ref< const VectorX< T > > & input,
EigenPtr< VectorX< ValueT > > output ) const

Performs Eval, but with the possibility of the values on the mesh having a different scalar type than the values defining the mesh (symbolic::Expression containing decision variables for an optimization problem is an important example)

Template Parameters
ValueTdefines the scalar type of the mesh_values and the output.
See also
Eval

◆ get_all_mesh_points()

template<typename T>
MatrixX< T > get_all_mesh_points ( ) const

Returns a matrix with all of the mesh points, one per column.

◆ get_input_grid()

template<typename T>
const MeshGrid & get_input_grid ( ) const

◆ get_input_size()

template<typename T>
int get_input_size ( ) const

◆ get_mesh_point() [1/2]

template<typename T>
VectorX< T > get_mesh_point ( int index) const

Returns the position of a mesh point in the input space referenced by its scalar index to point.

Parameters
indexmust be in [0, get_num_mesh_points).

◆ get_mesh_point() [2/2]

template<typename T>
void get_mesh_point ( int index,
EigenPtr< Eigen::VectorXd > point ) const

Writes the position of a mesh point in the input space referenced by its scalar index to point.

Parameters
indexmust be in [0, get_num_mesh_points).
pointis set to the num_inputs-by-1 location of the mesh point.

◆ get_num_interpolants()

template<typename T>
int get_num_interpolants ( ) const

◆ get_num_mesh_points()

template<typename T>
int get_num_mesh_points ( ) const

◆ MeshValuesFrom()

template<typename T>
MatrixX< T > MeshValuesFrom ( const std::function< VectorX< T >(const Eigen::Ref< const VectorX< T > > &)> & vector_func) const

Evaluates vector_func at all input mesh points and extracts the mesh value matrix that should be used to approximate the function with this barycentric interpolation.

MatrixXd mesh_values = bary.MeshValuesFrom(
[](const auto& x) { return Vector1d(std::sin(x[0])); });
x
Definition light_parameter.h:147
Eigen::Matrix< double, 1, 1 > Vector1d
A column vector of size 1 of doubles.
Definition eigen_types.h:35

◆ operator=() [1/2]

template<typename T>
BarycentricMesh & operator= ( BarycentricMesh< T > && )
default

◆ operator=() [2/2]

template<typename T>
BarycentricMesh & operator= ( const BarycentricMesh< T > & )
default

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