aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
gum::MultiDimCombinationDefault< GUM_SCALAR, TABLE > Class Template Reference

A class to combine efficiently several MultiDim tablesMultiDimCombinationDefault is a class designed to combine efficiently several multidimensional objects, that is, to compute expressions like T1 op T2 op T3 op .... More...

#include <agrum/tools/multidim/operators/multiDimCombinationDefault.h>

+ Inheritance diagram for gum::MultiDimCombinationDefault< GUM_SCALAR, TABLE >:
+ Collaboration diagram for gum::MultiDimCombinationDefault< GUM_SCALAR, TABLE >:

Public Member Functions

Constructors / Destructors
 MultiDimCombinationDefault (TABLE< GUM_SCALAR > *(*combine)(const TABLE< GUM_SCALAR > &, const TABLE< GUM_SCALAR > &))
 Default constructor. More...
 
 MultiDimCombinationDefault (const MultiDimCombinationDefault< GUM_SCALAR, TABLE > &)
 Copy constructor. More...
 
virtual ~MultiDimCombinationDefault ()
 Destructor. More...
 
virtual MultiDimCombinationDefault< GUM_SCALAR, TABLE > * newFactory () const
 virtual constructor More...
 
Accessors/Modifiers
virtual TABLE< GUM_SCALAR > * combine (const Set< const TABLE< GUM_SCALAR > * > &set)
 Creates and returns the result of the combination of the tables within set. More...
 
virtual void combine (TABLE< GUM_SCALAR > &container, const Set< const TABLE< GUM_SCALAR > * > &set)
 Creates and returns the result of the combination of the tables within set. More...
 
virtual void setCombineFunction (TABLE< GUM_SCALAR > *(*combine)(const TABLE< GUM_SCALAR > &, const TABLE< GUM_SCALAR > &))
 Changes the function used for combining two TABLES. More...
 
virtual TABLE< GUM_SCALAR > *(*)(const TABLE< GUM_SCALAR > &, const TABLE< GUM_SCALAR > &) combineFunction ()
 Returns the combination function currently used by the combinator. More...
 
virtual float nbOperations (const Set< const TABLE< GUM_SCALAR > * > &set) const
 returns a rough estimate of the number of operations that will be performed to compute the combination. More...
 
virtual float nbOperations (const Set< const Sequence< const DiscreteVariable * > * > &set) const
 Creates and returns the result of the combination of the tables within set. More...
 
virtual std::pair< long, long > memoryUsage (const Set< const TABLE< GUM_SCALAR > * > &set) const
 Returns the additional memory consumption used during the combination. More...
 
virtual std::pair< long, long > memoryUsage (const Set< const Sequence< const DiscreteVariable * > * > &set) const
 Creates and returns the result of the combination of the tables within set. More...
 

Protected Attributes

TABLE< GUM_SCALAR > *(* combine_ )(const TABLE< GUM_SCALAR > &t1, const TABLE< GUM_SCALAR > &t2)
 The function used to combine two tables. More...
 

Protected Member Functions

Size combinedSize_ (const Sequence< const DiscreteVariable * > &seq1, const Sequence< const DiscreteVariable * > &seq2) const
 returns the domain size of the Cartesian product of the union of all the variables in seq1 and seq2. More...
 

Detailed Description

template<typename GUM_SCALAR, template< typename > class TABLE>
class gum::MultiDimCombinationDefault< GUM_SCALAR, TABLE >

A class to combine efficiently several MultiDim tables

MultiDimCombinationDefault is a class designed to combine efficiently several multidimensional objects, that is, to compute expressions like T1 op T2 op T3 op ....

op Tn, where the Ti's are the multidimensional objects and op is an operator or a function taking in argument two such objects and producing a new (combined) Ti object. Note that the MultiDimCombinationDefault determines itself in which order the objects should be combined. As such, the combination operation to perform should thus be COMMUTATIVE and ASSOCIATIVE.

