bitrl & cuberl Documentation
Simulation engine for reinforcement learning agents
Loading...
Searching...
No Matches
vector_math.h File Reference
#include "cuberl/base/cubeai_config.h"
#include "cuberl/base/cuberl_types.h"
#include "cuberl/utils/cubeai_concepts.h"
#include "bitrl/bitrl_consts.h"
#include <cmath>
#include <algorithm>
#include <execution>
#include <random>
#include <iterator>
#include <iostream>
#include <stdexcept>
Include dependency graph for vector_math.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  cuberl::maths::detail_::randomize_handler< real_t >
 
struct  cuberl::maths::detail_::randomize_handler< float_t >
 

Namespaces

namespace  cuberl
 Various utilities used when working with RL problems.
 
namespace  cuberl::maths
 
namespace  cuberl::maths::detail_
 

Functions

template<utils::concepts::float_or_integral_vector VectorType>
VectorType cuberl::maths::element_product (const VectorType &v1, const VectorType &v2)
 
template<typename IteratorType >
std::iterator_traits< IteratorType >::value_type cuberl::maths::sum (IteratorType begin, IteratorType end, bool parallel=true)
 
template<typename VectorType >
VectorType::value_type cuberl::maths::sum (const VectorType &vec, bool parallel=true)
 
template<typename IteratorType >
real_t cuberl::maths::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 cuberl::maths::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 cuberl::maths::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 cuberl::maths::variance (IteratorType begin, IteratorType end, bool parallel=true)
 
real_t cuberl::maths::variance (const std::vector< real_t > &vals, bool parallel=true)
 Compute the variance of the given std::vector of real values.
 
std::vector< real_tcuberl::maths::standardize (const std::vector< real_t > &vals, real_t tol=bitrl::consts::TOLERANCE)
 Standardize the given vector.
 
template<utils::concepts::float_vector Vec2>
uint_t cuberl::maths::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 cuberl::maths::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 cuberl::maths::choose_value (const Vec &vals, uint_t seed=42)
 
template<utils::concepts::float_or_integral_vector Vec>
void cuberl::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.
 
template<typename T >
std::vector< T > & cuberl::maths::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 & cuberl::maths::divide (Vec &v1, typename Vec::value_type val)
 
template<utils::concepts::float_or_integral_vector Vec>
Vec & cuberl::maths::add (Vec &v1, const Vec &v2)
 
template<utils::concepts::float_or_integral_vector VectorType>
VectorType cuberl::maths::exponentiate (const VectorType &vec)
 
template<utils::concepts::float_or_integral_vector VectorType>
VectorType cuberl::maths::exponentiate (const VectorType &vec, typename VectorType::value_type v)
 
template<typename T >
std::vector< T > cuberl::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
 
template<typename T >
DynVec< T > cuberl::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
 
template<typename IteratorType >
DynVec< typename IteratorType::value_type > cuberl::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
 
template<typename VectorType >
uint_t cuberl::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.
 
template<typename VectorType >
uint_t cuberl::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.
 
template<typename T >
std::vector< uint_tcuberl::maths::max_indices (const DynVec< T > &vec)
 
template<typename VecTp >
std::vector< uint_tcuberl::maths::max_indices (const VecTp &vec)
 Returns the indices of vec where the maximum value in vec occurs.
 
template<typename T >
std::vector< T > cuberl::maths::extract_subvector (const std::vector< T > &vec, uint_t end, bool up_to=true)
 
template<typename SequenceTp >
uint_t cuberl::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
 
template<typename VectorType >
VectorType cuberl::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
 
template<typename VectorType >
VectorType cuberl::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.
 
template<typename T >
std::vector< T > cuberl::maths::normalize_max (const std::vector< T > &vec)
 
template<typename T >
std::vector< T > cuberl::maths::normalize_min (const std::vector< T > &vec)
 
std::vector< real_tcuberl::maths::logspace (real_t start, real_t end, uint_t num, real_t base=10.0)
 
template<typename IteratorType >
std::iterator_traits< IteratorType >::value_type cuberl::maths::dot_product (IteratorType bv1, IteratorType ev1, IteratorType bv2, IteratorType ev2)
 
template<typename VectorType >
real_t cuberl::maths::dot_product (const VectorType &v1, const VectorType &v2, uint_t start_idx=0)