AIToolbox
A library that offers tools for AI problem solving.
|
Namespaces | |
Bandit | |
MDP | |
Classes | |
struct | BasisFunction |
This struct represents a basis function. More... | |
struct | BasisMatrix |
This struct represents a basis matrix. More... | |
class | CPSQueue |
This class is used as the priority queue for CooperativePrioritizedSweeping. More... | |
struct | DynamicDecisionNetwork |
This class represents a Dynamic Decision Network with factored actions. More... | |
class | DynamicDecisionNetworkGraph |
This class represents the structure of a dynamic decision network. More... | |
struct | FactoredMatrix2D |
This class represents a factored 2D matrix. More... | |
struct | FactoredVector |
This class represents a factored vector. More... | |
class | FactorGraph |
This class offers a minimal interface to manager a factor graph. More... | |
class | FasterTrie |
This class is a generally faster implementation of a Trie. More... | |
class | FilterMap |
This class is a container which uses PartialFactors as keys. More... | |
class | GenericVariableElimination |
This class represents the Variable Elimination algorithm. More... | |
class | PartialFactorsEnumerator |
This class enumerates all possible values for a PartialFactors. More... | |
class | PartialIndexEnumerator |
This class enumerates the indeces of all combinations where a value is fixed. More... | |
class | Trie |
This class organizes data ids as if in a trie. More... | |
Typedefs | |
using | DDNGraph = DynamicDecisionNetworkGraph |
using | DDN = DynamicDecisionNetwork |
Enumerations | |
enum | TagErrors { TagErrors::None, TagErrors::NoElements, TagErrors::TooManyElements, TagErrors::IdTooHigh, TagErrors::NotSorted, TagErrors::Duplicates } |
This enum contains all possible errors in a tag. More... | |
Functions | |
template<typename Factor > | |
auto | buildAdjacencyList (const Action &A, const FactorGraph< Factor > &graph) |
template<typename Factor > | |
size_t | APSP (const FactorGraph< Factor > &graph) |
This function solves the APSP problem for the provided graph. More... | |
template<typename Factor > | |
auto | buildAdjacencyList (const FactorGraph< Factor > &graph) |
This function computes an adjacency list between the variables of the input graph. More... | |
BasisMatrix | backProject (const DDN &ddn, const BasisFunction &bf) |
FactoredMatrix2D | backProject (const DDN &ddn, const FactoredVector &fv) |
std::pair< TagErrors, size_t > | checkTag (const Factors &space, const PartialKeys &tag) |
This function verifies whether a tag is correct w.r.t. a space. More... | |
PartialFactors | removeFactor (const PartialFactors &pf, size_t f) |
This function removes the specified factor from the input PartialFactors. More... | |
template<typename Gen > | |
Factors | makeRandomValue (const Factors &space, Gen &rnd) |
This function randomly generates a valid value inside the provided space. More... | |
bool | match (const PartialFactors &lhs, const PartialFactors &rhs) |
This function returns whether the common factors in the inputs match in value. More... | |
bool | match (const Factors &lhs, const PartialFactors &rhs) |
This function returns whether the common factors in the inputs match in value. More... | |
bool | match (const PartialKeys &lhsK, const PartialValues &lhs, const PartialKeys &rhsK, const PartialValues &rhs) |
This function returns whether the common factors in the inputs match in value. More... | |
bool | match (const PartialKeys &keys, const Factors &lhs, const Factors &rhs) |
This function checks whether the two input Factors match at the specified ids. More... | |
bool | match (const std::vector< std::pair< size_t, size_t >> &matches, const Factors &lhs, const Factors &rhs) |
This function checks whether the two input Factors match at the specified ids. More... | |
void | join (size_t S, PartialFactors *lhs, const PartialFactors &rhs) |
This function appends the rhs to the lhs, assuming the original Factor for lhs has S elements. More... | |
Factors | join (const Factors &lhs, const Factors &rhs) |
This function creates a new Factor appending rhs to lhs. More... | |
PartialKeys | join (size_t S, const PartialKeys &lhs, const PartialKeys &rhs) |
This function appends rhs to lhs, assuming the full Factor for lhs has S elements. More... | |
PartialFactors | join (size_t S, const PartialFactors &lhs, const PartialFactors &rhs) |
This function appends rhs to lhs, assuming the full Factor for lhs has S elements. More... | |
void | unsafe_join (PartialFactors *lhs, const PartialFactors &rhs) |
This function appends the rhs to the lhs. More... | |
PartialFactors | merge (const PartialFactors &lhs, const PartialFactors &rhs) |
This function merges two PartialFactors together. More... | |
PartialValues | merge (const PartialKeys &lhsk, const PartialValues &lhs, const PartialKeys &rhsk, const PartialValues &rhs) |
This function merges two PartialValues together, using two PartialKeys as guides. More... | |
PartialKeys | merge (const PartialKeys &lhs, const PartialKeys &rhs, std::vector< std::pair< size_t, size_t >> *matches=nullptr) |
This function merges two PartialKeys together. More... | |
size_t | factorSpace (const Factors &space) |
This function returns the multiplication of all elements of the input factor. More... | |
size_t | factorSpacePartial (const PartialKeys &ids, const Factors &space) |
This function returns the multiplication of all elements of the input factor. More... | |
PartialFactors | toPartialFactors (const Factors &f) |
This function converts Factors into the equivalent PartialFactors structure. More... | |
Factors | toFactors (size_t F, const PartialFactors &pf) |
This function converts PartialFactors into the equivalent Factors structure. More... | |
Factors | toFactors (const Factors &space, size_t id) |
This function converts an index into the equivalent Factors, within the specified factor space. More... | |
void | toFactors (const Factors &space, size_t id, Factors *out) |
This function converts an index into the equivalent Factors, within the specified factor space. More... | |
PartialValues | toFactorsPartial (const PartialKeys &ids, const Factors &space, size_t id) |
This function converts an index into the equivalent PartialValues of the input keys, within the specified factor space. More... | |
template<typename It > | |
void | toFactorsPartial (It begin, const PartialKeys &ids, const Factors &space, size_t id) |
This function converts an index into the equivalent PartialValues of the input keys, within the specified factor space. More... | |
size_t | toIndex (const Factors &space, const Factors &f) |
This function converts the input factor in the input space to an unique index. More... | |
size_t | toIndex (const Factors &space, const PartialFactors &f) |
This function converts the input factor in the input space to an unique index. More... | |
size_t | toIndexPartial (const PartialKeys &ids, const Factors &space, const Factors &f) |
This function converts the input factor in the input space to an unique index. More... | |
size_t | toIndexPartial (const PartialKeys &ids, const Factors &space, const PartialFactors &pf) |
This function converts the input factor in the input space to an unique index. More... | |
size_t | toIndexPartial (const Factors &space, const PartialFactors &f) |
This function converts the input factor in the input space to an unique index. More... | |
std::pair< size_t, size_t > | toIndexPartialAndSkip (const PartialKeys &ids, const Factors &space, const Factors &f, size_t id) |
This function avoids computing indeces multiple times if only a single index is changing. More... | |
using AIToolbox::Factored::Action = typedef Factors |
using AIToolbox::Factored::DDN = typedef DynamicDecisionNetwork |
using AIToolbox::Factored::DDNGraph = typedef DynamicDecisionNetworkGraph |
using AIToolbox::Factored::Factors = typedef std::vector<size_t> |
using AIToolbox::Factored::PartialAction = typedef PartialFactors |
using AIToolbox::Factored::PartialFactors = typedef std::pair<PartialKeys, PartialValues> |
using AIToolbox::Factored::PartialKeys = typedef std::vector<size_t> |
using AIToolbox::Factored::PartialState = typedef PartialFactors |
using AIToolbox::Factored::PartialValues = typedef std::vector<size_t> |
using AIToolbox::Factored::Rewards = typedef Vector |
using AIToolbox::Factored::State = typedef Factors |
|
strong |
This enum contains all possible errors in a tag.
Enumerator | |
---|---|
None | |
NoElements | |
TooManyElements | |
IdTooHigh | |
NotSorted | |
Duplicates |
size_t AIToolbox::Factored::APSP | ( | const FactorGraph< Factor > & | graph | ) |
This function solves the APSP problem for the provided graph.
This function computes the graph diameter; i.e. the shortest longest path between any two variable nodes. Factor nodes are treated as multi-edges for this purpose, so they do not count as actual nodes and they do not (directly) contribute to the diameter size.
This function can be used to compute the iteration parameter for MaxPlus, as the number of message iterations needed should be the same as the diameter of the graph.
graph | The graph to compute the diameter for. |
BasisMatrix AIToolbox::Factored::backProject | ( | const DDN & | ddn, |
const BasisFunction & | bf | ||
) |
FactoredMatrix2D AIToolbox::Factored::backProject | ( | const DDN & | ddn, |
const FactoredVector & | fv | ||
) |
auto AIToolbox::Factored::buildAdjacencyList | ( | const Action & | A, |
const FactorGraph< Factor > & | graph | ||
) |
auto AIToolbox::Factored::buildAdjacencyList | ( | const FactorGraph< Factor > & | graph | ) |
This function computes an adjacency list between the variables of the input graph.
This function returns a vector with one element for each variable. Each variable's element is itself a vector containing the indeces of all neighbors of the variable. Two variables are neighbors if they are connected to at least one common factor.
graph | The graph to compute the adjacency list for. |
std::pair<TagErrors, size_t> AIToolbox::Factored::checkTag | ( | const Factors & | space, |
const PartialKeys & | tag | ||
) |
This function verifies whether a tag is correct w.r.t. a space.
This function does a series of basic checks on the input tag, to see whether it was initialized correctly with respect to the input space.
This function is useful to do some checking on your models to make sure that there are no errors.
space | The space associated with the tag. |
tag | The tag to verify. |
BasisFunction AIToolbox::Factored::dot | ( | const Factors & | space, |
const BasisFunction & | lhs, | ||
const BasisFunction & | rhs | ||
) |
size_t AIToolbox::Factored::factorSpace | ( | const Factors & | space | ) |
This function returns the multiplication of all elements of the input factor.
In case the factor space is too big to represent via a size_t, the maximum possible representable value is returned.
space | The factored factor space. |
size_t AIToolbox::Factored::factorSpacePartial | ( | const PartialKeys & | ids, |
const Factors & | space | ||
) |
This function returns the multiplication of all elements of the input factor.
This function only takes into account the input ids.
In case the factor space is too big to represent via a size_t, the maximum possible representable value is returned.
ids | The indeces to consider. |
space | The factored factor space. |
This function creates a new Factor appending rhs to lhs.
lhs | The left hand side. |
rhs | The right hand side. |
PartialFactors AIToolbox::Factored::join | ( | size_t | S, |
const PartialFactors & | lhs, | ||
const PartialFactors & | rhs | ||
) |
This function appends rhs to lhs, assuming the full Factor for lhs has S elements.
S | The number of factors the full Factor for lhs has. |
lhs | The left hand side. |
rhs | The right hand side. |
PartialKeys AIToolbox::Factored::join | ( | size_t | S, |
const PartialKeys & | lhs, | ||
const PartialKeys & | rhs | ||
) |
This function appends rhs to lhs, assuming the full Factor for lhs has S elements.
S | The number of factors the full Factor for lhs has. |
lhs | The left hand side. |
rhs | The right hand side. |
void AIToolbox::Factored::join | ( | size_t | S, |
PartialFactors * | lhs, | ||
const PartialFactors & | rhs | ||
) |
This function appends the rhs to the lhs, assuming the original Factor for lhs has S elements.
S | The number of factors the full Factor for lhs has. |
lhs | The left hand side that gets extended in place. |
rhs | The right hand side. |
Factors AIToolbox::Factored::makeRandomValue | ( | const Factors & | space, |
Gen & | rnd | ||
) |
This function randomly generates a valid value inside the provided space.
bool AIToolbox::Factored::match | ( | const Factors & | lhs, |
const PartialFactors & | rhs | ||
) |
This function returns whether the common factors in the inputs match in value.
lhs | The left hand side. |
rhs | The right hand side. |
bool AIToolbox::Factored::match | ( | const PartialFactors & | lhs, |
const PartialFactors & | rhs | ||
) |
This function returns whether the common factors in the inputs match in value.
lhs | The left hand side. |
rhs | The right hand side. |
bool AIToolbox::Factored::match | ( | const PartialKeys & | keys, |
const Factors & | lhs, | ||
const Factors & | rhs | ||
) |
This function checks whether the two input Factors match at the specified ids.
keys | The ids to check. |
lhs | The left hand side. |
rhs | The right hand side. |
bool AIToolbox::Factored::match | ( | const PartialKeys & | lhsK, |
const PartialValues & | lhs, | ||
const PartialKeys & | rhsK, | ||
const PartialValues & | rhs | ||
) |
This function returns whether the common factors in the inputs match in value.
This function is equivalent to match(const PartialFactors & lhs, const PartialFactors & rhs). It is provided to avoid having to construct two PartialFactors when not needed.
lhsK | The keys of the lhs. |
lhs | The values of the lhs. |
rhsK | The keys of the rhs. |
rhs | The values of the rhs. |
bool AIToolbox::Factored::match | ( | const std::vector< std::pair< size_t, size_t >> & | matches, |
const Factors & | lhs, | ||
const Factors & | rhs | ||
) |
This function checks whether the two input Factors match at the specified ids.
Each check is performed on a pair of ids: one for the left hand side, and its respective one for the right hand side.
matches | The id pairs to check. |
lhs | The left hand side. |
rhs | The right hand side. |
PartialFactors AIToolbox::Factored::merge | ( | const PartialFactors & | lhs, |
const PartialFactors & | rhs | ||
) |
This function merges two PartialFactors together.
This function assumes that all elements in the PartialFactors have different keys. If they have the same keys, the key is inserted once in the output, but its value is unspecified (it will be from one of the two inputs).
lhs | The left hand side. |
rhs | The right hand side. |
PartialKeys AIToolbox::Factored::merge | ( | const PartialKeys & | lhs, |
const PartialKeys & | rhs, | ||
std::vector< std::pair< size_t, size_t >> * | matches = nullptr |
||
) |
This function merges two PartialKeys together.
This function merges two PartialKeys over the same range. Overlapping elements are merged together.
The function optionally returns a vector which specifies the indeces of the matches in the input. This may be useful to do checks before doing merges.
lhs | The left hand side. |
rhs | The right hand side. |
matches | An optional vector containing the matching indexes of the inputs |
PartialValues AIToolbox::Factored::merge | ( | const PartialKeys & | lhsk, |
const PartialValues & | lhs, | ||
const PartialKeys & | rhsk, | ||
const PartialValues & | rhs | ||
) |
This function merges two PartialValues together, using two PartialKeys as guides.
This function is equivalent to merge(const PartialFactors&, const PartialFactors&), with the only difference that it does not merge the keys.
This function assumes that all elements in the PartialKeys are different. If there are matches, the corrisponding element is inserted once output, but its value is unspecified (it will be from one of the two input PartialValues).
lhsk | The left hand side keys. |
lhs | The left hand side. |
rhsk | The right hand side keys. |
rhs | The right hand side. |
BasisFunction AIToolbox::Factored::minus | ( | const Factors & | space, |
const BasisFunction & | lhs, | ||
const BasisFunction & | rhs | ||
) |
FactoredVector AIToolbox::Factored::minus | ( | const Factors & | space, |
FactoredVector | retval, | ||
const BasisFunction & | rhs, | ||
bool | clearZero = false |
||
) |
FactoredVector AIToolbox::Factored::minus | ( | const Factors & | space, |
FactoredVector | retval, | ||
const FactoredVector & | rhs, | ||
bool | clearZero = false |
||
) |
FactoredVector& AIToolbox::Factored::minusEqual | ( | const Factors & | space, |
FactoredVector & | retval, | ||
const BasisFunction & | basis, | ||
bool | clearZero = false |
||
) |
FactoredVector& AIToolbox::Factored::minusEqual | ( | const Factors & | space, |
FactoredVector & | retval, | ||
const FactoredVector & | rhs, | ||
bool | clearZero = false |
||
) |
BasisFunction& AIToolbox::Factored::minusEqualSubset | ( | const Factors & | space, |
BasisFunction & | retval, | ||
const BasisFunction & | rhs | ||
) |
BasisFunction AIToolbox::Factored::minusSubset | ( | const Factors & | space, |
BasisFunction | retval, | ||
const BasisFunction & | rhs | ||
) |
FactoredMatrix2D AIToolbox::Factored::operator* | ( | const double | v, |
FactoredMatrix2D | rhs | ||
) |
FactoredVector AIToolbox::Factored::operator* | ( | const double | v, |
FactoredVector | rhs | ||
) |
FactoredMatrix2D AIToolbox::Factored::operator* | ( | const Vector & | w, |
FactoredMatrix2D | rhs | ||
) |
FactoredVector AIToolbox::Factored::operator* | ( | const Vector & | w, |
FactoredVector | rhs | ||
) |
FactoredMatrix2D AIToolbox::Factored::operator* | ( | FactoredMatrix2D | lhs, |
const double | v | ||
) |
FactoredMatrix2D AIToolbox::Factored::operator* | ( | FactoredMatrix2D | lhs, |
const Vector & | w | ||
) |
FactoredVector AIToolbox::Factored::operator* | ( | FactoredVector | lhs, |
const double | v | ||
) |
FactoredVector AIToolbox::Factored::operator* | ( | FactoredVector | lhs, |
const Vector & | w | ||
) |
BasisFunction AIToolbox::Factored::plus | ( | const Factors & | space, |
const BasisFunction & | lhs, | ||
const BasisFunction & | rhs | ||
) |
BasisMatrix AIToolbox::Factored::plus | ( | const Factors & | space, |
const Factors & | actions, | ||
const BasisMatrix & | lhs, | ||
const BasisMatrix & | rhs | ||
) |
FactoredVector AIToolbox::Factored::plus | ( | const Factors & | space, |
FactoredVector | retval, | ||
const BasisFunction & | rhs | ||
) |
FactoredVector AIToolbox::Factored::plus | ( | const Factors & | space, |
FactoredVector | retval, | ||
const FactoredVector & | rhs | ||
) |
FactoredMatrix2D& AIToolbox::Factored::plusEqual | ( | const Factors & | space, |
const Factors & | actions, | ||
FactoredMatrix2D & | retval, | ||
BasisMatrix && | basis | ||
) |
FactoredMatrix2D& AIToolbox::Factored::plusEqual | ( | const Factors & | space, |
const Factors & | actions, | ||
FactoredMatrix2D & | retval, | ||
const BasisMatrix & | basis | ||
) |
FactoredMatrix2D& AIToolbox::Factored::plusEqual | ( | const Factors & | space, |
const Factors & | actions, | ||
FactoredMatrix2D & | retval, | ||
const FactoredMatrix2D & | rhs | ||
) |
FactoredMatrix2D& AIToolbox::Factored::plusEqual | ( | const Factors & | space, |
const Factors & | actions, | ||
FactoredMatrix2D & | retval, | ||
FactoredMatrix2D && | rhs | ||
) |
FactoredVector& AIToolbox::Factored::plusEqual | ( | const Factors & | space, |
FactoredVector & | retval, | ||
BasisFunction && | basis | ||
) |
FactoredVector& AIToolbox::Factored::plusEqual | ( | const Factors & | space, |
FactoredVector & | retval, | ||
const BasisFunction & | basis | ||
) |
FactoredVector& AIToolbox::Factored::plusEqual | ( | const Factors & | space, |
FactoredVector & | retval, | ||
const FactoredVector & | rhs | ||
) |
FactoredVector& AIToolbox::Factored::plusEqual | ( | const Factors & | space, |
FactoredVector & | retval, | ||
FactoredVector && | rhs | ||
) |
BasisFunction& AIToolbox::Factored::plusEqualSubset | ( | const Factors & | space, |
BasisFunction & | retval, | ||
const BasisFunction & | rhs | ||
) |
BasisMatrix& AIToolbox::Factored::plusEqualSubset | ( | const Factors & | space, |
const Factors & | actions, | ||
BasisMatrix & | retval, | ||
const BasisMatrix & | rhs | ||
) |
BasisFunction AIToolbox::Factored::plusSubset | ( | const Factors & | space, |
BasisFunction | retval, | ||
const BasisFunction & | rhs | ||
) |
BasisMatrix AIToolbox::Factored::plusSubset | ( | const Factors & | space, |
const Factors & | actions, | ||
BasisMatrix | retval, | ||
const BasisMatrix & | rhs | ||
) |
PartialFactors AIToolbox::Factored::removeFactor | ( | const PartialFactors & | pf, |
size_t | f | ||
) |
This function removes the specified factor from the input PartialFactors.
pf | The PartialFactors to modify. |
f | The factor to be removed. |
This function converts an index into the equivalent Factors, within the specified factor space.
This function is the inverse of the toIndex(const Factors &, size_t) function.
The input id shall not cause the output to exceed the input space (i.e. the id will always be lower than factorSpace(space)).
space | The factor space to consider. |
id | The integer uniquely identifying the factor. |
This function converts an index into the equivalent Factors, within the specified factor space.
This function is equivalent to toFactors(const Factors & space, size_t id), but does its work on the input Factors.
Note: this function does NOT check for nullptr.
space | The factor space to consider. |
id | The integer uniquely identifying the factor. |
out | The id's equivalent Factors. |
Factors AIToolbox::Factored::toFactors | ( | size_t | F, |
const PartialFactors & | pf | ||
) |
This function converts PartialFactors into the equivalent Factors structure.
If the PartialFactors are incomplete, the non-specified elements will be unspecified in the returned value as well. The PartialFactors will not contain a factor higher than what passed as input.
F | The size of the Factors to be returned. |
pf | The PartialFactors to be converted. |
PartialValues AIToolbox::Factored::toFactorsPartial | ( | const PartialKeys & | ids, |
const Factors & | space, | ||
size_t | id | ||
) |
This function converts an index into the equivalent PartialValues of the input keys, within the specified factor space.
This function is the inverse of the toIndexPartial(const PartialKeys &, const Factors &, const Factors &) function, but only generates the PartialValues for the keys (rather than a full Factors).
The input id shall not cause the output to exceed the input space (i.e. the id will always be lower than factorSpacePartial(ids, space)).
ids | The indeces to consider. |
space | The global factors space to consider. |
id | The integer uniquely identifying the factor. |
void AIToolbox::Factored::toFactorsPartial | ( | It | begin, |
const PartialKeys & | ids, | ||
const Factors & | space, | ||
size_t | id | ||
) |
This function converts an index into the equivalent PartialValues of the input keys, within the specified factor space.
This functioh outputs to a range beginning at begin
, of the same size as the input ids
.
begin | The beginning of the range where to write the output. |
ids | The indeces to consider. |
space | The global factors space to consider. |
id | The integer uniquely identifying the factor. |
This function converts the input factor in the input space to an unique index.
This function returns an unique integer in range [0, factorSpace(space)).
The conversion guarantees that the output can be converted back to the same Factors via the toFactors functions, and that the relative ordering of the ids is the same as the one iterated by the PartialFactorsEnumerator.
In particular, iterating over factors is always done from the lowest id first. So for example in a space (2,3), the equivalency is:
(0,0) -> 0 (1,0) -> 1 (0,1) -> 2 (1,1) -> 3 (0,2) -> 4 (1,2) -> 5
This function does not perform bound checking. If the resulting number is too big to be representable via a size_t, the behavior is unspecified. This can happen only if factorSpace(space) exceeds the size of a size_t variable.
space | The factor space to consider. |
f | The input factor to convert. |
size_t AIToolbox::Factored::toIndex | ( | const Factors & | space, |
const PartialFactors & | f | ||
) |
This function converts the input factor in the input space to an unique index.
All unspecified values are considered 0.
space | The factor space to consider. |
f | The input factor to convert. |
size_t AIToolbox::Factored::toIndexPartial | ( | const Factors & | space, |
const PartialFactors & | f | ||
) |
This function converts the input factor in the input space to an unique index.
In this function only the ids mentioned in the PartialFactors are considered to be part of the space.
space | The factor space to consider. |
f | The input factor to convert. |
size_t AIToolbox::Factored::toIndexPartial | ( | const PartialKeys & | ids, |
const Factors & | space, | ||
const Factors & | f | ||
) |
This function converts the input factor in the input space to an unique index.
In this method ONLY the ids passed as input are considered. This function effectively considers only a subset of the input space and factor (which should still have the same length).
So if the ids are {1, 3}, the function will behave as if the factor space is two-dimensional, taking the values at ids 1 and 3 from the input space.
Then it will take the values at ids 1 and 3 from the input factor and use them to compute the equivalent number.
ids | The ids to consider in the input space and factor. |
space | The factor space to consider. |
f | The input factor to convert. |
size_t AIToolbox::Factored::toIndexPartial | ( | const PartialKeys & | ids, |
const Factors & | space, | ||
const PartialFactors & | pf | ||
) |
This function converts the input factor in the input space to an unique index.
In this method ONLY the ids passed as input are considered. This function effectively considers only a subset of the input space and partial factor. The partial factor MUST contain the ids passed as input!
So if the ids are {1, 3}, the function will behave as if the factor space is two-dimensional, taking the values at ids 1 and 3 from the input space.
Then it will take the values at keys 1 and 3 from the input partial factor and use them to compute the equivalent number.
ids | The ids to consider in the input space and factor. |
space | The factor space to consider. |
pf | The input factor to convert. |
std::pair<size_t, size_t> AIToolbox::Factored::toIndexPartialAndSkip | ( | const PartialKeys & | ids, |
const Factors & | space, | ||
const Factors & | f, | ||
size_t | id | ||
) |
This function avoids computing indeces multiple times if only a single index is changing.
If you need to compute a sequence of indeces given that you are iterating over the values of a single key id (and keeping all the rest identical), you can use this function.
It returns the first valid index (the one where the input key id would have value 0, and all the rest of the input value is the same), and a skip value to find all the subsequent ones.
For example, suppose you have a space of
This function would output 19, 2.
19 is the index of { 1, 0, 3 }, which is the first value that matches the input f.
Then, skipping by 2, we'd have { 1, 1, 3 } and { 1, 2, 3 }. Note you have to only repeat the process space[id] times to avoid going out of bounds.
This is faster than calling toIndexPartial multiple times since we only go over the inputs once to do the multiplication, and the subsequent iteration is simply summing the skip value to the first index.
ids | The ids to consider in the input space and factor. |
space | The factor space to consider. |
f | The input factor to convert. |
id | The single id we are interested in iterating over. |
PartialFactors AIToolbox::Factored::toPartialFactors | ( | const Factors & | f | ) |
This function converts Factors into the equivalent PartialFactors structure.
f | The Factors to be converted. |
void AIToolbox::Factored::unsafe_join | ( | PartialFactors * | lhs, |
const PartialFactors & | rhs | ||
) |
This function appends the rhs to the lhs.
This function may produce a non-valid PartialFactors. This is useful in case multiple joins must be done in successions, so that the process is more efficient.
Remember to call sort() at the end to make the output valid again.
lhs | The left hand side that gets extended in place. |
rhs | The right hand side. |