AIToolbox
A library that offers tools for AI problem solving.
AIToolbox Namespace Reference

Namespaces

 Bandit
 
 Factored
 
 Impl
 
 MDP
 
 POMDP
 

Classes

class  Adam
 This class implements the ADAM gradient descent algorithm. More...
 
class  CassandraParser
 This class can parse files containing MDPs and POMDPs in the Cassandra file format. More...
 
struct  copy_const
 This struct is used to copy constness from one type to another. More...
 
class  EpsilonPolicyInterface
 This class is a policy wrapper for epsilon action choice. More...
 
class  EpsilonPolicyInterface< void, void, Action >
 This class represents the base interface for epsilon policies in games and bandits. More...
 
class  IndexMap
 This class is an iterable construct on a list of ids on a given container. More...
 
class  IndexMapIterator
 This class is a simple iterator to iterate over a container with the specified ids. More...
 
class  IndexSkipMap
 This class is an iterable construct on a list of ids on a given container. More...
 
class  IndexSkipMapIterator
 This class is a simple iterator to iterate over a container without the specified ids. More...
 
class  LP
 This class presents a common interface for solving Linear Programming problems. More...
 
struct  NoCheck
 This is used to tag functions that avoid runtime checks. More...
 
class  PolicyInterface
 This class represents the base interface for policies. More...
 
class  PolicyInterface< void, void, Action >
 This class represents the base interface for policies in games and bandits. More...
 
class  Pruner
 This class offers pruning facilities for non-parsimonious ValueFunction sets. More...
 
class  Seeder
 This class is an internal class used to seed all random engines in the library. More...
 
class  Statistics
 This class registers sets of data and computes statistics about it. More...
 
class  StorageMatrix2D
 This class provides an Eigen-compatible automatically resized Matrix2D. More...
 
class  StorageVector
 This class provides an Eigen-compatible automatically resized Vector. More...
 
class  SubsetEnumerator
 This class enumerates all possible vectors of finite subsets over N elements. More...
 
class  VoseAliasSampler
 This class represents the Alias sampling method. More...
 
class  WitnessLP
 This class implements an easy interface to do Witness discovery through linear programming. More...
 

Typedefs

using AILoggerFun = void(int, const char *)
 
using RandomEngine = std::mt19937
 
using Vector = Eigen::Matrix< double, Eigen::Dynamic, 1 >
 
using Matrix2D = Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor|Eigen::AutoAlign >
 
using SparseMatrix2D = Eigen::SparseMatrix< double, Eigen::RowMajor >
 
using Matrix3D = std::vector< Matrix2D >
 
using SparseMatrix3D = std::vector< SparseMatrix2D >
 
using Matrix4D = boost::multi_array< Matrix2D, 2 >
 
using SparseMatrix4D = boost::multi_array< SparseMatrix2D, 2 >
 
using Table2D = Eigen::Matrix< unsigned long, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor|Eigen::AutoAlign >
 
using Table3D = std::vector< Table2D >
 
using SparseTable2D = Eigen::SparseMatrix< unsigned long, Eigen::RowMajor >
 
using SparseTable3D = std::vector< SparseTable2D >
 
using ProbabilityVector = Vector
 
using DumbMatrix2D = boost::multi_array< double, 2 >
 
using DumbMatrix3D = boost::multi_array< double, 3 >
 
using DumbTable2D = boost::multi_array< unsigned long, 2 >
 
using DumbTable3D = boost::multi_array< unsigned long, 3 >
 
template<typename CopiedType , typename ConstReference >
using copy_const_t = typename copy_const< CopiedType, ConstReference >::type
 
using Hyperplane = Vector
 Defines a plane in a simplex where each value is the height at that corner. More...
 
using Point = ProbabilityVector
 Defines a point inside a simplex. Coordinates sum to 1. More...
 
using PointSurface = std::pair< std::vector< Point >, std::vector< double > >
 A surface within a simplex defined by points and their height. Should not contain the corners. More...
 
using CompactHyperplanes = Matrix2D
 A compact set of (probably |A|) hyperplanes, one per column (probably |S| rows). This is generally used with PointSurface; otherwise we use a vector<Hyperplane>. More...
 

Functions

std::ostream & operator<< (std::ostream &os, const Statistics &rh)
 This function writes the output of the Statistics to the stream. More...
 
unsigned nChooseK (unsigned n, unsigned k)
 Returns (n k); i.e. n choose k. More...
 
unsigned starsBars (unsigned stars, unsigned bars)
 Returns the number of stars/bars combinations. More...
 
unsigned ballsBins (unsigned balls, unsigned bins)
 Returns the number of balls/bins combinations. More...
 
unsigned nonZeroStarsBars (unsigned stars, unsigned bars)
 Returns the number of stars/bars combinations. More...
 
unsigned nonZeroBallsBins (unsigned balls, unsigned bins)
 Returns the number of balls/bins combinations. More...
 
unsigned ceil (unsigned x, unsigned y)
 This function returns a fast ceiling between two unsigned ints. More...
 
bool checkEqualSmall (const double a, const double b)
 This function checks if two doubles near [0,1] are reasonably equal. More...
 
bool checkDifferentSmall (const double a, const double b)
 This function checks if two doubles near [0,1] are reasonably different. More...
 
bool checkEqualGeneral (const double a, const double b)
 This function checks if two doubles are reasonably equal. More...
 
bool checkDifferentGeneral (const double a, const double b)
 This function checks if two doubles are reasonably different. More...
 
template<typename V >
bool checkEqualSmall (const V &v, const double d)
 This function checks whether a given vector only contains the stated value. More...
 
template<typename V >
bool checkDifferentSmall (const V &v, const double d)
 This function checks whether a given vector does not contain only the stated value. More...
 
template<typename V >
bool checkEqualGeneral (const V &v, const double d)
 This function checks whether a given vector only contains the stated value. More...
 
template<typename V >
bool checkDifferentGeneral (const V &v, const double d)
 This function checks whether a given vector does not contain only the stated value. More...
 
template<typename V >
std::strong_ordering veccmp (const V &lhs, const V &rhs)
 This function compares two general vectors of equal size lexicographically. More...
 
template<typename V >
std::partial_ordering veccmpSmall (const V &lhs, const V &rhs)
 This function compares two general vectors of equal size lexicographically. More...
 
template<typename V >
std::partial_ordering veccmpGeneral (const V &lhs, const V &rhs)
 This function compares two general vectors of equal size lexicographically. More...
 
template<typename It >
It sequential_sorted_find (It begin, It end, const typename std::iterator_traits< It >::value_type &elem)
 This function returns an iterator to the position where the input should be in a sorted range, via sequential scan. More...
 
template<typename It >
bool sequential_sorted_contains (It begin, It end, const typename std::iterator_traits< It >::value_type &elem)
 This function returns whether a sorted range contains a given element, via sequential scan. More...
 
template<typename V >
bool sequential_sorted_contains (const V &v, const V &elems)
 This function returns whether a sorted range contains another sorted range, via sequential scan. More...
 
template<typename T >
void set_union_inplace (std::vector< T > &lhs, const std::vector< T > &rhs)
 This function performs an inplace union of two sorted sets. More...
 
template<typename It , typename F >
auto max_element_unary (It begin, const It end, F unary_converter)
 This function is equivalent to std::max_element, but takes a unary function. More...
 
template<typename T , typename U >
void copyDumb3D (const T &in, U &out, const size_t d1, const size_t d2, const size_t d3)
 Copies a 3d container into another 3d container. More...
 
template<class T , class Container >
 IndexMap (std::initializer_list< T > i, Container c) -> IndexMap< std::vector< T >, Container >
 
template<typename IdsContainer , typename Container >
 IndexMap (IdsContainer, Container &) -> IndexMap< IdsContainer, Container >
 
template<class T , class Container >
 IndexSkipMap (std::initializer_list< T > i, Container c) -> IndexSkipMap< std::vector< T >, Container >
 
template<typename IdsContainer , typename Container >
 IndexSkipMap (IdsContainer, Container &) -> IndexSkipMap< IdsContainer, Container >
 
bool dominates (const Hyperplane &lhs, const Hyperplane &rhs)
 This function checks whether an Hyperplane dominates another. More...
 
template<typename Iterator , typename P = std::identity>
Iterator findBestAtPoint (const Point &point, Iterator begin, Iterator end, double *value=nullptr, P p=P{})
 This function returns an iterator pointing to the best Hyperplane for the specified point. More...
 
template<typename Iterator , typename P = std::identity>
Iterator findBestAtSimplexCorner (const size_t corner, Iterator begin, Iterator end, double *value=nullptr, P p=P{})
 This function returns an iterator pointing to the best Hyperplane for the specified corner of the simplex space. More...
 
template<typename Iterator , typename P = std::identity>
Iterator findBestDeltaDominated (const Point &point, const Hyperplane &plane, double delta, Iterator begin, Iterator end, P p=P{})
 This function returns, if it exists, an iterator to the highest Hyperplane that delta-dominates the input one. More...
 
template<typename Iterator , typename P = std::identity>
Iterator extractBestAtPoint (const Point &point, Iterator begin, Iterator bound, Iterator end, P p=P{})
 This function finds and moves the Hyperplane with the highest value for the given point at the beginning of the specified range. More...
 
template<typename Iterator , typename P = std::identity>
Iterator extractBestAtSimplexCorners (const size_t S, Iterator begin, Iterator bound, Iterator end, P p=P{})
 This function finds and moves all best Hyperplanes in the simplex corners at the beginning of the specified range. More...
 
template<typename PIterator , typename VIterator , typename P = std::identity>
PIterator extractBestUsefulPoints (PIterator pbegin, PIterator pend, VIterator begin, VIterator end, P p=P{})
 This function finds and moves all non-useful points at the end of the input range. More...
 
template<typename NewIt , typename OldIt , typename P1 = std::identity, typename P2 = std::identity>
PointSurface findVerticesNaive (NewIt beginNew, NewIt endNew, OldIt alphasBegin, OldIt alphasEnd, P1 p1=P1{}, P2 p2=P2{})
 This function implements a naive vertex enumeration algorithm. More...
 
template<typename Range , typename P = std::identity>
PointSurface findVerticesNaive (const Range &range, P p=P{})
 This function returns all vertices for a given range of planes. More...
 
double computeOptimisticValue (const Point &p, const std::vector< Point > &points, const std::vector< double > &values)
 This function computes the optimistic value of a point given known vertices and values. More...
 
std::tuple< double, VectorLPInterpolation (const Point &p, const CompactHyperplanes &ubQ, const PointSurface &ubV)
 This function computes the exact value of the input Point w.r.t. the given surfaces. More...
 
std::tuple< double, VectorsawtoothInterpolation (const Point &p, const CompactHyperplanes &ubQ, const PointSurface &ubV)
 This function computes an approximate, but quick, upper bound on the surface value at the input point. More...
 
static std::uniform_real_distribution< double > probabilityDistribution (0.0, 1.0)
 
template<typename T >
bool isProbability (const size_t size, const T &in)
 This function checks whether the supplied 1D container is a valid discrete distribution. More...
 
template<typename T >
bool isProbability (const size_t rows, const size_t cols, const T &in)
 This function checks whether the rows of the input 2D container contain valid discrete distributions. More...
 
template<typename T >
bool isProbability (const size_t depth, const size_t rows, const size_t cols, const T &in)
 This function checks whether the rows of the input 3D container contain valid discrete distributions. More...
 
bool isProbability (const Matrix2D &in)
 This function checks whether the rows of the input matrix contain valid discrete distributions. More...
 
bool isProbability (const Matrix3D &in)
 This function checks whether the rows of the input matrix contain valid discrete distributions. More...
 
bool isProbability (const SparseMatrix2D &in)
 This function checks whether the rows of the input matrix contain valid discrete distributions. More...
 
bool isProbability (const SparseMatrix3D &in)
 This function checks whether the rows of the input matrix contain valid discrete distributions. More...
 
template<typename T , typename G >
size_t sampleProbability (const size_t d, const T &in, G &generator)
 This function samples an index from a probability vector. More...
 
template<typename G >
size_t sampleProbability (const size_t d, const SparseMatrix2D::ConstRowXpr &in, G &generator)
 This function samples an index from a sparse probability vector. More...
 
template<typename G >
double sampleBetaDistribution (double a, double b, G &generator)
 This function samples from a Beta distribution. More...
 
template<typename TIn , typename G >
ProbabilityVector sampleDirichletDistribution (const TIn &params, G &generator)
 This function samples from the input Dirichlet distribution. More...
 
template<typename TIn , typename TOut , typename G >
void sampleDirichletDistribution (const TIn &params, G &generator, TOut &&out)
 This function samples from the input Dirichlet distribution inline. More...
 
template<typename G >
ProbabilityVector makeRandomProbability (const size_t S, G &generator)
 This function generates a random probability vector. More...
 
bool checkEqualProbability (const ProbabilityVector &lhs, const ProbabilityVector &rhs)
 This function checks whether two input ProbabilityVector are equal. More...
 
double getEntropy (const ProbabilityVector &v)
 This function returns the entropy of the input ProbabilityVector. More...
 
double getEntropyBase2 (const ProbabilityVector &v)
 This function returns the entropy of the input ProbabilityVector computed using log2. More...
 
ProbabilityVector projectToProbability (const Vector &v)
 This function projects the input vector to a valid probability space. More...
 
template<typename Iterator , typename P = std::identity>
Iterator extractDominated (Iterator begin, Iterator end, P p=P{})
 This function finds and moves all Hyperplanes in the range that are dominated by others. More...
 
template<typename Iterator , typename P = std::identity>
std::tuple< Iterator, Iterator, Iterator > extractDominatedIncremental (Iterator begin, Iterator newBegin, Iterator end, P p=P{})
 This function finds and moves all Hyperplanes in the range that are dominated by others. More...
 

Variables

AILoggerFunAILogger = nullptr
 This pointer defines the function used to log. More...
 
struct AIToolbox::NoCheck NO_CHECK
 
template<typename A , typename B >
concept different_from = !std::same_as<A, B>
 This concept simplifies checking for non-void. More...
 
template<typename M >
concept IsNaive2DMatrix
 This concept checks for a simple 2D accessible matrix. More...
 
template<typename M >
concept IsNaive3DMatrix
 This concept checks for a simple 3D accessible matrix. More...
 
template<typename T >
concept IsNaive2DTable
 This concept checks for a simple 2D accessible table. More...
 
template<typename T >
concept IsNaive3DTable
 This concept checks for a simple 3D accessible table. More...
 
template<typename T >
concept IsDerivedFromEigen = std::derived_from<T, Eigen::EigenBase<T>>
 This concept simplifies checking for non-void. More...
 
template<typename M >
concept HasStateSpace
 This concept checks that getS() exists. More...
 
template<typename M >
concept HasFixedActionSpace
 This concept checks that getA() exists. More...
 
template<typename M >
concept HasVariableActionSpace
 This concept checks that getA(state) exists. More...
 
template<typename M >
concept HasActionSpace = HasFixedActionSpace<M> || HasVariableActionSpace<M>
 This concept checks that some form of getA exists. More...
 
template<typename M >
concept HasObservationSpace
 This concept checks that getO() exists. More...
 
template<typename M >
concept HasIntegralStateSpace
 This concept checks that getS() returns size_t. More...
 
template<typename M >
concept HasIntegralActionSpace
 This concept checks that getA returns size_t. More...
 
template<typename M >
concept HasIntegralObservationSpace
 This concept checks that getO() returns size_t. More...
 
template<typename M >
concept IsGenerativeModel
 This concept checks the minimum requirements for a generative model. More...
 
constexpr auto equalToleranceSmall = 0.000001
 This is the max absolute difference for which two values can be considered equal. More...
 
constexpr auto equalToleranceGeneral = 0.00000000001
 

Typedef Documentation

◆ AILoggerFun

using AIToolbox::AILoggerFun = typedef void(int, const char *)

◆ CompactHyperplanes

A compact set of (probably |A|) hyperplanes, one per column (probably |S| rows). This is generally used with PointSurface; otherwise we use a vector<Hyperplane>.

◆ copy_const_t

template<typename CopiedType , typename ConstReference >
using AIToolbox::copy_const_t = typedef typename copy_const<CopiedType, ConstReference>::type

◆ DumbMatrix2D

using AIToolbox::DumbMatrix2D = typedef boost::multi_array<double, 2>

◆ DumbMatrix3D

using AIToolbox::DumbMatrix3D = typedef boost::multi_array<double, 3>

◆ DumbTable2D

using AIToolbox::DumbTable2D = typedef boost::multi_array<unsigned long, 2>

◆ DumbTable3D

using AIToolbox::DumbTable3D = typedef boost::multi_array<unsigned long, 3>

◆ Hyperplane

using AIToolbox::Hyperplane = typedef Vector

Defines a plane in a simplex where each value is the height at that corner.

◆ Matrix2D

using AIToolbox::Matrix2D = typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor | Eigen::AutoAlign>

◆ Matrix3D

using AIToolbox::Matrix3D = typedef std::vector<Matrix2D>

◆ Matrix4D

using AIToolbox::Matrix4D = typedef boost::multi_array<Matrix2D, 2>

◆ Point

Defines a point inside a simplex. Coordinates sum to 1.

◆ PointSurface

using AIToolbox::PointSurface = typedef std::pair<std::vector<Point>, std::vector<double> >

A surface within a simplex defined by points and their height. Should not contain the corners.

◆ ProbabilityVector

◆ RandomEngine

using AIToolbox::RandomEngine = typedef std::mt19937

◆ SparseMatrix2D

using AIToolbox::SparseMatrix2D = typedef Eigen::SparseMatrix<double, Eigen::RowMajor>

◆ SparseMatrix3D

using AIToolbox::SparseMatrix3D = typedef std::vector<SparseMatrix2D>

◆ SparseMatrix4D

using AIToolbox::SparseMatrix4D = typedef boost::multi_array<SparseMatrix2D, 2>

◆ SparseTable2D

using AIToolbox::SparseTable2D = typedef Eigen::SparseMatrix<unsigned long, Eigen::RowMajor>

◆ SparseTable3D

using AIToolbox::SparseTable3D = typedef std::vector<SparseTable2D>

◆ Table2D

using AIToolbox::Table2D = typedef Eigen::Matrix<unsigned long, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor | Eigen::AutoAlign>

◆ Table3D

using AIToolbox::Table3D = typedef std::vector<Table2D>

◆ Vector

using AIToolbox::Vector = typedef Eigen::Matrix<double, Eigen::Dynamic, 1>

Function Documentation

◆ ballsBins()

unsigned AIToolbox::ballsBins ( unsigned  balls,
unsigned  bins 
)

Returns the number of balls/bins combinations.

This function returns the number of combinations in which you can split a set of indistinguishable balls into a set of distinguishable bins.

This is equivalent to starsBars(balls, bins - 1).

Note: bins shall NOT be equal to 0.

◆ ceil()

unsigned AIToolbox::ceil ( unsigned  x,
unsigned  y 
)
inline

This function returns a fast ceiling between two unsigned ints.

Note: we do x + y, so it may overflow.

Parameters
xThe dividend.
yThe divisor.
Returns
The ceiling from the integer division.

◆ checkDifferentGeneral() [1/2]

bool AIToolbox::checkDifferentGeneral ( const double  a,
const double  b 
)
inline

This function checks if two doubles are reasonably different.

The order of the parameters is not important.

Parameters
aThe first number to compare.
bThe second number to compare.
Returns
True if the two numbers are far away enough, false otherwise.

◆ checkDifferentGeneral() [2/2]

template<typename V >
bool AIToolbox::checkDifferentGeneral ( const V &  v,
const double  d 
)

This function checks whether a given vector does not contain only the stated value.

Returns
True if not all elements are equal to the input.

◆ checkDifferentSmall() [1/2]

bool AIToolbox::checkDifferentSmall ( const double  a,
const double  b 
)
inline

This function checks if two doubles near [0,1] are reasonably different.

If the numbers are not near [0,1], the result is not guaranteed to be what may be expected. The order of the parameters is not important.

Parameters
aThe first number to compare.
bThe second number to compare.
Returns
True if the two numbers are far away enough, false otherwise.

◆ checkDifferentSmall() [2/2]

template<typename V >
bool AIToolbox::checkDifferentSmall ( const V &  v,
const double  d 
)

This function checks whether a given vector does not contain only the stated value.

Returns
True if not all elements are equal to the input.

◆ checkEqualGeneral() [1/2]

bool AIToolbox::checkEqualGeneral ( const double  a,
const double  b 
)
inline

This function checks if two doubles are reasonably equal.

The order of the parameters is not important.

Parameters
aThe first number to compare.
bThe second number to compare.
Returns
True if the two numbers are close enough, false otherwise.

◆ checkEqualGeneral() [2/2]

template<typename V >
bool AIToolbox::checkEqualGeneral ( const V &  v,
const double  d 
)

This function checks whether a given vector only contains the stated value.

This function compares using checkEqualGeneral(double, double);

Returns
True if all elements are compared equal to the input.

◆ checkEqualProbability()

bool AIToolbox::checkEqualProbability ( const ProbabilityVector lhs,
const ProbabilityVector rhs 
)
inline

This function checks whether two input ProbabilityVector are equal.

This function is approximate. It assumes that the vectors are valid, so they must sum up to one, and each element must be between zero and one. The vector must also be of the same size.

This function is approximate, as we're dealing with floating point.

Parameters
lhsThe left hand side to check.
rhsThe right hand side to check.
Returns
Whether the two ProbabilityVectors are the same.

◆ checkEqualSmall() [1/2]

bool AIToolbox::checkEqualSmall ( const double  a,
const double  b 
)
inline

This function checks if two doubles near [0,1] are reasonably equal.

If the numbers are not near [0,1], the result is not guaranteed to be what may be expected. The order of the parameters is not important.

Parameters
aThe first number to compare.
bThe second number to compare.
Returns
True if the two numbers are close enough, false otherwise.

◆ checkEqualSmall() [2/2]

template<typename V >
bool AIToolbox::checkEqualSmall ( const V &  v,
const double  d 
)

This function checks whether a given vector only contains the stated value.

This function compares using checkEqualSmall(double, double);

Returns
True if all elements are compared equal to the input.

◆ computeOptimisticValue()

double AIToolbox::computeOptimisticValue ( const Point p,
const std::vector< Point > &  points,
const std::vector< double > &  values 
)

This function computes the optimistic value of a point given known vertices and values.

This function computes an LP to determine the best possible value of a point given all known best vertices around it.

This function is needed in multi-objective settings (rather than POMDPs), since the step where we compute the optimal value for a given point is extremely expensive (it requires solving a full MDP). Thus linear programming is used in order to determine an optimistic bound when deciding the next point to extract from the queue during the linear support process.

Note that the input is the same as a PointSurface; the two components have been kept as separate arguments simply to allow more freedom to the user.

Parameters
pThe point where we want to compute the best possible value.
pointsThe points that make up the surface.
valuesThe respective values of the input points.
Returns
The best possible value that the input point can have given the known vertices.

◆ copyDumb3D()

template<typename T , typename U >
void AIToolbox::copyDumb3D ( const T &  in,
U &  out,
const size_t  d1,
const size_t  d2,
const size_t  d3 
)

Copies a 3d container into another 3d container.

The containers needs to support data access through operator[]. In addition, the dimensions of the containers must match the ones specified.

This is important, as this function DOES NOT perform any size checks on the containers.

Template Parameters
TType of the input container.
UType of the output container.
Parameters
inInput container.
outOutput container.
d1First dimension of the containers.
d2Second dimension of the containers.
d3Third dimension of the containers.

◆ dominates()

bool AIToolbox::dominates ( const Hyperplane lhs,
const Hyperplane rhs 
)
inline

This function checks whether an Hyperplane dominates another.

Parameters
lhsThe Hyperplane that should dominate.
rhsThe Hyperplane that should be dominated.
Returns
Whether the left hand side dominates the right hand side.

◆ extractBestAtPoint()

template<typename Iterator , typename P = std::identity>
Iterator AIToolbox::extractBestAtPoint ( const Point point,
Iterator  begin,
Iterator  bound,
Iterator  end,
p = P{} 
)

This function finds and moves the Hyperplane with the highest value for the given point at the beginning of the specified range.

This function uses an already existing bound containing previously marked useful hyperplanes. The order is 'begin'->'bound'->'end', where bound may be equal to end where no previous bound exists. The found hyperplane is moved between 'begin' and 'bound', but only if it was not there previously.

Parameters
pointThe point where we need to check the value
beginThe begin of the search range.
boundThe begin of the 'useful' range.
endThe range end to be checked. It is NOT included in the search.
pA projection function to call on the iterators (defaults to identity).
Returns
The new bound iterator.

◆ extractBestAtSimplexCorners()

template<typename Iterator , typename P = std::identity>
Iterator AIToolbox::extractBestAtSimplexCorners ( const size_t  S,
Iterator  begin,
Iterator  bound,
Iterator  end,
p = P{} 
)

This function finds and moves all best Hyperplanes in the simplex corners at the beginning of the specified range.

What this function does is to find out which hyperplanes give the highest value in the corner points. Since multiple corners may use the same hyperplanes, the number of found hyperplanes may not be the same as the number of corners.

This function uses an already existing bound containing previously marked useful hyperplanes. The order is 'begin'->'bound'->'end', where bound may be equal to end where no previous bound exists. All found hyperplanes are added between 'begin' and 'bound', but only if they were not there previously.

Parameters
SThe number of corners of the simplex.
beginThe begin of the search range.
boundThe begin of the 'useful' range.
endThe end of the search range. It is NOT included in the search.
pA projection function to call on the iterators (defaults to identity).
Returns
The new bound iterator.

◆ extractBestUsefulPoints()

template<typename PIterator , typename VIterator , typename P = std::identity>
PIterator AIToolbox::extractBestUsefulPoints ( PIterator  pbegin,
PIterator  pend,
VIterator  begin,
VIterator  end,
p = P{} 
)

This function finds and moves all non-useful points at the end of the input range.

This function helps remove points which do not support any hyperplane and are thus not useful for improving the overall surface.

This function moves all non-useful points at the end of the input range, and returns the resulting iterator pointing to the first non-useful point.

When multiple Points support the same Hyperplane, the one with the best value is returned.

The Hyperplane range may contain elements which are not supported by any of the input Points (although if they exist they may slow down the function).

Parameters
pbeginThe beginning of the Point range to check.
pendThe end of the Point range to check.
beginThe beginning of the Hyperplane range to check against.
endThe end of the Hyperplane range to check against.
pA projection function to call on the iterators (defaults to identity).
Returns
An iterator pointing to the first non-useful Point.

◆ extractDominated()

template<typename Iterator , typename P = std::identity>
Iterator AIToolbox::extractDominated ( Iterator  begin,
Iterator  end,
p = P{} 
)

This function finds and moves all Hyperplanes in the range that are dominated by others.

This function performs simple comparisons between all Hyperplanes in the range, and is thus much more performant than a full-fledged prune, since that would need to solve multiple linear programming problems. However, this function will not return the truly parsimonious set of Hyperplanes, as its pruning powers are limited.

Dominated elements will be moved at the end of the range for safe removal.

Parameters
beginThe begin of the list that needs to be pruned.
endThe end of the list that needs to be pruned.
pA projection function to call on the iterators (defaults to identity).
Returns
The iterator that separates dominated elements with non-pruned.

◆ extractDominatedIncremental()

template<typename Iterator , typename P = std::identity>
std::tuple<Iterator, Iterator, Iterator> AIToolbox::extractDominatedIncremental ( Iterator  begin,
Iterator  newBegin,
Iterator  end,
p = P{} 
)

This function finds and moves all Hyperplanes in the range that are dominated by others.

This function is similar to extractDominated, with the additional assumption that a certain set of Hyperplanes do not dominate each other. This function can be useful to extract dominated Hyperplanes after new ones have been added to an already pruned set. This function would then skip re-checking between the already pruned Hyperplanes.

This function assumes that the new additions are not that many with respect to the already validated Hyperplanes. If that's not the case, it's possible that extractDominated might be faster.

Dominated elements will be moved at the end of the range for safe removal.

In order to enable possible optimizations, entries are kept grouped in four groups: still good old entries, good new entries, dominated old entries and dominated new entries. Note that the initial ordering of these sub-ranges is lost.

We return the three iterators needed to identify these four ranges (together with the provided begin and end iterators).

Parameters
beginThe begin of the list that needs to be pruned.
newBeginThe begin of the new Hyperplanes that need to be checked.
endThe end of the list that needs to be pruned.
pA projection function to call on the iterators (defaults to identity).
Returns
Three iterators demarking the various filtered ranges: old, new, dominated old.

◆ findBestAtPoint()

template<typename Iterator , typename P = std::identity>
Iterator AIToolbox::findBestAtPoint ( const Point point,
Iterator  begin,
Iterator  end,
double *  value = nullptr,
p = P{} 
)

This function returns an iterator pointing to the best Hyperplane for the specified point.

Given a list of hyperplanes as a surface, this function returns the hyperplane which provides the highest value at the specified point.

Parameters
pointThe point where we need to check the value
beginThe start of the range to look in.
endThe end of the range to look in (excluded).
valueA pointer to double, which gets set to the value of the given point with the found Hyperplane.
pA projection function to call on the iterators (defaults to identity).
Returns
An iterator pointing to the best choice in range.

◆ findBestAtSimplexCorner()

template<typename Iterator , typename P = std::identity>
Iterator AIToolbox::findBestAtSimplexCorner ( const size_t  corner,
Iterator  begin,
Iterator  end,
double *  value = nullptr,
p = P{} 
)

This function returns an iterator pointing to the best Hyperplane for the specified corner of the simplex space.

This function is slightly more efficient than findBestAtPoint for a simplex corner.

Parameters
cornerThe corner of the simplex space we are checking.
beginThe start of the range to look in.
endThe end of the range to look in (excluded).
valueA pointer to double, which gets set to the value of the corner with the found Hyperplane.
pA projection function to call on the iterators (defaults to identity).
Returns
An iterator pointing to the best choice in range.

◆ findBestDeltaDominated()

template<typename Iterator , typename P = std::identity>
Iterator AIToolbox::findBestDeltaDominated ( const Point point,
const Hyperplane plane,
double  delta,
Iterator  begin,
Iterator  end,
p = P{} 
)

This function returns, if it exists, an iterator to the highest Hyperplane that delta-dominates the input one.

Delta-domination refers to a concept introduced in the SARSOP paper. It means that a Hyperplane dominates another in a neighborhood of a given Point p. This is in contrast to either simply being higher at that point, or dominating the other plane across the whole simplex space.

The returned entry of this function depends on the ordering of the range, as more than one Hyperplane may delta-dominate the input, but they may not delta-dominate each other.

Thus, we iterate the input range once, and we check iteratively if an entry delta-dominates the currently found best Hyperplane.

Note that an entry is not guaranteed to exist; in that case we return the end of the input range.

Parameters
pointThe Point where to check for delta-domination.
planeThe Hyperplane that needs to be delta-dominated.
deltaThe delta value to use to validate delta-domination, i.e. the size of the neighborhood to check.
beginThe start of the range to check.
endThe end of the range to check.
pA projection function to call on the iterators (defaults to identity).
Returns
An iterator to the highest dominating entry, or if none is found, the end of the range.

◆ findVerticesNaive() [1/2]

template<typename Range , typename P = std::identity>
PointSurface AIToolbox::findVerticesNaive ( const Range &  range,
p = P{} 
)

This function returns all vertices for a given range of planes.

This function is used as a convenience to avoid duplicate plane problems. It will still possibly return duplicate vertices though.

Parameters
rangeThe range of planes to examine.
pA projection function to call on the iterators of the range (defaults to identity).
Returns
A non-unique list of all the vertices found.

◆ findVerticesNaive() [2/2]

template<typename NewIt , typename OldIt , typename P1 = std::identity, typename P2 = std::identity>
PointSurface AIToolbox::findVerticesNaive ( NewIt  beginNew,
NewIt  endNew,
OldIt  alphasBegin,
OldIt  alphasEnd,
P1  p1 = P1{},
P2  p2 = P2{} 
)

This function implements a naive vertex enumeration algorithm.

This function goes through every subset of planes of size S, and finds all vertices it can. In particular, it goes through the first list one element at a time, and joins it with S-1 elements from the second list.

Even more precisely, we take >= 1 elements from the second list. The remaining elements (so that in total we still use S-1) are simply the simplex boundaries, which allows us to find the corners located there.

This method may find duplicate vertices (it does not bother to prune them), as a vertex can be in the convergence of more than S planes.

The advantage is that we do not need any linear programming, and simple matrix decomposition techniques suffice.

We do NOT return simplex corners.

Warning: this function will return wrong vertices if the first set contains the same vectors in the second set!

Warning: the values of each vertex depends on the planes it has been found of, and thus may not be the true value if considering all planes at the same time! In other words, the same vertex may be found multiple times with different values!

This function works on ranges of Vectors.

Parameters
beginNewThe beginning of the range of the planes to find vertices for.
endNewThe end of the range of the planes to find vertices for.
alphasBeginThe beginning of the range of all other planes.
alphasEndThe end of the range of all other planes.
p1A projection function to call on the iterators of the first range (defaults to identity).
p2A projection function to call on the iterators of the second range (defaults to identity).
Returns
A non-unique list of all the vertices found.

◆ getEntropy()

double AIToolbox::getEntropy ( const ProbabilityVector v)
inline

This function returns the entropy of the input ProbabilityVector.

Parameters
vThe input ProbabilityVector.
Returns
The entropy of the input.

◆ getEntropyBase2()

double AIToolbox::getEntropyBase2 ( const ProbabilityVector v)
inline

This function returns the entropy of the input ProbabilityVector computed using log2.

Parameters
vThe input ProbabilityVector.
Returns
The entropy of the input in base 2.

◆ IndexMap() [1/2]

template<typename IdsContainer , typename Container >
AIToolbox::IndexMap ( IdsContainer  ,
Container &   
) -> IndexMap< IdsContainer, Container >

◆ IndexMap() [2/2]

template<class T , class Container >
AIToolbox::IndexMap ( std::initializer_list< T >  i,
Container  c 
) -> IndexMap< std::vector< T >, Container >

◆ IndexSkipMap() [1/2]

template<typename IdsContainer , typename Container >
AIToolbox::IndexSkipMap ( IdsContainer  ,
Container &   
) -> IndexSkipMap< IdsContainer, Container >

◆ IndexSkipMap() [2/2]

template<class T , class Container >
AIToolbox::IndexSkipMap ( std::initializer_list< T >  i,
Container  c 
) -> IndexSkipMap< std::vector< T >, Container >

◆ isProbability() [1/7]

bool AIToolbox::isProbability ( const Matrix2D in)

This function checks whether the rows of the input matrix contain valid discrete distributions.

See also
isProbability(const size_t size, const T & in);
Parameters
inThe input matrix.
Returns
True if the matrix satisfies probability constraints, and false otherwise.

◆ isProbability() [2/7]

bool AIToolbox::isProbability ( const Matrix3D in)

This function checks whether the rows of the input matrix contain valid discrete distributions.

See also
isProbability(const size_t size, const T & in);
Parameters
inThe input matrix.
Returns
True if the matrix satisfies probability constraints, and false otherwise.

◆ isProbability() [3/7]

template<typename T >
bool AIToolbox::isProbability ( const size_t  depth,
const size_t  rows,
const size_t  cols,
const T &  in 
)

This function checks whether the rows of the input 3D container contain valid discrete distributions.

