bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
bitrl::maths Namespace Reference

Namespaces

namespace  optim
namespace  stats
namespace  detail_

Classes

class  LpMetric
 The LpMetric class It conforms to the metric policy. More...

Typedefs

using ManhattanMetric = LpMetric<1, false>
 some useful shortcuts
using SqrEuclidean_metric = LpMetric<2, false>
using EuclideanMetric = LpMetric<2, true>

Functions

template<typename MatType>
void exchange_rows (MatType &mat, uint_t r1, uint_t r2)
 Exchange the rows of the matrix.
template<typename MatType>
std::set< uint_t > shuffle_matrix_rows (MatType &mat)
 Shuffle the rows of the matrix. Returns a set with the rows that have been shuffled.
template<typename T>
DynVec< T > get_row (const DynMat< T > &matrix, uint_t row_idx)
 Extract the cidx-th column from the matrix.
template<typename T>
T get_row_max (const DynMat< T > &matrix, uint_t row_idx)
template<typename T>
T get_row_min (const DynMat< T > &matrix, uint_t row_idx)
template<utils::concepts::float_or_integral_vector VectorType>
VectorType element_product (const VectorType &v1, const VectorType &v2)
template<typename IteratorType>
std::iterator_traits< IteratorType >::value_type sum (IteratorType begin, IteratorType end, bool parallel=true)
template<typename VectorType>
VectorType::value_type sum (const VectorType &vec, bool parallel=true)
template<typename IteratorType>
real_t mean (IteratorType begin, IteratorType end, bool parallel=true)
 mean Compute the mean value of the values in the provided iterator range
template<utils::concepts::float_or_integral_vector VectorType>
real_t mean (const VectorType &vector, bool parallel=true)
 mean Computes the mean value of the vector. If parallel=true it uses std::reduce
template<typename T>
real_t mean (const DynVec< T > &vector, bool parallel=true)
 mean computes the mean value of the given DynVec
template<typename IteratorType>
std::iterator_traits< IteratorType >::value_type variance (IteratorType begin, IteratorType end, bool parallel=true)
real_t variance (const std::vector< real_t > &vals, bool parallel=true)
 Compute the variance of the given std::vector of real values.
std::vector< real_t > standardize (const std::vector< real_t > &vals, real_t tol=bitsim::consts::TOLERANCE)
 Standardize the given vector.
template<utils::concepts::float_vector Vec2>
uint_t choice (const Vec2 &probs, uint_t seed=42)
 choice. Implements similar functionality to numpy.choice function
template<utils::concepts::integral_vector Vec1, utils::concepts::float_vector Vec2>
uint_t choice (const Vec1 &choices, const Vec2 &probs, uint_t seed=42)
 choice. Implements similar functionality to numpy.choice function
template<utils::concepts::float_vector Vec>
Vec::value_type choose_value (const Vec &vals, uint_t seed=42)
template<utils::concepts::float_or_integral_vector Vec>
void randomize_vec (Vec &v, const Vec &walk_set, uint_t seed=42)
 Given a vector of intergal or floating point values and a set of values to choose from, randomize the entries ofv.
template<typename T>
std::vector< T > & randomize (std::vector< T > &vec, T a, T b, uint_t seed=42)
 Fill in the given vector with random values.
template<utils::concepts::float_or_integral_vector Vec>
Vec & divide (Vec &v1, typename Vec::value_type val)
template<utils::concepts::float_or_integral_vector Vec>
Vec & add (Vec &v1, const Vec &v2)
template<utils::concepts::float_or_integral_vector VectorType>
VectorType exponentiate (const VectorType &vec)
template<utils::concepts::float_or_integral_vector VectorType>
VectorType exponentiate (const VectorType &vec, typename VectorType::value_type v)
template<utils::concepts::float_or_integral_vector VectorType>
VectorType exponentiate (const torch_tensor_t tensor, typename VectorType::value_type v)
template<typename T>
std::vector< T > softmax_vec (const std::vector< T > &vec, real_t tau=1.0)
 applies softmax operation to the elements of the vector and returns a vector with the result