By multidimensional objects, we mean of course MultiDimImplementations, but also more complex objects such as, for instance, pairs of MultiDimImplementations the first one of which being a utility function and the second one being a table of instantiations (useful, e.g., for computing MPE's) but this can also be a pair (Utility,Potential) for the inference in an Influence Diagram. Actually, the important point for a multidimensional object to be eligible to be combined by the MultiDimCombinationDefault is:

that the object contains a method variablesSequence that returns a

sequence of Discrete variables that represent the dimensions of the multidimensional object

that there exists a function taking in arguments two such

multidimensional objects and producing a new object of the same type, which is the so-called combined result of these two objects.

To be quite generic, the MultiDimCombinationDefault takes in argument the function that produces the result of the combination of two multidimensional objects. The following code gives an example of the usage of MultiDimCombinations:

// a function used to combine two Potential<float>'s:
Potential<float>* addPotential ( const Potential<float>& t1,
const Potential<float>& t2 ) {
return new Potential<float> (t1 + t2);
}
// another function used to combine two Potential<float>'s:
Potential<float>* multPotential ( const Potential<float>& t1,
const Potential<float>& t2 ) {
return new Potential<float> (t1 * t2);
}
Potential<float> t1, t2, t3;
Set<const Potential<float>*> set;
set << &table1 << &table2 << &table3;
MultiDimCombinationDefault<float,Potential> Comb ( addPotential );
Potential<float>* combined_table = Comb.combine ( set );
// change the operator to apply
Comb.setCombineFunction ( multPotential );
Potential<float>* combined_table2 = Comb.combine ( set );

Definition at line 101 of file multiDimCombinationDefault.h.

Constructor & Destructor Documentation

◆ MultiDimCombinationDefault() [1/2]

template<typename GUM_SCALAR , template< typename > class TABLE>
gum::MultiDimCombinationDefault< GUM_SCALAR, TABLE >::MultiDimCombinationDefault ( TABLE< GUM_SCALAR > *(*)(const TABLE< GUM_SCALAR > &, const TABLE< GUM_SCALAR > &)  combine)

Default constructor.

Parameters
combinea function that takes two tables in input and produces a new table which is the result of the combination of the two tables passed in argument.

◆ MultiDimCombinationDefault() [2/2]

template<typename GUM_SCALAR , template< typename > class TABLE>
gum::MultiDimCombinationDefault< GUM_SCALAR, TABLE >::MultiDimCombinationDefault ( const MultiDimCombinationDefault< GUM_SCALAR, TABLE > &  )

Copy constructor.

◆ ~MultiDimCombinationDefault()

template<typename GUM_SCALAR , template< typename > class TABLE>
virtual gum::MultiDimCombinationDefault< GUM_SCALAR, TABLE >::~MultiDimCombinationDefault ( )
virtual

Destructor.

Member Function Documentation

◆ combine() [1/2]

template<typename GUM_SCALAR , template< typename > class TABLE>
virtual TABLE< GUM_SCALAR >* gum::MultiDimCombinationDefault< GUM_SCALAR, TABLE >::combine ( const Set< const TABLE< GUM_SCALAR > * > &  set)
virtual

Creates and returns the result of the combination of the tables within set.

Returns
a new freshly created TABLE which is the result of the combination of all the TABLES passed in argument
Exceptions
InvalidArgumentsNumberexception is thrown if the set passed in argument contains less than two elements.

Implements gum::MultiDimCombination< GUM_SCALAR, TABLE >.

◆ combine() [2/2]

template<typename GUM_SCALAR , template< typename > class TABLE>
virtual void gum::MultiDimCombinationDefault< GUM_SCALAR, TABLE >::combine ( TABLE< GUM_SCALAR > &  container,
const Set< const TABLE< GUM_SCALAR > * > &  set 
)
virtual

Creates and returns the result of the combination of the tables within set.

Returns
a new freshly created TABLE which is the result of the combination of all the TABLES passed in argument
Exceptions
InvalidArgumentsNumberexception is thrown if the set passed in argument contains less than two elements.

Implements gum::MultiDimCombination< GUM_SCALAR, TABLE >.

◆ combinedSize_()

template<typename GUM_SCALAR , template< typename > class TABLE>
Size gum::MultiDimCombinationDefault< GUM_SCALAR, TABLE >::combinedSize_ ( const Sequence< const DiscreteVariable * > &  seq1,
const Sequence< const DiscreteVariable * > &  seq2 
) const
protected

returns the domain size of the Cartesian product of the union of all the variables in seq1 and seq2.

◆ combineFunction()

template<typename GUM_SCALAR , template< typename > class TABLE>
virtual TABLE< GUM_SCALAR >*(*)(const TABLE< GUM_SCALAR >&, const TABLE< GUM_SCALAR >&) gum::MultiDimCombinationDefault< GUM_SCALAR, TABLE >::combineFunction ( )
virtual

Returns the combination function currently used by the combinator.

Reimplemented from gum::MultiDimCombination< GUM_SCALAR, TABLE >.

◆ memoryUsage() [1/2]

template<typename GUM_SCALAR , template< typename > class TABLE>
virtual std::pair< long, long > gum::MultiDimCombinationDefault< GUM_SCALAR, TABLE >::memoryUsage ( const Set< const TABLE< GUM_SCALAR > * > &  set) const
virtual

Returns the additional memory consumption used during the combination.

Actually, this function does not return a precise account of the memory used by the multidimCombination but a rough estimate based on the sizes of the tables involved in the combination.

Returns
a pair of memory consumption: the first one is the maximum amount of memory used during the combination and the second one is the amount of memory still used at the end of the function ( the memory used by the resulting table ).

Implements gum::MultiDimCombination< GUM_SCALAR, TABLE >.

◆ memoryUsage() [2/2]

template<typename GUM_SCALAR , template< typename > class TABLE>
virtual std::pair< long, long > gum::MultiDimCombinationDefault< GUM_SCALAR, TABLE >::memoryUsage ( const Set< const Sequence< const DiscreteVariable * > * > &  set) const
virtual

Creates and returns the result of the combination of the tables within set.

Returns
a new freshly created TABLE which is the result of the combination of all the TABLES passed in argument
Exceptions
InvalidArgumentsNumberexception is thrown if the set passed in argument contains less than two elements.

Implements gum::MultiDimCombination< GUM_SCALAR, TABLE >.

◆ nbOperations() [1/2]

template<typename GUM_SCALAR , template< typename > class TABLE>
virtual float gum::MultiDimCombinationDefault< GUM_SCALAR, TABLE >::nbOperations ( const Set< const TABLE< GUM_SCALAR > * > &  set) const
virtual

returns a rough estimate of the number of operations that will be performed to compute the combination.

Implements gum::MultiDimCombination< GUM_SCALAR, TABLE >.

◆ nbOperations() [2/2]

template<typename GUM_SCALAR , template< typename > class TABLE>
virtual float gum::MultiDimCombinationDefault< GUM_SCALAR, TABLE >::nbOperations ( const Set< const Sequence< const DiscreteVariable * > * > &  set) const
virtual

Creates and returns the result of the combination of the tables within set.

Returns
a new freshly created TABLE which is the result of the combination of all the TABLES passed in argument
Exceptions
InvalidArgumentsNumberexception is thrown if the set passed in argument contains less than two elements.

Implements gum::MultiDimCombination< GUM_SCALAR, TABLE >.

◆ newFactory()

template<typename GUM_SCALAR , template< typename > class TABLE>
virtual MultiDimCombinationDefault< GUM_SCALAR, TABLE >* gum::MultiDimCombinationDefault< GUM_SCALAR, TABLE >::newFactory ( ) const
virtual

virtual constructor

Returns
A new fresh MultiDimCombinator with the same combination function.

Implements gum::MultiDimCombination< GUM_SCALAR, TABLE >.

◆ setCombineFunction()

template<typename GUM_SCALAR , template< typename > class TABLE>
virtual void gum::MultiDimCombinationDefault< GUM_SCALAR, TABLE >::setCombineFunction ( TABLE< GUM_SCALAR > *(*)(const TABLE< GUM_SCALAR > &, const TABLE< GUM_SCALAR > &)  combine)
virtual

Changes the function used for combining two TABLES.

Implements gum::MultiDimCombination< GUM_SCALAR, TABLE >.

Member Data Documentation

◆ combine_

template<typename GUM_SCALAR , template< typename > class TABLE>
TABLE< GUM_SCALAR >*(* gum::MultiDimCombinationDefault< GUM_SCALAR, TABLE >::combine_) (const TABLE< GUM_SCALAR > &t1, const TABLE< GUM_SCALAR > &t2)
protected

The function used to combine two tables.

Definition at line 186 of file multiDimCombinationDefault.h.


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