AIToolbox
A library that offers tools for AI problem solving.
|
This class represents the Variable Elimination algorithm. More...
#include <AIToolbox/Factored/Utils/GenericVariableElimination.hpp>
Public Types | |
using | Rule = std::pair< size_t, Factor > |
using | Rules = std::vector< Rule > |
using | Graph = FactorGraph< Rules > |
using | FinalFactors = std::vector< Factor > |
Public Member Functions | |
template<typename Global > | |
void | operator() (const Factors &V, Graph &graph, Global &global) |
This operator performs the Variable Elimination operation on the inputs. More... | |
This class represents the Variable Elimination algorithm.
This class applies Variable Elimination to an input FactorGraph<Factor>.
Since the cross-sum steps in the algorithm differ depending on the type of node in the graph, we require as input a separate structure which may contain certain methods depending on what the use-case requires, and which holds any needed temporaries to store for the duration of the algorithm.
In particular, this structure (the global
parameter), MUST provide:
Factor newFactor
which stores the results of the cross-sum of each removed variable. At each iteration over the values of that variable's neighbors, we move from it, so be sure to re-initialize it if needed.void crossSum(const Factor &)
function, which should perform the cross-sum of the input into the newFactor
member variable.void makeResult(std::vector<Factor> &&)
method, which should process the final factors of the VE process in order to create your result.Since VE usually requires custom computations, you can OPTIONALLY define the following methods:
void beginRemoval(const Graph &, const Graph::FactorItList &, const Graph::Variable &, size_t)
method, which is called at the beginning of the removal of each variable.void initNewFactor()
method, which is called when the newFactor
variable needs to be initialized.void beginCrossSum(size_t)
method, which is called at the beginning of each set of cross-sum operations with the current value of the variable being eliminated.void beginFactorCrossSum()
method, which is called at the beginning of each set of cross-sum operations with a given factor.void endFactorCrossSum()
method, which is called at the end of each set of cross-sum operations with a given factor.void endCrossSum()
method, which is called at the end of each set of cross-sum operations.bool isValidNewFactor()
method, which returns whether the newFactor
variable can be used after all cross-sum operations.void mergeFactors(Factor &, Factor &&)
function, which should merge the rhs into the lhs. If not specified a new Rule is appended to the Rules rather than merged. If this function is specified the input graph must have sorted Rules!!All these functions can optionally be const
; nothing changes. In addition, for the 'beginRemoval' and 'beginCrossSum' functions, all parameters are optional: you can define only the ones you want (as long as they are in the same order as specified here), and we will call them correctly.
The class will fail to compile if you provide a method with the required name but with the wrong signature, as we would just skip it silently otherwise.
Factor | The Factor type to use. |
using AIToolbox::Factored::GenericVariableElimination< Factor >::FinalFactors = std::vector<Factor> |
using AIToolbox::Factored::GenericVariableElimination< Factor >::Graph = FactorGraph<Rules> |
using AIToolbox::Factored::GenericVariableElimination< Factor >::Rule = std::pair<size_t, Factor> |
using AIToolbox::Factored::GenericVariableElimination< Factor >::Rules = std::vector<Rule> |
void AIToolbox::Factored::GenericVariableElimination< Factor >::operator() | ( | const Factors & | V, |
Graph & | graph, | ||
Global & | global | ||
) |
This operator performs the Variable Elimination operation on the inputs.
V | The space of all variables to eliminate. |
graph | The already populated graph to perform VE onto. |
global | The global callback structure. |