Drake
BarycentricMesh< T > Class Template Reference

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

#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. More...
 
typedef std::vector< CoordinatesMeshGrid
 

Public Member Functions

 BarycentricMesh (MeshGrid input_grid)
 Constructs the mesh. More...
 
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. More...
 
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. More...
 
MatrixX< T > get_all_mesh_points () const
 Returns a matrix with all of the mesh points, one per column. More...
 
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. More...
 
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. More...
 
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. More...
 
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) More...
 
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. More...
 
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. More...
 
Implements CopyConstructible, CopyAssignable, MoveConstructible, MoveAssignable
 BarycentricMesh (const BarycentricMesh &)=default
 
BarycentricMeshoperator= (const BarycentricMesh &)=default
 
 BarycentricMesh (BarycentricMesh &&)=default
 
BarycentricMeshoperator= (BarycentricMesh &&)=default
 

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 vector element type, which must be a valid Eigen scalar.

Instantiated templates for the following kinds of T's are provided:

  • double

Member Typedef Documentation

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).

Constructor & Destructor Documentation

BarycentricMesh ( const BarycentricMesh< T > &  )
default
BarycentricMesh ( BarycentricMesh< T > &&  )
default
BarycentricMesh ( MeshGrid  input_grid)
explicit

Constructs the mesh.

Here is the call graph for this function:

Member Function Documentation

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

Here is the caller graph for this function:

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.

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().

Here is the call graph for this function:

Here is the caller graph for this function:

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

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

Here is the call graph for this function:

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

Returns the function evaluated at input.

Here is the call graph for this function:

MatrixX< T > get_all_mesh_points ( ) const

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

Here is the call graph for this function:

Here is the caller graph for this function:

const MeshGrid& get_input_grid ( ) const
inline
int get_input_size ( ) const
inline

Here is the caller graph for this function:

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.

Here is the call graph for this function:

Here is the caller graph for this function:

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).

Here is the call graph for this function:

int get_num_interpolants ( ) const
inline

Here is the call graph for this function:

Here is the caller graph for this function:

int get_num_mesh_points ( ) const
inline

Here is the caller graph for this function:

MatrixX< T > MeshValuesFrom ( ) 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.

Example usages: MatrixXd mesh_values = bary.MeshValuesFrom( [](const auto& x) { return Vector1d(std::sin(x[0])); });

Here is the call graph for this function:

Here is the caller graph for this function:

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

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