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

Rectangular set over an arbitrary number of dimensions. More...

#include <RectSet.h>

Inheritance diagram for lucid::RectSet:
lucid::Set

Public Member Functions

 RectSet (Vector lb, Vector ub)
 Construct a rectangular set from lower and upper bounds.
 
 RectSet (std::initializer_list< Scalar > lb, std::initializer_list< Scalar > ub)
 Construct a rectangular set from lower and upper bounds.
 
 RectSet (const std::vector< std::pair< Scalar, Scalar > > &bounds)
 Construct a rectangular set from lower and upper bounds.
 
 RectSet (std::initializer_list< std::pair< Scalar, Scalar > > bounds)
 Construct a rectangular set from lower and upper bounds.
 
Dimension dimension () const override
 Get read-only access to the dimension of the set \( \texttip{\mathcal{X}}{Polish sample vector space} \).
 
const Vector & lower_bound () const
 Get read-only access to the lower bound of the rectangular set.
 
Vector general_lower_bound () const override
 Get read-only access to the lower bound of the smallest rectangular set including the whole set.
 
const Vector & upper_bound () const
 Get read-only access to the upper bound of the rectangular set.
 
Vector general_upper_bound () const override
 Get read-only access to the upper bound of the smallest rectangular set including the whole set.
 
Vector sizes () const
 Get read-only access to the size for each dimension of the rectangular set.
 
Matrix sample (Index num_samples) const override
 Extract \( N \) elements from \( \texttip{\mathcal{X}}{Polish sample vector space} \) using some kind of random distribution.
 
bool operator() (ConstVectorRef x) const override
 Check if a vector is in \( \texttip{\mathcal{X}}{Polish sample vector space} \).
 
Matrix lattice (const VectorI &points_per_dim, bool endpoint) const override
 Generate a lattice of points in the set.
 
void change_size (ConstVectorRef delta_size) override
 Change the size of the set.
 
std::unique_ptr< Setto_rect_set () const override
 Convert the set to a rectangular set.
 
RectSet relative_to (const RectSet &set) const
 Compute the rectangular set relative to another rectangular set.
 
RectSet relative_to (ConstVectorRef point) const
 Compute the rectangular set relative a new origin point.
 
RectSet scale (ConstVectorRef scale) const
 Scale the rectangular set by the given factor(s).
 
RectSet scale (double scale) const
 Scale the rectangular set by the given factor.
 
RectSet scale (ConstVectorRef scale, const RectSet &bounds, bool relative_to_bounds=false) const
 Scale the rectangular set by the given factor(s) while keeping it inside the given bounds.
 
RectSet scale (double scale, const RectSet &bounds, bool relative_to_bounds=false) const
 Scale the rectangular set by the given factor while keeping it inside the given bounds.
 
 operator Matrix () const
 Convert the rectangular set to a matrix representation.
 
std::string to_string () const override
 Obtain the string representation of this object.
 
std::unique_ptr< Setclone () const override
 Clone the set.
 
void change_size (double delta_size)
 Change the size of the set.
 
Matrix lattice (Index points_per_dim, bool endpoint=false) const
 Generate a lattice of points in the set.
 
- Public Member Functions inherited from lucid::Set
Vector sample () const
 Extract an element from \( \texttip{\mathcal{X}}{Polish sample vector space} \) using some kind of random distribution.
 
bool contains (ConstVectorRef x) const
 Check if a vector is in \( \texttip{\mathcal{X}}{Polish sample vector space} \).
 
bool contains_wrapped (ConstVectorRef x, ConstVectorRef period, Dimension num_periods) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool contains_wrapped (ConstVectorRef x, ConstVectorRef period, const std::vector< Dimension > &num_periods) const
 Check if a vector is in \( \texttip{\mathcal{X}}{Polish sample vector space} \), having the vector wrapped around a given period.
 
bool contains_wrapped (ConstVectorRef x, ConstVectorRef period, Dimension num_periods_below, Dimension num_periods_above) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool contains_wrapped (ConstVectorRef x, ConstVectorRef period, const std::vector< Dimension > &num_periods_below, const std::vector< Dimension > &num_periods_above) const
 Check if a vector is in \( \texttip{\mathcal{X}}{Polish sample vector space} \), having the vector wrapped around a given period.
 