template<typename T>
DynVec< T > softmax_vec (const DynVec< T > &vec, real_t tau=1.0)
 applies softmax operation to the elements of the vector and returns a vector with the result
template<typename IteratorType>
DynVec< typename IteratorType::value_type > softmax_vec (IteratorType begin, IteratorType end, real_t tau=1.0)
 applies softmax operation to the elements of the vector and returns a vector with the result
template<typename VectorType>
uint_t arg_max (const VectorType &vec)
 Returns the index of the element that has the maximum value in the array. Implementation taken from http://www.jclay.host/dev-journal/simple_cpp_argmax_argmin.html.
template<typename VectorType>
uint_t arg_min (const VectorType &vec)
 Returns the index of the element that has the minimum value in the array. Implementation taken from http://www.jclay.host/dev-journal/simple_cpp_argmax_argmin.html.
template<typename T>
std::vector< uint_t > max_indices (const DynVec< T > &vec)
template<typename VecTp>
std::vector< uint_t > max_indices (const VecTp &vec)
 Returns the indices of vec where the maximum value in vec occurs.
template<typename T>
std::vector< T > extract_subvector (const std::vector< T > &vec, uint_t end, bool up_to=true)
template<typename SequenceTp>
uint_t bin_index (const typename SequenceTp::value_type &x, const SequenceTp &sequence)
 bin_index. Compute sequnce[i - 1] <= x sequnce[i] and returns the index. Sequence should be sorted
template<typename VectorType>
VectorType zero_center (const VectorType &vec, bool parallel=true)
 zero_center. Subtracts the mean value of the given vector from every value of the vector
template<typename VectorType>
VectorType normalize (const VectorType &vec, typename VectorType::value_type v)
 Normalize the values of the given vector with the given value. Essentially this function divides the elements of the vector with the value provided.
template<typename T>
std::vector< T > normalize_max (const std::vector< T > &vec)
template<typename T>
std::vector< T > normalize_min (const std::vector< T > &vec)
std::vector< real_t > logspace (real_t start, real_t end, uint_t num, real_t base=10.0)
template<typename IteratorType>
std::iterator_traits< IteratorType >::value_type dot_product (IteratorType bv1, IteratorType ev1, IteratorType bv2, IteratorType ev2)
template<typename VectorType>
real_t dot_product (const VectorType &v1, const VectorType &v2, uint_t start_idx=0)

Variables

template<int P, bool TTakeRoot>
real_t LpMetric< P, TTakeRoot >::tolerance_value = 1.0e-8

Typedef Documentation

◆ EuclideanMetric

◆ ManhattanMetric

some useful shortcuts

◆ SqrEuclidean_metric

Function Documentation

◆ add()

template<utils::concepts::float_or_integral_vector Vec>
Vec & bitrl::maths::add ( Vec & v1,
const Vec & v2 )

◆ arg_max()

template<typename VectorType>
uint_t bitrl::maths::arg_max ( const VectorType & vec)

Returns the index of the element that has the maximum value in the array. Implementation taken from http://www.jclay.host/dev-journal/simple_cpp_argmax_argmin.html.

◆ arg_min()

template<typename VectorType>
uint_t bitrl::maths::arg_min ( const VectorType & vec)

Returns the index of the element that has the minimum value in the array. Implementation taken from http://www.jclay.host/dev-journal/simple_cpp_argmax_argmin.html.

◆ bin_index()

template<typename SequenceTp>
uint_t bitrl::maths::bin_index ( const typename SequenceTp::value_type & x,
const SequenceTp & sequence )

bin_index. Compute sequnce[i - 1] <= x sequnce[i] and returns the index. Sequence should be sorted

◆ choice() [1/2]

template<utils::concepts::integral_vector Vec1, utils::concepts::float_vector Vec2>
uint_t bitrl::maths::choice ( const Vec1 & choices,
const Vec2 & probs,
uint_t seed = 42 )

choice. Implements similar functionality to numpy.choice function

https://www.cplusplus.com/reference/random/discrete_distribution/

◆ choice() [2/2]

template<utils::concepts::float_vector Vec2>
uint_t bitrl::maths::choice ( const Vec2 & probs,
uint_t seed = 42 )

choice. Implements similar functionality to numpy.choice function

https://www.cplusplus.com/reference/random/discrete_distribution/

◆ choose_value()

template<utils::concepts::float_vector Vec>
Vec::value_type bitrl::maths::choose_value ( const Vec & vals,
uint_t seed = 42 )

◆ divide()

template<utils::concepts::float_or_integral_vector Vec>
Vec & bitrl::maths::divide ( Vec & v1,
typename Vec::value_type val )

◆ dot_product() [1/2]

template<typename VectorType>
real_t bitrl::maths::dot_product ( const VectorType & v1,
const VectorType & v2,
uint_t start_idx = 0 )

◆ dot_product() [2/2]

template<typename IteratorType>
std::iterator_traits< IteratorType >::value_type bitrl::maths::dot_product ( IteratorType bv1,
IteratorType ev1,
IteratorType bv2,
IteratorType ev2 )

◆ element_product()

template<utils::concepts::float_or_integral_vector VectorType>
VectorType bitrl::maths::element_product ( const VectorType & v1,
const VectorType & v2 )

◆ exchange_rows()

template<typename MatType>
void bitrl::maths::exchange_rows ( MatType & mat,
uint_t r1,
uint_t r2 )

Exchange the rows of the matrix.

◆ exponentiate() [1/3]

template<utils::concepts::float_or_integral_vector VectorType>
VectorType bitrl::maths::exponentiate ( const torch_tensor_t tensor,
typename VectorType::value_type v )

◆ exponentiate() [2/3]

template<utils::concepts::float_or_integral_vector VectorType>
VectorType bitrl::maths::exponentiate ( const VectorType & vec)

◆ exponentiate() [3/3]

template<utils::concepts::float_or_integral_vector VectorType>
VectorType bitrl::maths::exponentiate ( const VectorType & vec,
typename VectorType::value_type v )

◆ extract_subvector()

template<typename T>
std::vector< T > bitrl::maths::extract_subvector ( const std::vector< T > & vec,
uint_t end,
bool up_to = true )

◆ get_row()

template<typename T>
DynVec< T > bitrl::maths::get_row ( const DynMat< T > & matrix,
uint_t row_idx )

Extract the cidx-th column from the matrix.

get_column_means. Computes the means of the matrix columns

get_column_variances. Computes the variances of the matrix columns

Extract the row_idx-th row from the matrix

◆ get_row_max()

template<typename T>
T bitrl::maths::get_row_max ( const DynMat< T > & matrix,
uint_t row_idx )

◆ get_row_min()

template<typename T>
T bitrl::maths::get_row_min ( const DynMat< T > & matrix,
uint_t row_idx )

◆ logspace()

std::vector< real_t > bitrl::maths::logspace ( real_t start,
real_t end,
uint_t num,
real_t base = 10.0 )

Return numbers spaced evenly on a log scale. The implementation is inspired from numpy: https://numpy.org/doc/stable/reference/generated/numpy.logspace.html See also: https://quick-bench.com/q/Hs39BWQf5kr5Gjnv6zQkLXMrsDw

The starting point of the scale is: std::pow(base, start) Similarly the endpoint is: std::pow(base, end) The intermediate points are aligned as std::pow(base, point) where point = start + i*dx where dx = (end - start) / (num - 1)

◆ max_indices() [1/2]

template<typename T>
std::vector< uint_t > bitrl::maths::max_indices ( const DynVec< T > & vec)

◆ max_indices() [2/2]

template<typename VecTp>
std::vector< uint_t > bitrl::maths::max_indices ( const VecTp & vec)

Returns the indices of vec where the maximum value in vec occurs.

◆ mean() [1/3]

template<typename T>
real_t bitrl::maths::mean ( const DynVec< T > & vector,
bool parallel = true )

mean computes the mean value of the given DynVec

◆ mean() [2/3]

template<utils::concepts::float_or_integral_vector VectorType>
real_t bitrl::maths::mean ( const VectorType & vector,
bool parallel = true )

mean Computes the mean value of the vector. If parallel=true it uses std::reduce

◆ mean() [3/3]

template<typename IteratorType>
real_t bitrl::maths::mean ( IteratorType begin,
IteratorType end,
bool parallel = true )

mean Compute the mean value of the values in the provided iterator range

◆ normalize()

template<typename VectorType>
VectorType bitrl::maths::normalize ( const VectorType & vec,
typename VectorType::value_type v )

Normalize the values of the given vector with the given value. Essentially this function divides the elements of the vector with the value provided.

Parameters
vec
v
parallel

◆ normalize_max()

template<typename T>
std::vector< T > bitrl::maths::normalize_max ( const std::vector< T > & vec)

◆ normalize_min()

template<typename T>
std::vector< T > bitrl::maths::normalize_min ( const std::vector< T > & vec)

◆ randomize()

template<typename T>
std::vector< T > & bitrl::maths::randomize ( std::vector< T > & vec,
T a,
T b,
uint_t seed = 42 )

Fill in the given vector with random values.

Parameters
vecThe vector to fill in
seedThe seed for the random engine

◆ randomize_vec()

template<utils::concepts::float_or_integral_vector Vec>
void bitrl::maths::randomize_vec ( Vec & v,
const Vec & walk_set,
uint_t seed = 42 )

Given a vector of intergal or floating point values and a set of values to choose from, randomize the entries ofv.

◆ shuffle_matrix_rows()

template<typename MatType>
std::set< uint_t > bitrl::maths::shuffle_matrix_rows ( MatType & mat)

Shuffle the rows of the matrix. Returns a set with the rows that have been shuffled.

◆ softmax_vec() [1/3]

template<typename T>
DynVec< T > bitrl::maths::softmax_vec ( const DynVec< T > & vec,
real_t tau = 1.0 )

applies softmax operation to the elements of the vector and returns a vector with the result

◆ softmax_vec() [2/3]

template<typename T>
std::vector< T > bitrl::maths::softmax_vec ( const std::vector< T > & vec,
real_t tau = 1.0 )

applies softmax operation to the elements of the vector and returns a vector with the result

◆ softmax_vec() [3/3]

template<typename IteratorType>
DynVec< typename IteratorType::value_type > bitrl::maths::softmax_vec ( IteratorType begin,
IteratorType end,
real_t tau = 1.0 )

applies softmax operation to the elements of the vector and returns a vector with the result

◆ standardize()

std::vector< real_t > bitrl::maths::standardize ( const std::vector< real_t > & vals,
real_t tol = bitsim::consts::TOLERANCE )

Standardize the given vector.

◆ sum() [1/2]

template<typename VectorType>
VectorType::value_type bitrl::maths::sum ( const VectorType & vec,
bool parallel = true )

◆ sum() [2/2]

template<typename IteratorType>
std::iterator_traits< IteratorType >::value_type bitrl::maths::sum ( IteratorType begin,
IteratorType end,
bool parallel = true )

◆ variance() [1/2]

real_t bitrl::maths::variance ( const std::vector< real_t > & vals,
bool parallel = true )
inline

Compute the variance of the given std::vector of real values.

◆ variance() [2/2]

template<typename IteratorType>
std::iterator_traits< IteratorType >::value_type bitrl::maths::variance ( IteratorType begin,
IteratorType end,
bool parallel = true )

◆ zero_center()

template<typename VectorType>
VectorType bitrl::maths::zero_center ( const VectorType & vec,
bool parallel = true )

zero_center. Subtracts the mean value of the given vector from every value of the vector

Variable Documentation

◆ LpMetric< P, TTakeRoot >::tolerance_value

template<int P, bool TTakeRoot>
real_t bitrl::maths::LpMetric< P, TTakeRoot >::tolerance_value = 1.0e-8