lucid  0.0.1
Lifting-based Uncertain Control Invariant Dynamics
Loading...
Searching...
No Matches
lucid::TruncatedFourierFeatureMap Class Reference

Truncated Fourier feature map. More...

#include <TruncatedFourierFeatureMap.h>

Inheritance diagram for lucid::TruncatedFourierFeatureMap:
lucid::FeatureMap lucid::ConstantTruncatedFourierFeatureMap lucid::LinearTruncatedFourierFeatureMap lucid::LogTruncatedFourierFeatureMap

Public Member Functions

 TruncatedFourierFeatureMap (int num_frequencies, const Matrix &prob_per_dim, const Matrix &omega_per_dim, ConstVectorRef sigma_l, Scalar sigma_f, const RectSet &X_bounds)
 Construct a truncated Fourier feature map.
 
 TruncatedFourierFeatureMap (int num_frequencies, const Matrix &prob_per_dim, const Matrix &omega_per_dim, double sigma_l, Scalar sigma_f, const RectSet &X_bounds)
 Construct a truncated Fourier feature map.
 
Vector map_vector (ConstVectorRef x) const
 Given a \( \texttip{d}{Dimension of the vector space} \) dimensional vector \( \texttip{x}{Element of the vector space} \), project it to the unit hypercube \( [0, 1]^d \), then compute the feature map.
 
Vector invert_vector (ConstVectorRef y) const
 Given a @2M+1 dimensional vector \( \texttip{y}{Element of the vector space} \), invert the feature map to obtain the original input vector.
 
Matrix map_matrix (ConstMatrixRef x) const
 Given an \( \texttip{n}{Number of samples} \times \texttip{d}{Dimension of the vector space} \) dimensional matrix \( \texttip{x}{Element of the vector space} \), project each row vector to the unit hypercube \( [0, 1]^d \), then compute the feature map.
 
Dimension dimension () const
 Get read-only access to the dimension of the the feature map space.
 
const Matrix & omega () const
 Get read-only access to the frequency matrix of the truncated Fourier feature map.
 
const Vector & weights () const
 Get read-only access to the weights matrix of the truncated Fourier feature map.
 
int num_frequencies () const
 Get read-only access to the number of frequencies per dimension of the truncated Fourier feature map.
 
Scalar captured_probability () const
 Get read-only access to the probability captured by the Fourier expansion of the truncated Fourier feature map.
 
const RectSetX_bounds () const
 Get read-only access to the limits of the original input space.
 
double sigma_f () const
 Get read-only access to the sigma_f value of the truncated Fourier feature map.
 
const Vector & sigma_l () const
 Get read-only access to the sigma_l value of the truncated Fourier feature map.
 
virtual RectSet get_periodic_set () const
 Return the periodic input domain for this linear truncated Fourier map.
 
std::unique_ptr< FeatureMapclone () const override
 Clone the feature map.
 
- Public Member Functions inherited from lucid::FeatureMap
Matrix operator() (ConstMatrixRef x) const
 Apply the feature map to a vector.
 
Matrix invert (ConstMatrixRef y) const
 Apply the inverse feature map to a vector.
 
virtual std::string to_string () const
 Obtain the string representation of this object.
 

Protected Member Functions

Matrix apply_impl (ConstMatrixRef x) const override
 Given an \( \texttip{n}{Number of samples} \times \texttip{d}{Dimension of the vector space} \) dimensional matrix \( \texttip{x}{Element of the vector space} \), project each row vector to the unit hypercube \( [0, 1]^d \), then compute the feature map.
 
Matrix invert_impl (ConstMatrixRef y) const override
 Concrete implementation of invert().
 

Protected Attributes

int num_frequencies_
 Number of frequencies per dimension.
 
Matrix omega_
 Frequencies matrix.
 
Vector weights_
 Weights matrix.
 
Scalar sigma_f_
 \( \sigma_f \) value
 
Vector sigma_l_
 \( \sigma_l \) vector
 
RectSet X_bounds_
 Limits of the input space expressed as a matrix. The set is a rectangle.
 
Scalar captured_probability_
 Probability captured by the Fourier expansion. NaN if not computed.
 

Detailed Description

Truncated Fourier feature map.

It maps vectors from \( \texttip{\mathcal{X}}{Polish sample vector space} \subseteq \mathbb{R}^d \) to a higher-dimensional space using the truncated Fourier series. The number of frequencies, \( M > 0 \), determines the dimension of the output space. All possible combinations of frequencies are computed for each input dimension. Therefore, the output vector has a dimension of \( 2^d M + 1 \). The feature map is computed as

\[\phi_{M}(x) = \sigma_{f}\begin{bmatrix} w_{0}\\ \sqrt{2}w_{1}\cos(\omega_{1}^{\top}P(x))\\ \sqrt{2}w_{1}\sin(\omega_{1}^{\top}P(x))\\ \vdots\\ \sqrt{2}w_{M}\cos(\omega_{M}^{\top}P(x))\\ \sqrt{2}w_{M}\sin(\omega_{M}^{\top}P(x)) \end{bmatrix}, \]

The way the weights and omegas are computed depends on the subclass.

Constructor & Destructor Documentation

◆ TruncatedFourierFeatureMap() [1/2]

lucid::TruncatedFourierFeatureMap::TruncatedFourierFeatureMap ( int num_frequencies,
const Matrix & prob_per_dim,
const Matrix & omega_per_dim,
ConstVectorRef sigma_l,
Scalar sigma_f,
const RectSet & X_bounds )

Construct a truncated Fourier feature map.

Precondition
num_frequencies must be greater than 0.
sigma_f must be greater than 0.
Parameters
num_frequenciesnumber of frequencies per dimension. Includes the zero frequency
prob_per_dimprobability distribution of frequencies per dimension, \( \mathbb{P}(\zeta_j) \)
omega_per_dimmatrix omega where each row is a dimension and each column is a frequency coefficient
sigma_llength scales per dimension
sigma_fscaling factor
X_boundsdomain of the input space, \( \texttip{\mathcal{X}}{Polish sample vector space} \subseteq \mathbb{R}^d \)

◆ TruncatedFourierFeatureMap() [2/2]

lucid::TruncatedFourierFeatureMap::TruncatedFourierFeatureMap ( int num_frequencies,
const Matrix & prob_per_dim,
const Matrix & omega_per_dim,
double sigma_l,
Scalar sigma_f,
const RectSet & X_bounds )

Construct a truncated Fourier feature map.

Precondition
num_frequencies must be greater than 0.
sigma_f must be greater than 0.
Parameters
num_frequenciesnumber of frequencies per dimension. Includes the zero frequency
prob_per_dimprobability distribution of frequencies per dimension, \( \mathbb{P}(\zeta_j) \)
omega_per_dimmatrix omega where each row is a dimension and each column is a frequency coefficient
sigma_llength scales per dimension
sigma_fscaling factor
X_boundsdomain of the input space, \( \texttip{\mathcal{X}}{Polish sample vector space} \subseteq \mathbb{R}^d \)

Member Function Documentation

◆ apply_impl()

Matrix lucid::TruncatedFourierFeatureMap::apply_impl ( ConstMatrixRef x) const
nodiscardoverrideprotectedvirtual

Given an \( \texttip{n}{Number of samples} \times \texttip{d}{Dimension of the vector space} \) dimensional matrix \( \texttip{x}{Element of the vector space} \), project each row vector to the unit hypercube \( [0, 1]^d \), then compute the feature map.

Parameters
xinput vector
Returns
\( n \times 2 M + 1 \) dimensional feature map

Implements lucid::FeatureMap.

◆ captured_probability()

Scalar lucid::TruncatedFourierFeatureMap::captured_probability ( ) const
inlinenodiscard

Get read-only access to the probability captured by the Fourier expansion of the truncated Fourier feature map.

NaN if not computed

Returns
probability captured by the Fourier expansion of the truncated Fourier feature map

◆ clone()

std::unique_ptr< FeatureMap > lucid::TruncatedFourierFeatureMap::clone ( ) const
nodiscardoverridevirtual

Clone the feature map.

Create a new instance of the feature map with the same parameters.

Returns
new instance of the feature map

Implements lucid::FeatureMap.

◆ dimension()

Dimension lucid::TruncatedFourierFeatureMap::dimension ( ) const
inlinenodiscard

Get read-only access to the dimension of the the feature map space.

Returns
dimension of the the feature map space

◆ get_periodic_set()

RectSet lucid::TruncatedFourierFeatureMap::get_periodic_set ( ) const
nodiscardvirtual

Return the periodic input domain for this linear truncated Fourier map.

We want to find a space such that the smallest frequency is able to complete a full period. Given that frequencies are defined as \( \omega P(x) \), where \( P(x) \) is the projection to the unit hypercube of the original domain, we want to find the upper bound of the periodic domain \( \bar{x} \) such that

\[\omega P(\bar{x}) = 2\pi \]

for the smallest \( \omega \). Graphically,

New max (x̄)
┌───────────────────────────────●
│ │
│ │
│ Old max │
├───────────────────────● │
│ │ │
│ │ │
│ │ │
│ │ │
│ Min │ │
●───────────────────────┴───────┘

Notice how the lower bound remains fixed, while the upper bound is shifted to create the periodic domain.

Note
The periodic domain could be smaller than the original domain, depending on the values of \( \sigma_l \).
Precondition
\( \sigma_l \) must have the same dimension as the input space.
All values in \( \sigma_l \) must be greater than 0.
Returns
new RectSet representing the periodic input domain

Reimplemented in lucid::ConstantTruncatedFourierFeatureMap, and lucid::LinearTruncatedFourierFeatureMap.

◆ invert_impl()

Matrix lucid::TruncatedFourierFeatureMap::invert_impl ( ConstMatrixRef y) const
nodiscardoverrideprotectedvirtual

Concrete implementation of invert().

Parameters
y\( n \times M \) input vector in the feature space
Returns
\( \texttip{n}{Number of samples} \times \texttip{d}{Dimension of the vector space} \) output in the original space

Implements lucid::FeatureMap.

◆ invert_vector()

Vector lucid::TruncatedFourierFeatureMap::invert_vector ( ConstVectorRef y) const
nodiscard

Given a @2M+1 dimensional vector \( \texttip{y}{Element of the vector space} \), invert the feature map to obtain the original input vector.

Precondition
\( \texttip{y}{Element of the vector space} \) must have the same dimension as the feature map output.
Parameters
yinput vector in the feature space
Returns
\( \texttip{d}{Dimension of the vector space} \) dimensional output in the original space

◆ map_matrix()

Matrix lucid::TruncatedFourierFeatureMap::map_matrix ( ConstMatrixRef x) const
nodiscard

Given an \( \texttip{n}{Number of samples} \times \texttip{d}{Dimension of the vector space} \) dimensional matrix \( \texttip{x}{Element of the vector space} \), project each row vector to the unit hypercube \( [0, 1]^d \), then compute the feature map.

Parameters
xinput vector
Returns
\( n \times 2 M + 1 \) dimensional feature map

◆ map_vector()

Vector lucid::TruncatedFourierFeatureMap::map_vector ( ConstVectorRef x) const
nodiscard

Given a \( \texttip{d}{Dimension of the vector space} \) dimensional vector \( \texttip{x}{Element of the vector space} \), project it to the unit hypercube \( [0, 1]^d \), then compute the feature map.

Parameters
xinput vector
Returns
\( 2 M + 1 \) dimensional feature map

◆ num_frequencies()

int lucid::TruncatedFourierFeatureMap::num_frequencies ( ) const
inlinenodiscard

Get read-only access to the number of frequencies per dimension of the truncated Fourier feature map.

Returns
number of frequencies per dimension of the truncated Fourier feature map

◆ omega()

const Matrix & lucid::TruncatedFourierFeatureMap::omega ( ) const
inlinenodiscard

Get read-only access to the frequency matrix of the truncated Fourier feature map.

Returns
frequency matrix of the truncated Fourier feature map

◆ sigma_f()

double lucid::TruncatedFourierFeatureMap::sigma_f ( ) const
inlinenodiscard

Get read-only access to the sigma_f value of the truncated Fourier feature map.

Returns
sigma_f value of the truncated Fourier feature map

◆ sigma_l()

const Vector & lucid::TruncatedFourierFeatureMap::sigma_l ( ) const
inlinenodiscard

Get read-only access to the sigma_l value of the truncated Fourier feature map.

Returns
sigma_l value of the truncated Fourier feature map

◆ weights()

const Vector & lucid::TruncatedFourierFeatureMap::weights ( ) const
inlinenodiscard

Get read-only access to the weights matrix of the truncated Fourier feature map.

Returns
weights matrix of the truncated Fourier feature map

◆ X_bounds()

const RectSet & lucid::TruncatedFourierFeatureMap::X_bounds ( ) const
inlinenodiscard

Get read-only access to the limits of the original input space.

Returns
limits of the original input space

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