bool contains_wrapped (ConstVectorRef x, ConstVectorRef period) const
 Check if a vector is in \( \texttip{\mathcal{X}}{Polish sample vector space} \), having the vector wrapped around a given period.
 
Matrix include (ConstMatrixRef xs) const
 Filter a set xs, returning only the row vectors that are in \( \texttip{\mathcal{X}}{Polish sample vector space} \).
 
std::vector< Index > include_mask (ConstMatrixRef xs) const
 Filter a set xs, returning a mask containing the indices corresponding to the row vectors that are in \( \texttip{\mathcal{X}}{Polish sample vector space} \).
 
std::vector< Index > include_mask_wrapped (ConstMatrixRef xs, ConstVectorRef period) const
 Filter a set xs, returning a mask containing the indices corresponding to the row vectors that are in \( \texttip{\mathcal{X}}{Polish sample vector space} \), accounting for wrapping around a given period.
 
Matrix exclude (ConstMatrixRef xs) const
 Filter xs, return only the row vectors that are NOT in \( \texttip{\mathcal{X}}{Polish sample vector space} \).
 
std::vector< Index > exclude_mask (ConstMatrixRef xs) const
 Filter a set xs, returning a mask containing the indices corresponding to the row vectors that are NOT in \( \texttip{\mathcal{X}}{Polish sample vector space} \).
 
std::vector< Index > exclude_mask_wrapped (ConstMatrixRef xs, ConstVectorRef period) const
 Filter a set xs, returning a mask containing the indices corresponding to the row vectors that are NOT in \( \texttip{\mathcal{X}}{Polish sample vector space} \), accounting for wrapping around a given period.
 
std::pair< std::vector< Index >, std::vector< Index > > include_exclude_masks (ConstMatrixRef xs) const
 Filter a set xs, returning masks containing the indices corresponding to the row vectors that are in \( \texttip{\mathcal{X}}{Polish sample vector space} \) and NOT in \( \texttip{\mathcal{X}}{Polish sample vector space} \).
 
std::pair< std::vector< Index >, std::vector< Index > > include_exclude_masks_wrapped (ConstMatrixRef xs, ConstVectorRef period) const
 Filter a set xs, returning masks containing the indices corresponding to the row vectors that are in \( \texttip{\mathcal{X}}{Polish sample vector space} \) and NOT in \( \texttip{\mathcal{X}}{Polish sample vector space} \), accounting for wrapping around a given period.
 
std::pair< std::vector< Index >, std::vector< Index > > include_exclude_masks_wrapped (ConstMatrixRef xs, const RectSet &period) const
 Filter a set xs, returning masks containing the indices corresponding to the row vectors that are in \( \texttip{\mathcal{X}}{Polish sample vector space} \) and NOT in \( \texttip{\mathcal{X}}{Polish sample vector space} \), accounting for wrapping around a given period.
 
std::unique_ptr< Setscale_wrapped (double scale, const RectSet &bounds, bool relative_to_bounds=false) const
 Scale the set by the given factor while keeping it inside the given bounds.
 
std::unique_ptr< Setscale_wrapped (ConstVectorRef scale, const RectSet &bounds, bool relative_to_bounds=false) const
 Scale the set by the given factor while keeping it inside the given bounds.
 
template<bool Inplace = false>
requires (!Inplace)
std::unique_ptr< Setincrease_size (ConstVectorRef size_increase) const
 Increase the size of the set.
 
template<bool Inplace = false>
requires (Inplace)
void increase_size (ConstVectorRef size_increase)
 Increase the size of the set.
 
void change_size (double delta_size)
 Change the size of the set.
 
Matrix lattice (Index points_per_dim, bool endpoint=false) const
 Generate a lattice of points in the set.
 
virtual std::unique_ptr< Setto_anisotropic () const
 Create a new anisotropic set.
 
template<class Derived>
Eigen::MatrixBase< Derived > & operator>> (Eigen::MatrixBase< Derived > &x) const
 Extract \( N \) elements element from \( \texttip{\mathcal{X}}{Polish sample vector space} \) using some kind of random distribution, where \( N \) is the number of rows in \( \texttip{x}{Element of the vector space} \).
 

Private Member Functions

std::unique_ptr< Setscale_wrapped_impl (ConstVectorRef scale, const RectSet &bounds, bool relative_to_bounds) const override
 Scale the rectangular set by the given factor while keeping it inside the given bounds.
 
void increase_size_impl (ConstVectorRef size_increase) override
 Increase the size of the set.
 

Private Attributes

Vector lb_
 Lower bound vector.
 
Vector ub_
 Upper bound vector.
 

Detailed Description

Rectangular set over an arbitrary number of dimensions.

A vector \( \texttip{x}{Element of the vector space} \) is in the set if \( lb_i \le x_i \le ub_i \) for all components of the vector.

Constructor & Destructor Documentation

◆ RectSet() [1/4]

lucid::RectSet::RectSet ( Vector lb,
Vector ub )

Construct a rectangular set from lower and upper bounds.

Both bounds must belong to the same vector space.

Parameters
lblower bound vector
ubupper bound vector

◆ RectSet() [2/4]

lucid::RectSet::RectSet ( std::initializer_list< Scalar > lb,
std::initializer_list< Scalar > ub )

Construct a rectangular set from lower and upper bounds.

Both bounds must belong to the same vector space.

Parameters
lblower bound vector
ubupper bound vector

◆ RectSet() [3/4]

lucid::RectSet::RectSet ( const std::vector< std::pair< Scalar, Scalar > > & bounds)
explicit

Construct a rectangular set from lower and upper bounds.

Both bounds must belong to the same vector space.

Parameters
boundsvector of pairs of lower and upper bounds

◆ RectSet() [4/4]

lucid::RectSet::RectSet ( std::initializer_list< std::pair< Scalar, Scalar > > bounds)

Construct a rectangular set from lower and upper bounds.

Both bounds must belong to the same vector space.

Parameters
boundsvector of pairs of lower and upper bounds

Member Function Documentation

◆ change_size() [1/2]

void lucid::RectSet::change_size ( ConstVectorRef delta_size)
overridevirtual

Change the size of the set.

The size change can be different for each dimension. For example, for a rectangular set, this would change the lower and upper bounds so that the original set sits in the center of the new set, which has its size changed by the specified amounts.

Precondition
The set must support size changes.
The size of delta_size must be equal to the dimension of the set.
The new size must be non-negative in all dimensions.
Parameters
delta_sizevector of amounts to change the size of the set for each dimension

Reimplemented from lucid::Set.

◆ change_size() [2/2]

void lucid::Set::change_size ( double delta_size)

Change the size of the set.

The size change can be different for each dimension. For example, for a rectangular set, this would change the lower and upper bounds so that the original set sits in the center of the new set, which has its size changed by the specified amounts.

Precondition
The set must support size changes.
The new size must be non-negative in all dimensions.
Parameters
delta_sizeamount to change the size of the set

◆ clone()

std::unique_ptr< Set > lucid::RectSet::clone ( ) const
nodiscardoverridevirtual

Clone the set.

Create a new instance of the set with the same properties as the current one.

Returns
new instance of the set

Implements lucid::Set.

◆ dimension()

Dimension lucid::RectSet::dimension ( ) const
inlinenodiscardoverridevirtual

Get read-only access to the dimension of the set \( \texttip{\mathcal{X}}{Polish sample vector space} \).

Returns
dimension of the set \( \texttip{\mathcal{X}}{Polish sample vector space} \)

Implements lucid::Set.

◆ general_lower_bound()

Vector lucid::RectSet::general_lower_bound ( ) const
inlinenodiscardoverridevirtual

Get read-only access to the lower bound of the smallest rectangular set including the whole set.

Returns
lower bound of the smallest rectangular set including the whole set

Reimplemented from lucid::Set.

◆ general_upper_bound()

Vector lucid::RectSet::general_upper_bound ( ) const
inlinenodiscardoverridevirtual

Get read-only access to the upper bound of the smallest rectangular set including the whole set.

Returns
upper bound of the smallest rectangular set including the whole set

Reimplemented from lucid::Set.

◆ increase_size_impl()

void lucid::RectSet::increase_size_impl ( ConstVectorRef size_increase)
overrideprivatevirtual

Increase the size of the set.

The size increase can be different for each dimension. The increase is applied symmetrically around the center of the set such that the total size after the increase is equal to the original size plus size_increase.

Precondition
The set must support size changes.
The size of scale must be equal to the dimension of the set.
The new size must be non-negative in all dimensions.
Parameters
size_increaseamount to increase the size of the set for each dimension

Reimplemented from lucid::Set.

◆ lattice() [1/2]

Matrix lucid::RectSet::lattice ( const VectorI & points_per_dim,
bool endpoint ) const
nodiscardoverridevirtual

Generate a lattice of points in the set.

In python, this would be implemented as:

import numpy as np
def build_lattice(points_per_dim, endpoint):
# self.lb_ and self.ub_ are the lower and upper bounds of the rectangular set
grids = [np.linspace(l, u, n, endpoint) for l, u, n in zip(self.lb_, self.ub_, points_per_dim)]
mesh = np.meshgrid(*grids, indexing="xy")
pts = np.vstack([m.ravel() for m in mesh]).T
return pts
Parameters
points_per_dimnumber of points per each dimension
endpointwhether to include the endpoints of the lattice
Returns
lattice of points in the set

Implements lucid::Set.

◆ lattice() [2/2]

Matrix lucid::Set::lattice ( Index points_per_dim,
bool endpoint = false ) const
nodiscard

Generate a lattice of points in the set.

Parameters
points_per_dimnumber of points per each dimension
endpointwhether to include the endpoints of the lattice
Returns
lattice of points in the set

◆ lower_bound()

const Vector & lucid::RectSet::lower_bound ( ) const
inlinenodiscard

Get read-only access to the lower bound of the rectangular set.

Returns
lower bound of the rectangular set

◆ operator Matrix()

lucid::RectSet::operator Matrix ( ) const

Convert the rectangular set to a matrix representation.

Returns
matrix where the first row contains lower bounds and the second row contains upper bounds

◆ operator()()

bool lucid::RectSet::operator() ( ConstVectorRef x) const
nodiscardoverridevirtual

Check if a vector is in \( \texttip{\mathcal{X}}{Polish sample vector space} \).

Precondition
\( \texttip{x}{Element of the vector space} \) must have the same dimension as the set
Parameters
xvector to test
Returns
true if \( \texttip{x}{Element of the vector space} \) is in the set
false if \( \texttip{x}{Element of the vector space} \) is not in the set

Implements lucid::Set.

◆ relative_to() [1/2]

RectSet lucid::RectSet::relative_to ( const RectSet & set) const
nodiscard

Compute the rectangular set relative to another rectangular set.

Instead of absolute coordinates, the new rectangular set will be expressed in coordinates relative to the lower bound of the other rectangular set.

Precondition
The two rectangular sets must have the same dimension.
Parameters
setother rectangular set
Returns
new rectangular set expressed in relative coordinates

◆ relative_to() [2/2]

RectSet lucid::RectSet::relative_to ( ConstVectorRef point) const
nodiscard

Compute the rectangular set relative a new origin point.

Instead of absolute coordinates, the new rectangular set will be expressed in coordinates relative to the given point.

Precondition
The point must have the same dimension as the rectangular set.
Parameters
pointpoint representing the new origin
Returns
new rectangular set expressed in relative coordinates

◆ sample()

Matrix lucid::RectSet::sample ( Index num_samples) const
nodiscardoverridevirtual

Extract \( N \) elements from \( \texttip{\mathcal{X}}{Polish sample vector space} \) using some kind of random distribution.

