AIToolbox
A library that offers tools for AI problem solving.
AIToolbox::Factored::GenericVariableElimination< Factor > Class Template Reference

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...
 

Detailed Description

template<typename Factor>
class AIToolbox::Factored::GenericVariableElimination< Factor >

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:

  • A member 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.
  • A member void crossSum(const Factor &) function, which should perform the cross-sum of the input into the newFactor member variable.
  • A member 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:

  • A member 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.
  • A member void initNewFactor() method, which is called when the newFactor variable needs to be initialized.
  • A member 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.
  • A member void beginFactorCrossSum() method, which is called at the beginning of each set of cross-sum operations with a given factor.
  • A member void endFactorCrossSum() method, which is called at the end of each set of cross-sum operations with a given factor.
  • A member void endCrossSum() method, which is called at the end of each set of cross-sum operations.
  • A member bool isValidNewFactor() method, which returns whether the newFactor variable can be used after all cross-sum operations.
  • A member 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.

Template Parameters
FactorThe Factor type to use.

Member Typedef Documentation

◆ FinalFactors

template<typename Factor >
using AIToolbox::Factored::GenericVariableElimination< Factor >::FinalFactors = std::vector<Factor>

◆ Graph

template<typename Factor >
using AIToolbox::Factored::GenericVariableElimination< Factor >::Graph = FactorGraph<Rules>

◆ Rule

template<typename Factor >
using AIToolbox::Factored::GenericVariableElimination< Factor >::Rule = std::pair<size_t, Factor>

◆ Rules

template<typename Factor >
using AIToolbox::Factored::GenericVariableElimination< Factor >::Rules = std::vector<Rule>

Member Function Documentation

◆ operator()()

template<typename Factor >
template<typename Global >
void AIToolbox::Factored::GenericVariableElimination< Factor >::operator() ( const Factors V,
Graph graph,
Global &  global 
)

This operator performs the Variable Elimination operation on the inputs.

Parameters
VThe space of all variables to eliminate.
graphThe already populated graph to perform VE onto.
globalThe global callback structure.

The documentation for this class was generated from the following file: