AIToolbox
A library that offers tools for AI problem solving.
|
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, Vector > | 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. More... | |
std::tuple< double, Vector > | 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. 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 ¶ms, G &generator) |
This function samples from the input Dirichlet distribution. More... | |
template<typename TIn , typename TOut , typename G > | |
void | sampleDirichletDistribution (const TIn ¶ms, 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 | |
AILoggerFun * | AILogger = 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 |
using AIToolbox::AILoggerFun = typedef void(int, const char *) |
using AIToolbox::CompactHyperplanes = typedef 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>.
using AIToolbox::copy_const_t = typedef typename copy_const<CopiedType, ConstReference>::type |
using AIToolbox::DumbMatrix2D = typedef boost::multi_array<double, 2> |
using AIToolbox::DumbMatrix3D = typedef boost::multi_array<double, 3> |
using AIToolbox::DumbTable2D = typedef boost::multi_array<unsigned long, 2> |
using AIToolbox::DumbTable3D = typedef boost::multi_array<unsigned long, 3> |
using AIToolbox::Hyperplane = typedef Vector |
Defines a plane in a simplex where each value is the height at that corner.
using AIToolbox::Matrix2D = typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor | Eigen::AutoAlign> |
using AIToolbox::Matrix3D = typedef std::vector<Matrix2D> |
using AIToolbox::Matrix4D = typedef boost::multi_array<Matrix2D, 2> |
using AIToolbox::Point = typedef ProbabilityVector |
Defines a point inside a simplex. Coordinates sum to 1.
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.
using AIToolbox::ProbabilityVector = typedef Vector |
using AIToolbox::RandomEngine = typedef std::mt19937 |
using AIToolbox::SparseMatrix2D = typedef Eigen::SparseMatrix<double, Eigen::RowMajor> |
using AIToolbox::SparseMatrix3D = typedef std::vector<SparseMatrix2D> |
using AIToolbox::SparseMatrix4D = typedef boost::multi_array<SparseMatrix2D, 2> |
using AIToolbox::SparseTable2D = typedef Eigen::SparseMatrix<unsigned long, Eigen::RowMajor> |
using AIToolbox::SparseTable3D = typedef std::vector<SparseTable2D> |
using AIToolbox::Table2D = typedef Eigen::Matrix<unsigned long, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor | Eigen::AutoAlign> |
using AIToolbox::Table3D = typedef std::vector<Table2D> |
using AIToolbox::Vector = typedef Eigen::Matrix<double, Eigen::Dynamic, 1> |
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.
|
inline |
This function returns a fast ceiling between two unsigned ints.
Note: we do x + y, so it may overflow.
x | The dividend. |
y | The divisor. |
|
inline |
This function checks if two doubles are reasonably different.
The order of the parameters is not important.
a | The first number to compare. |
b | The second number to compare. |
bool AIToolbox::checkDifferentGeneral | ( | const V & | v, |
const double | d | ||
) |
This function checks whether a given vector does not contain only the stated value.
|
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.
a | The first number to compare. |
b | The second number to compare. |
bool AIToolbox::checkDifferentSmall | ( | const V & | v, |
const double | d | ||
) |
This function checks whether a given vector does not contain only the stated value.
|
inline |
This function checks if two doubles are reasonably equal.
The order of the parameters is not important.
a | The first number to compare. |
b | The second number to compare. |
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);
|
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.
lhs | The left hand side to check. |
rhs | The right hand side to check. |
|
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.
a | The first number to compare. |
b | The second number to compare. |
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);
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.
p | The point where we want to compute the best possible value. |
points | The points that make up the surface. |
values | The respective values of the input points. |
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.
T | Type of the input container. |
U | Type of the output container. |
in | Input container. |
out | Output container. |
d1 | First dimension of the containers. |
d2 | Second dimension of the containers. |
d3 | Third dimension of the containers. |
|
inline |
This function checks whether an Hyperplane dominates another.
lhs | The Hyperplane that should dominate. |
rhs | The Hyperplane that should be dominated. |
Iterator AIToolbox::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.
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.
point | The point where we need to check the value |
begin | The begin of the search range. |
bound | The begin of the 'useful' range. |
end | The range end to be checked. It is NOT included in the search. |
p | A projection function to call on the iterators (defaults to identity). |
Iterator AIToolbox::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.
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.
S | The number of corners of the simplex. |
begin | The begin of the search range. |
bound | The begin of the 'useful' range. |
end | The end of the search range. It is NOT included in the search. |
p | A projection function to call on the iterators (defaults to identity). |
PIterator AIToolbox::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.
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).
pbegin | The beginning of the Point range to check. |
pend | The end of the Point range to check. |
begin | The beginning of the Hyperplane range to check against. |
end | The end of the Hyperplane range to check against. |
p | A projection function to call on the iterators (defaults to identity). |
Iterator AIToolbox::extractDominated | ( | Iterator | begin, |
Iterator | end, | ||
P | 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.
begin | The begin of the list that needs to be pruned. |
end | The end of the list that needs to be pruned. |
p | A projection function to call on the iterators (defaults to identity). |
std::tuple<Iterator, Iterator, Iterator> AIToolbox::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.
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).
begin | The begin of the list that needs to be pruned. |
newBegin | The begin of the new Hyperplanes that need to be checked. |
end | The end of the list that needs to be pruned. |
p | A projection function to call on the iterators (defaults to identity). |
Iterator AIToolbox::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.
Given a list of hyperplanes as a surface, this function returns the hyperplane which provides the highest value at the specified point.
point | The point where we need to check the value |
begin | The start of the range to look in. |
end | The end of the range to look in (excluded). |
value | A pointer to double, which gets set to the value of the given point with the found Hyperplane. |
p | A projection function to call on the iterators (defaults to identity). |
Iterator AIToolbox::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.
This function is slightly more efficient than findBestAtPoint for a simplex corner.
corner | The corner of the simplex space we are checking. |
begin | The start of the range to look in. |
end | The end of the range to look in (excluded). |
value | A pointer to double, which gets set to the value of the corner with the found Hyperplane. |
p | A projection function to call on the iterators (defaults to identity). |
Iterator AIToolbox::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.
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.
point | The Point where to check for delta-domination. |
plane | The Hyperplane that needs to be delta-dominated. |
delta | The delta value to use to validate delta-domination, i.e. the size of the neighborhood to check. |
begin | The start of the range to check. |
end | The end of the range to check. |
p | A projection function to call on the iterators (defaults to identity). |
PointSurface AIToolbox::findVerticesNaive | ( | const Range & | range, |
P | 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.
range | The range of planes to examine. |
p | A projection function to call on the iterators of the range (defaults to 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.
beginNew | The beginning of the range of the planes to find vertices for. |
endNew | The end of the range of the planes to find vertices for. |
alphasBegin | The beginning of the range of all other planes. |
alphasEnd | The end of the range of all other planes. |
p1 | A projection function to call on the iterators of the first range (defaults to identity). |
p2 | A projection function to call on the iterators of the second range (defaults to identity). |
|
inline |
This function returns the entropy of the input ProbabilityVector.
v | The input ProbabilityVector. |
|
inline |
This function returns the entropy of the input ProbabilityVector computed using log2.
v | The input ProbabilityVector. |
AIToolbox::IndexMap | ( | IdsContainer | , |
Container & | |||
) | -> IndexMap< IdsContainer, Container > |
AIToolbox::IndexMap | ( | std::initializer_list< T > | i, |
Container | c | ||
) | -> IndexMap< std::vector< T >, Container > |
AIToolbox::IndexSkipMap | ( | IdsContainer | , |
Container & | |||
) | -> IndexSkipMap< IdsContainer, Container > |
AIToolbox::IndexSkipMap | ( | std::initializer_list< T > | i, |
Container | c | ||
) | -> IndexSkipMap< std::vector< T >, Container > |
bool AIToolbox::isProbability | ( | const Matrix2D & | in | ) |
This function checks whether the rows of the input matrix contain valid discrete distributions.
in | The input matrix. |
bool AIToolbox::isProbability | ( | const Matrix3D & | in | ) |
This function checks whether the rows of the input matrix contain valid discrete distributions.
in | The input matrix. |
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.
T | The 3D container type. |
depth | The size of the first dimension of the container. |
rows | The size of the second dimension of the container. |
cols | The size of the third dimension of the container. |
in | The input container. |
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.
T | The 2D container type. |
rows | The size of the first dimension of the container. |
cols | The size of the second dimension of the container. |
in | The input container. |
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.
T | The 1D container type. |
size | The size of the container. |
in | The input container. |
bool AIToolbox::isProbability | ( | const SparseMatrix2D & | in | ) |
This function checks whether the rows of the input matrix contain valid discrete distributions.
in | The input matrix. |
bool AIToolbox::isProbability | ( | const SparseMatrix3D & | in | ) |
This function checks whether the rows of the input matrix contain valid discrete distributions.
in | The input matrix. |
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.
p | The point to compute the value of. |
ubQ | A set of Hyperplanes to use as a baseline surface. |
ubV | A set of Points (not on the corners of the simplex) to use as main interpolation. |
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.
S | The number of entries of the output vector. |
generator | A random number generator. |
auto AIToolbox::max_element_unary | ( | It | begin, |
const It | end, | ||
F | 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.
begin | The begin of the range to compare. |
end | The end of the range to compare. |
unary_converter | The unary function to apply to each item in the range. |
unsigned AIToolbox::nChooseK | ( | unsigned | n, |
unsigned | k | ||
) |
Returns (n k); i.e. n choose k.
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.
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.
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.
os | The stream to write to. |
rh | The Statistics to get data from. |
|
static |
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.
v | The vector to project to a valid probability space. |
std::istream& AIToolbox::read | ( | std::istream & | is, |
Matrix2D & | m | ||
) |
std::istream& AIToolbox::read | ( | std::istream & | is, |
Matrix3D & | m | ||
) |
std::istream& AIToolbox::read | ( | std::istream & | is, |
SparseMatrix2D & | m | ||
) |
std::istream& AIToolbox::read | ( | std::istream & | is, |
SparseMatrix3D & | m | ||
) |
std::istream& AIToolbox::read | ( | std::istream & | is, |
SparseTable2D & | t | ||
) |
std::istream& AIToolbox::read | ( | std::istream & | is, |
SparseTable3D & | t | ||
) |
std::istream& AIToolbox::read | ( | std::istream & | is, |
Table2D & | t | ||
) |
std::istream& AIToolbox::read | ( | std::istream & | is, |
Table3D & | t | ||
) |
std::istream& AIToolbox::read | ( | std::istream & | is, |
Vector & | v | ||
) |
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.
G | The type of the generator used. |
a | The 'a' shape parameter of the Beta distribution to sample. |
b | The 'b' shape parameter of the Beta distribution to sample. |
generator | A random number generator. |
FIXME: make dist object like the others.
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.
params | The parameters of the Dirichlet distribution. |
generator | The random generator to sample from. |
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).
params | The parameters of the Dirichlet distribution. |
generator | The random generator to sample from. |
out | The output container. |
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.
G | The type of the generator used. |
in | The external probability container. |
d | The size of the supplied container. |
generator | The generator used to sample. |
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.
T | The type of the container vector to sample. |
G | The type of the generator used. |
in | The external probability container. |
d | The size of the supplied container. |
generator | The generator used to sample. |
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.
p | The point to compute the value of. |
ubQ | A set of Hyperplanes to use as a baseline surface. |
ubV | A set of Points (not on the corners of the simplex) to use as main interpolation. |
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.
V | The type of the vector to be scanned. |
v | The vector to be scanned. |
elems | The vector that must be contained. |
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.
begin | The beginning of the sorted range to scan. |
end | The end of the sorted range to scan. |
elem | The element to be looked for in the range. |
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.
begin | The beginning of the sorted range to scan. |
end | The end of the sorted range to scan. |
elem | The element to be looked for in the range. |
void AIToolbox::set_union_inplace | ( | std::vector< T > & | lhs, |
const std::vector< T > & | rhs | ||
) |
This function performs an inplace union of two sorted sets.
lhs | The left hand side, to be increased. |
rhs | The right hand side. |
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.
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.
lhs | The left hand size of the comparison. |
rhs | The right hand size of the comparison. |
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.
lhs | The left hand size of the comparison. |
rhs | The right hand size of the comparison. |
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.
lhs | The left hand size of the comparison. |
rhs | The right hand size of the comparison. |
std::ostream& AIToolbox::write | ( | std::ostream & | os, |
const Matrix2D & | m | ||
) |
std::ostream& AIToolbox::write | ( | std::ostream & | os, |
const Matrix3D & | m | ||
) |
std::ostream& AIToolbox::write | ( | std::ostream & | os, |
const SparseMatrix2D & | m | ||
) |
std::ostream& AIToolbox::write | ( | std::ostream & | os, |
const SparseMatrix3D & | m | ||
) |
std::ostream& AIToolbox::write | ( | std::ostream & | os, |
const SparseTable2D & | t | ||
) |
std::ostream& AIToolbox::write | ( | std::ostream & | os, |
const SparseTable3D & | t | ||
) |
std::ostream& AIToolbox::write | ( | std::ostream & | os, |
const Table2D & | t | ||
) |
std::ostream& AIToolbox::write | ( | std::ostream & | os, |
const Table3D & | t | ||
) |
std::ostream& AIToolbox::write | ( | std::ostream & | os, |
const Vector & | v | ||
) |
std::ostream& AIToolbox::write | ( | std::ostream & | os, |
double | d | ||
) |
|
inline |
This pointer defines the function used to log.
concept AIToolbox::different_from = !std::same_as<A, B> |
This concept simplifies checking for non-void.
|
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.
|
constexpr |
This is the max absolute difference for which two values can be considered equal.
concept AIToolbox::HasActionSpace = HasFixedActionSpace<M> || HasVariableActionSpace<M> |
This concept checks that some form of getA exists.
concept AIToolbox::HasFixedActionSpace |
This concept checks that getA() exists.
concept AIToolbox::HasIntegralActionSpace |
This concept checks that getA returns size_t.
concept AIToolbox::HasIntegralObservationSpace |
This concept checks that getO() returns size_t.
concept AIToolbox::HasIntegralStateSpace |
This concept checks that getS() returns size_t.
concept AIToolbox::HasObservationSpace |
This concept checks that getO() exists.
concept AIToolbox::HasStateSpace |
This concept checks that getS() exists.
concept AIToolbox::HasVariableActionSpace |
This concept checks that getA(state) exists.
concept AIToolbox::IsDerivedFromEigen = std::derived_from<T, Eigen::EigenBase<T>> |
This concept simplifies checking for non-void.
concept AIToolbox::IsGenerativeModel |
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:
Note that we do not specify here which types the states and actions should be.
concept AIToolbox::IsNaive2DMatrix |
This concept checks for a simple 2D accessible matrix.
concept AIToolbox::IsNaive2DTable |
This concept checks for a simple 2D accessible table.
concept AIToolbox::IsNaive3DMatrix |
This concept checks for a simple 3D accessible matrix.
concept AIToolbox::IsNaive3DTable |
This concept checks for a simple 3D accessible table.
struct AIToolbox::NoCheck AIToolbox::NO_CHECK |