Note
The seed for the random number generator can be set using random::seed.
Precondition
num_samples must be greater than 0
Parameters
num_samplesnumber of samples to generate \( N \)
Returns
\( \texttip{n}{Number of samples} \times \texttip{d}{Dimension of the vector space} \) matrix of samples, where \( \texttip{d}{Dimension of the vector space} \) is the dimension of \( \texttip{\mathcal{X}}{Polish sample vector space} \). In other words, the samples are stored as rows vectors in the matrix

Implements lucid::Set.

◆ scale() [1/4]

RectSet lucid::RectSet::scale ( ConstVectorRef scale) const
nodiscard

Scale the rectangular set by the given factor(s).

The scaling is performed with respect to the center of the rectangular set.

Parameters
scalescaling factor(s) for each dimension
Returns
new scaled rectangular set

◆ scale() [2/4]

RectSet lucid::RectSet::scale ( ConstVectorRef scale,
const RectSet & bounds,
bool relative_to_bounds = false ) const
nodiscard

Scale the rectangular set by the given factor(s) while keeping it inside the given bounds.

The scaling is performed with respect to the center of the rectangular set. The scaling factor can be computed relative to either

  • the current size of the rectangular set;
  • the size of the bounding rectangular set.
    Parameters
    scalescaling factor(s) for each dimension
    boundsbounding rectangular set
    relative_to_boundsif true, the scaling factor is computed relative to the size of the bounding rectangular set; if false, the scaling factor is computed relative to the current size of the rectangular
    Returns
    new scaled rectangular set

◆ scale() [3/4]

RectSet lucid::RectSet::scale ( double scale) const
nodiscard

Scale the rectangular set by the given factor.

The scaling is performed with respect to the center of the rectangular set.

Parameters
scalescaling factor
Returns
new scaled rectangular set

◆ scale() [4/4]

RectSet lucid::RectSet::scale ( double scale,
const RectSet & bounds,
bool relative_to_bounds = false ) const
nodiscard

Scale the rectangular set by the given factor while keeping it inside the given bounds.

The scaling is performed with respect to the center of the rectangular set. The scaling factor can be computed relative to either

  • the current size of the rectangular set;
  • the size of the bounding rectangular set.
    Parameters
    scalescaling factor
    boundsbounding rectangular set
    relative_to_boundsif true, the scaling factor is computed relative to the size of the bounding rectangular set; if false, the scaling factor is computed relative to the current size of the rectangular
    Returns
    new scaled rectangular set

◆ scale_wrapped_impl()

std::unique_ptr< Set > lucid::RectSet::scale_wrapped_impl ( ConstVectorRef scale,
const RectSet & bounds,
bool relative_to_bounds ) const
nodiscardoverrideprivatevirtual

Scale the rectangular set by the given factor while keeping it inside the given bounds.

If any dimension exceeds the bounds after scaling, it is wrapped around to the other side, as another rectangular set. The scaling is performed with respect to the center of the rectangular set. The scaling factor can be computed relative to either

  • the current size of the rectangular set;
  • the size of the bounding rectangular set.
    Parameters
    scalescaling factor
    boundsbounding rectangular set
    relative_to_boundsif true, the scaling factor is computed relative to the size of the bounding rectangular set; if false, the scaling factor is computed relative to the current size of the rectangular
    Returns
    new scaled rectangular set

Reimplemented from lucid::Set.

◆ sizes()

Vector lucid::RectSet::sizes ( ) const
inlinenodiscard

Get read-only access to the size for each dimension of the rectangular set.

Returns
size for each dimension of the rectangular set

◆ to_rect_set()

std::unique_ptr< Set > lucid::RectSet::to_rect_set ( ) const
nodiscardoverridevirtual

Convert the set to a rectangular set.

Not all sets can be converted to rectangular sets. If the set cannot be converted, an exception is thrown.

Returns
unique pointer to the rectangular set

Reimplemented from lucid::Set.

◆ to_string()

std::string lucid::RectSet::to_string ( ) const
nodiscardoverridevirtual

Obtain the string representation of this object.

Returns
string representation of this object

Reimplemented from lucid::Set.

◆ upper_bound()

const Vector & lucid::RectSet::upper_bound ( ) const
inlinenodiscard

Get read-only access to the upper bound of the rectangular set.

Returns
upper bound of the rectangular set

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