The container needs to support data access through operator[] for both dimensions (i.e. in[depth][row][col] must be valid). In addition, the dimensions of the container must match the ones provided.

This is important, as this function DOES NOT perform any size checks on the external container.

Internal values of the container will be converted to double, so the conversion T to double must be possible.

See also
isProbability(const size_t size, const T & in);
Template Parameters
TThe 3D container type.
Parameters
depthThe size of the first dimension of the container.
rowsThe size of the second dimension of the container.
colsThe size of the third dimension of the container.
inThe input container.
Returns
True if the container satisfies probability constraints, and false otherwise.

◆ isProbability() [4/7]

template<typename T >
bool AIToolbox::isProbability ( const size_t  rows,
const size_t  cols,
const T &  in 
)

This function checks whether the rows of the input 2D container contain valid discrete distributions.

The container needs to support data access through operator[] for both dimensions (i.e. in[row][col] must be valid). In addition, the dimensions of the container must match the ones provided.

This is important, as this function DOES NOT perform any size checks on the external container.

Internal values of the container will be converted to double, so the conversion T to double must be possible.

See also
isProbability(const size_t size, const T & in);
Template Parameters
TThe 2D container type.
Parameters
rowsThe size of the first dimension of the container.
colsThe size of the second dimension of the container.
inThe input container.
Returns
True if the container satisfies probability constraints, and false otherwise.

◆ isProbability() [5/7]

template<typename T >
bool AIToolbox::isProbability ( const size_t  size,
const T &  in 
)

This function checks whether the supplied 1D container is a valid discrete distribution.

This function verifies basic probability conditions on the supplied container. The sum of all elements must be 1, and all elements must be >= 0 and <= 1.

The container needs to support data access through operator[]. In addition, the dimension of the container must match the one provided as argument.

This is important, as this function DOES NOT perform any size checks on the input container.

Internal values of the container will be converted to double, so the conversion of its elements to double must be possible.

Template Parameters
TThe 1D container type.
Parameters
sizeThe size of the container.
inThe input container.
Returns
True if the container satisfies probability constraints, and false otherwise.

◆ isProbability() [6/7]

bool AIToolbox::isProbability ( const SparseMatrix2D in)

This function checks whether the rows of the input matrix contain valid discrete distributions.

See also
isProbability(const size_t size, const T & in);
Parameters
inThe input matrix.
Returns
True if the matrix satisfies probability constraints, and false otherwise.

◆ isProbability() [7/7]

bool AIToolbox::isProbability ( const SparseMatrix3D in)

This function checks whether the rows of the input matrix contain valid discrete distributions.

See also
isProbability(const size_t size, const T & in);
Parameters
inThe input matrix.
Returns
True if the matrix satisfies probability constraints, and false otherwise.

◆ LPInterpolation()

std::tuple<double, Vector> AIToolbox::LPInterpolation ( const Point p,
const CompactHyperplanes ubQ,
const PointSurface ubV 
)

This function computes the exact value of the input Point w.r.t. the given surfaces.

The input CompactHyperplanes are used as an easy upper bound.

Then, a linear programming is created that uses the input PointSurface. What happens is that the linear program uses each Point (and its value) to construct a piecewise linear surface, where the value of the input belief is determined.

The higher of the two surfaces is then returned as the value of the input Point.

Parameters
pThe point to compute the value of.
ubQA set of Hyperplanes to use as a baseline surface.
ubVA set of Points (not on the corners of the simplex) to use as main interpolation.
Returns
The value of the Point, and a vector containing the proportion in which each Point in the PointSurface contributes to the upper bound.

◆ makeRandomProbability()

template<typename G >
ProbabilityVector AIToolbox::makeRandomProbability ( const size_t  S,
G &  generator 
)

This function generates a random probability vector.

This function will sample uniformly from the simplex space with the specified number of dimensions.

S must be at least one or we don't guarantee any behaviour.

Parameters
SThe number of entries of the output vector.
generatorA random number generator.
Returns
A new random probability vector.

◆ max_element_unary()

template<typename It , typename F >
auto AIToolbox::max_element_unary ( It  begin,
const It  end,
unary_converter 
)

This function is equivalent to std::max_element, but takes a unary function.

This function can be called when doing a comparison between elements is expensive, as they must be converted to some particular value every single time.

Instead, here we take a unary function which we apply once to every element in the range, and we pick the one with the value that compares the max.

If there are duplicates, the first max is returned.

Parameters
beginThe begin of the range to compare.
endThe end of the range to compare.
unary_converterThe unary function to apply to each item in the range.
Returns
The iterator pointing to the max element in the range.

◆ nChooseK()

unsigned AIToolbox::nChooseK ( unsigned  n,
unsigned  k 
)

Returns (n k); i.e. n choose k.

◆ nonZeroBallsBins()

unsigned AIToolbox::nonZeroBallsBins ( unsigned  balls,
unsigned  bins 
)

Returns the number of balls/bins combinations.

This function returns the number of combinations in which you can split a set of indistinguishable balls into a set of distinguishable bins, where no bin can be empty.

This is equivalent to nonZeroStarsBars(balls, bins - 1).

Note: bins shall NOT be equal to 0.

◆ nonZeroStarsBars()

unsigned AIToolbox::nonZeroStarsBars ( unsigned  stars,
unsigned  bars 
)

Returns the number of stars/bars combinations.

This function returns the number of combinations for dividing a set of stars with bars number of elements, where no two bars can be adjacent.

◆ operator<<()

std::ostream& AIToolbox::operator<< ( std::ostream &  os,
const Statistics rh 
)

This function writes the output of the Statistics to the stream.

The output will contain a series of lines, each formed by: timestep, mean, cumulative mean, standard deviation and cumulative standard deviation.

The output is GnuPlot friendly!

Note that each reprint will recompute the statistics from scratch, as they are not cached.

See also
Statistics::process()
Parameters
osThe stream to write to.
rhThe Statistics to get data from.
Returns
The input stream.

◆ probabilityDistribution()

static std::uniform_real_distribution<double> AIToolbox::probabilityDistribution ( 0.  0,
1.  0 
)
static

◆ projectToProbability()

ProbabilityVector AIToolbox::projectToProbability ( const Vector v)

This function projects the input vector to a valid probability space.

This function finds the closest valid ProbabilityVector to the input vector. The distance measure used here is the sum of the absolute values of the element-wise difference between the input and the output.

When it has a choice, it tries to preserve the "shape" of the input and not arbitrarily change elements around.

Parameters
vThe vector to project to a valid probability space.
Returns
The closes valid probability vector to the input.

◆ read() [1/9]

std::istream& AIToolbox::read ( std::istream &  is,
Matrix2D m 
)

◆ read() [2/9]

std::istream& AIToolbox::read ( std::istream &  is,
Matrix3D m 
)

◆ read() [3/9]

std::istream& AIToolbox::read ( std::istream &  is,
SparseMatrix2D m 
)

◆ read() [4/9]

std::istream& AIToolbox::read ( std::istream &  is,
SparseMatrix3D m 
)

◆ read() [5/9]

std::istream& AIToolbox::read ( std::istream &  is,
SparseTable2D t 
)

◆ read() [6/9]

std::istream& AIToolbox::read ( std::istream &  is,
SparseTable3D t 
)

◆ read() [7/9]

std::istream& AIToolbox::read ( std::istream &  is,
Table2D t 
)

◆ read() [8/9]

std::istream& AIToolbox::read ( std::istream &  is,
Table3D t 
)

◆ read() [9/9]

std::istream& AIToolbox::read ( std::istream &  is,
Vector v 
)

◆ sampleBetaDistribution()

template<typename G >
double AIToolbox::sampleBetaDistribution ( double  a,
double  b,
G &  generator 
)

This function samples from a Beta distribution.

The Beta distribution can be useful as it is the conjugate prior of the Bernoulli and Binomial distributions (and others).

As C++ does not yet have a Beta distribution in the standard, we emulate the sampling using two gamma distributions.

Template Parameters
GThe type of the generator used.
Parameters
aThe 'a' shape parameter of the Beta distribution to sample.
bThe 'b' shape parameter of the Beta distribution to sample.
generatorA random number generator.

FIXME: make dist object like the others.

Returns
The sampled number.

◆ sampleDirichletDistribution() [1/2]

template<typename TIn , typename G >
ProbabilityVector AIToolbox::sampleDirichletDistribution ( const TIn &  params,
G &  generator 
)

This function samples from the input Dirichlet distribution.

The input parameters's type must support size() and square bracket access.

Parameters
paramsThe parameters of the Dirichlet distribution.
generatorThe random generator to sample from.
Returns
A ProbabilityVector containing the sampled Dirichlet.

◆ sampleDirichletDistribution() [2/2]

template<typename TIn , typename TOut , typename G >
void AIToolbox::sampleDirichletDistribution ( const TIn &  params,
G &  generator,
TOut &&  out 
)

This function samples from the input Dirichlet distribution inline.

The input parameters's type must support size() and square bracket access. The output parameter's type must be a dense Eigen type (Vector, row, etc).

Parameters
paramsThe parameters of the Dirichlet distribution.
generatorThe random generator to sample from.
outThe output container.

◆ sampleProbability() [1/2]

template<typename G >
size_t AIToolbox::sampleProbability ( const size_t  d,
const SparseMatrix2D::ConstRowXpr &  in,
G &  generator 
)

This function samples an index from a sparse probability vector.

This function randomly samples an index between 0 and d, given a vector containing the probabilities of sampling each of the indexes.

For performance reasons this function does not verify that the input container is effectively a probability.

The generator has to be supplied to the function, so that different objects are able to maintain different generators, to reduce correlations between different samples. The generator has to be compatible with std::uniform_real_distribution<double>, since that is what is used to obtain the random sample.

Template Parameters
GThe type of the generator used.
Parameters
inThe external probability container.
dThe size of the supplied container.
generatorThe generator used to sample.
Returns
An index in range [0,d-1].

◆ sampleProbability() [2/2]

template<typename T , typename G >
size_t AIToolbox::sampleProbability ( const size_t  d,
const T &  in,
G &  generator 
)

This function samples an index from a probability vector.

This function randomly samples an index between 0 and d, given a vector containing the probabilities of sampling each of the indexes.

For performance reasons this function does not verify that the input container is effectively a probability.

The generator has to be supplied to the function, so that different objects are able to maintain different generators, to reduce correlations between different samples. The generator has to be compatible with std::uniform_real_distribution<double>, since that is what is used to obtain the random sample.

Template Parameters
TThe type of the container vector to sample.
GThe type of the generator used.
Parameters
inThe external probability container.
dThe size of the supplied container.
generatorThe generator used to sample.
Returns
An index in range [0,d-1].

◆ sawtoothInterpolation()

std::tuple<double, Vector> AIToolbox::sawtoothInterpolation ( const Point p,
const CompactHyperplanes ubQ,
const PointSurface ubV 
)

This function computes an approximate, but quick, upper bound on the surface value at the input point.

The input CompactHyperplanes are used as an easy upper bound.

We then start to consider every surface composed by one Point in the input PointSurface, and N-1 corners of the simplex (the highest corners of the surface, as identified by the CompactHyperplanes). Since each Point defines N such surfaces (one for each corner we "skip"), the enumeration can be done fairly quickly.

The overall surface has a sawtooth shape, from which the name of this method. The approximation is not perfect, but some methods must use it as using the LPInterpolation method would be too computationally expensive.

Parameters
pThe point to compute the value of.
ubQA set of Hyperplanes to use as a baseline surface.
ubVA set of Points (not on the corners of the simplex) to use as main interpolation.
Returns
The value of the Point, and a vector containing the proportion in which each Point in the PointSurface contributes to the upper bound.

◆ sequential_sorted_contains() [1/2]

template<typename V >
bool AIToolbox::sequential_sorted_contains ( const V &  v,
const V &  elems 
)

This function returns whether a sorted range contains another sorted range, via sequential scan.

Note: This function assumes that the contained vector is smaller or equal in size of the vector to be searched.

Template Parameters
VThe type of the vector to be scanned.
Parameters
vThe vector to be scanned.
elemsThe vector that must be contained.
Returns
True if the vector contains all elements from the input, false otherwise.

◆ sequential_sorted_contains() [2/2]

template<typename It >
bool AIToolbox::sequential_sorted_contains ( It  begin,
It  end,
const typename std::iterator_traits< It >::value_type &  elem 
)

This function returns whether a sorted range contains a given element, via sequential scan.

The idea behind this function is that for small sorted vectors it is faster to do a sequential scan rather than employing the heavy handed technique of binary search.

Parameters
beginThe beginning of the sorted range to scan.
endThe end of the sorted range to scan.
elemThe element to be looked for in the range.
Returns
True if the input is in the range, false otherwise.

◆ sequential_sorted_find()

template<typename It >
It AIToolbox::sequential_sorted_find ( It  begin,
It  end,
const typename std::iterator_traits< It >::value_type &  elem 
)

This function returns an iterator to the position where the input should be in a sorted range, via sequential scan.

The idea behind this function is that for small sorted vectors it is faster to do a sequential scan rather than employing the heavy handed technique of binary search.

Parameters
beginThe beginning of the sorted range to scan.
endThe end of the sorted range to scan.
elemThe element to be looked for in the range.
Returns
An iterator to the position the input element should be in the sorted range.

◆ set_union_inplace()

template<typename T >
void AIToolbox::set_union_inplace ( std::vector< T > &  lhs,
const std::vector< T > &  rhs 
)

This function performs an inplace union of two sorted sets.

Parameters
lhsThe left hand side, to be increased.
rhsThe right hand side.

◆ starsBars()

unsigned AIToolbox::starsBars ( unsigned  stars,
unsigned  bars 
)

Returns the number of stars/bars combinations.

This function returns the number of combinations for dividing a set of stars with bars number of elements.

◆ veccmp()

template<typename V >
std::strong_ordering AIToolbox::veccmp ( const V &  lhs,
const V &  rhs 
)

This function compares two general vectors of equal size lexicographically.

Note that veccmp reports equality only if the elements are all exactly the same. You should not use this function to compare floating point numbers unless you know what you are doing.

Note: This function assumes that the inputs are equally sized.

Parameters
lhsThe left hand size of the comparison.
rhsThe right hand size of the comparison.
Returns
The strong_ordering of the input vectors.

◆ veccmpGeneral()

template<typename V >
std::partial_ordering AIToolbox::veccmpGeneral ( const V &  lhs,
const V &  rhs 
)

This function compares two general vectors of equal size lexicographically.

This function considers two elements equal using the checkEqualGeneral function.

Note: This function assumes that the inputs are equally sized.

Parameters
lhsThe left hand size of the comparison.
rhsThe right hand size of the comparison.
Returns
The strong_ordering of the input vectors.

◆ veccmpSmall()

template<typename V >
std::partial_ordering AIToolbox::veccmpSmall ( const V &  lhs,
const V &  rhs 
)

This function compares two general vectors of equal size lexicographically.

Note that veccmpSmall considers two elements equal using the checkEqualSmall function.

Note: This function assumes that the inputs are equally sized.

Parameters
lhsThe left hand size of the comparison.
rhsThe right hand size of the comparison.
Returns
The strong_ordering of the input vectors.

◆ write() [1/10]

std::ostream& AIToolbox::write ( std::ostream &  os,
const Matrix2D m 
)

◆ write() [2/10]

std::ostream& AIToolbox::write ( std::ostream &  os,
const Matrix3D m 
)

◆ write() [3/10]

std::ostream& AIToolbox::write ( std::ostream &  os,
const SparseMatrix2D m 
)

◆ write() [4/10]

std::ostream& AIToolbox::write ( std::ostream &  os,
const SparseMatrix3D m 
)

◆ write() [5/10]

std::ostream& AIToolbox::write ( std::ostream &  os,
const SparseTable2D t 
)

◆ write() [6/10]

std::ostream& AIToolbox::write ( std::ostream &  os,
const SparseTable3D t 
)

◆ write() [7/10]

std::ostream& AIToolbox::write ( std::ostream &  os,
const Table2D t 
)

◆ write() [8/10]

std::ostream& AIToolbox::write ( std::ostream &  os,
const Table3D t 
)

◆ write() [9/10]

std::ostream& AIToolbox::write ( std::ostream &  os,
const Vector v 
)

◆ write() [10/10]

std::ostream& AIToolbox::write ( std::ostream &  os,
double  d 
)

Variable Documentation

◆ AILogger

AILoggerFun* AIToolbox::AILogger = nullptr
inline

This pointer defines the function used to log.

See also
How Logging Works

◆ different_from

template<typename A , typename B >
concept AIToolbox::different_from = !std::same_as<A, B>

This concept simplifies checking for non-void.

◆ equalToleranceGeneral

constexpr auto AIToolbox::equalToleranceGeneral = 0.00000000001
constexpr

This is a relative term used in the checkEqualGeneral functions, where two values may be considered equal if they are within this percentage of each other.

◆ equalToleranceSmall

constexpr auto AIToolbox::equalToleranceSmall = 0.000001
constexpr

This is the max absolute difference for which two values can be considered equal.

◆ HasActionSpace

template<typename M >
concept AIToolbox::HasActionSpace = HasFixedActionSpace<M> || HasVariableActionSpace<M>

This concept checks that some form of getA exists.

◆ HasFixedActionSpace

template<typename M >
concept AIToolbox::HasFixedActionSpace
Initial value:
= requires(const M m) {
{ m.getA() } -> different_from<void>;
}

This concept checks that getA() exists.

◆ HasIntegralActionSpace

template<typename M >
concept AIToolbox::HasIntegralActionSpace
Initial value:
= requires(const M m) {
requires
(HasFixedActionSpace<M> && requires {{ m.getA() } -> std::same_as<size_t>; }) ||
(HasVariableActionSpace<M> && requires {{ m.getA(m.getS()) } -> std::same_as<size_t>; });
}

This concept checks that getA returns size_t.

◆ HasIntegralObservationSpace

template<typename M >
concept AIToolbox::HasIntegralObservationSpace
Initial value:
= requires(const M m) {
{ m.getO() } -> std::same_as<size_t>;
}

This concept checks that getO() returns size_t.

◆ HasIntegralStateSpace

template<typename M >
concept AIToolbox::HasIntegralStateSpace
Initial value:
= requires(const M m) {
{ m.getS() } -> std::same_as<size_t>;
}

This concept checks that getS() returns size_t.

◆ HasObservationSpace

template<typename M >
concept AIToolbox::HasObservationSpace
Initial value:
= requires(const M m) {
{ m.getO() } -> different_from<void>;
}

This concept checks that getO() exists.

◆ HasStateSpace

template<typename M >
concept AIToolbox::HasStateSpace
Initial value:
= requires(const M m) {
{ m.getS() } -> different_from<void>;
}

This concept checks that getS() exists.

◆ HasVariableActionSpace

template<typename M >
concept AIToolbox::HasVariableActionSpace
Initial value:
= requires(const M m) {
{ m.getA(m.getS()) } -> different_from<void>;
}

This concept checks that getA(state) exists.

◆ IsDerivedFromEigen

template<typename T >
concept AIToolbox::IsDerivedFromEigen = std::derived_from<T, Eigen::EigenBase<T>>

This concept simplifies checking for non-void.

◆ IsGenerativeModel

template<typename M >
concept AIToolbox::IsGenerativeModel
Initial value:
= HasStateSpace<M> && HasActionSpace<M> && requires(const M m) {
{ m.getDiscount() } -> std::convertible_to<double>;
{ m.isTerminal(m.getS()) } -> std::convertible_to<bool>;
requires
(HasFixedActionSpace<M> && requires {{ m.sampleSR(m.getS(), m.getA()) } -> std::convertible_to<std::tuple<std::remove_cvref_t<decltype(m.getS())>, double>>; }) ||
(HasVariableActionSpace<M> && requires {{ m.sampleSR(m.getS(), m.getA(m.getS())) } -> std::convertible_to<std::tuple<std::remove_cvref_t<decltype(m.getS())>, double>>; });
}

This concept checks the minimum requirements for a generative model.

This concept defines the minimum requirements for the minimum generative model we will probably accept around the library.

While the concept has no specific requirements for what the states and actions can be, each algorithm will probably be more strict about types (for example may require integral state/action spaces, or a fixed action space).

We need:

  • getS()
  • getA() or getA(state)

Note that we do not specify here which types the states and actions should be.

  • getDiscount()
  • sampleSR(state, action)
  • isTerminal(state)

◆ IsNaive2DMatrix

template<typename M >
concept AIToolbox::IsNaive2DMatrix
Initial value:
= requires (M m) {
{ m[0][0] } -> std::convertible_to<double>;
}

This concept checks for a simple 2D accessible matrix.

◆ IsNaive2DTable

template<typename T >
concept AIToolbox::IsNaive2DTable
Initial value:
= requires (T t) {
{ t[0][0] } -> std::convertible_to<long unsigned>;
}

This concept checks for a simple 2D accessible table.

◆ IsNaive3DMatrix

template<typename M >
concept AIToolbox::IsNaive3DMatrix
Initial value:
= requires (M m) {
{ m[0][0][0] } -> std::convertible_to<double>;
}

This concept checks for a simple 3D accessible matrix.

◆ IsNaive3DTable

template<typename T >
concept AIToolbox::IsNaive3DTable
Initial value:
= requires (T t) {
{ t[0][0][0] } -> std::convertible_to<long unsigned>;
}

This concept checks for a simple 3D accessible table.

◆ NO_CHECK

struct AIToolbox::NoCheck AIToolbox::NO_CHECK