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
T | The scalar type, which must be double . |
#include <drake/math/barycentric.h>
Public Types | |
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. More... | |
typedef std::vector< Coordinates > | MeshGrid |
Public Member Functions | |
BarycentricMesh (MeshGrid input_grid) | |
Constructs the mesh. More... | |
const MeshGrid & | get_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 | |
BarycentricMesh & | operator= (const BarycentricMesh &)=default |
BarycentricMesh (BarycentricMesh &&)=default | |
BarycentricMesh & | operator= (BarycentricMesh &&)=default |
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).
typedef std::vector<Coordinates> MeshGrid |
|
default |
|
default |
|
explicit |
Constructs the mesh.
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.
mesh_values | is 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(). |
input | must be a vector of length get_num_inputs(). |
output | is the interpolated vector of length num_outputs |
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.
input | must be a vector of length get_num_inputs(). |
mesh_indices | is a pointer to a vector of length get_num_interpolants(). |
weights | is a vector of coefficients (which sum to 1) of length get_num_interpolants(). |
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)
ValueT | defines the scalar type of the mesh_values and the output. |
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> get_all_mesh_points | ( | ) | const |
Returns a matrix with all of the mesh points, one per column.
const MeshGrid& get_input_grid | ( | ) | const |
int get_input_size | ( | ) | const |
Writes the position of a mesh point in the input space referenced by its scalar index to point
.
index | must be in [0, get_num_mesh_points). |
point | is set to the num_inputs-by-1 location of the mesh point. |
Returns the position of a mesh point in the input space referenced by its scalar index to point
.
index | must be in [0, get_num_mesh_points). |
int get_num_interpolants | ( | ) | const |
int get_num_mesh_points | ( | ) | const |
MatrixX<T> MeshValuesFrom | ( | ) |
|
default |
|
default |