aGrUM  0.16.0
gum::TreeOperatorStrategy< GUM_SCALAR > Class Template Reference

<agrum/FMDP/planning/treeOperatorStrategy.h> More...

#include <treeOperatorStrategy.h>

+ Inheritance diagram for gum::TreeOperatorStrategy< GUM_SCALAR >:
+ Collaboration diagram for gum::TreeOperatorStrategy< GUM_SCALAR >:

Public Member Functions

Constructor & destructor.
 TreeOperatorStrategy ()
 Default constructor. More...
 
 ~TreeOperatorStrategy ()
 Default destructor. More...
 
MultiDimFunctionGraph< GUM_SCALAR, ExactTerminalNodePolicy > * getFunctionInstance ()
 
MultiDimFunctionGraph< ArgMaxSet< GUM_SCALAR, Idx >, SetTerminalNodePolicy > * getArgMaxFunctionInstance ()
 
MultiDimFunctionGraph< ActionSet, SetTerminalNodePolicy > * getAggregatorInstance ()
 

Protected Member Functions

INLINE void _deleteFunctionGraph (const MultiDimFunctionGraph< GUM_SCALAR > *f1, const MultiDimFunctionGraph< GUM_SCALAR > *f2, Idx del)
 
INLINE void _deleteFunctionGraph (const MultiDimFunctionGraph< ArgMaxSet< GUM_SCALAR, Idx >, SetTerminalNodePolicy > *f1, const MultiDimFunctionGraph< ArgMaxSet< GUM_SCALAR, Idx >, SetTerminalNodePolicy > *f2, Idx del)
 
Graph Function Operations Methods
MultiDimFunctionGraph< GUM_SCALAR > * regress (const MultiDimFunctionGraph< GUM_SCALAR > *Vold, Idx actionId, const FMDP< GUM_SCALAR > *fmdp, const Set< const DiscreteVariable * > &elVarSeq)
 Computes Qaction for given actionid. More...
 
virtual MultiDimFunctionGraph< GUM_SCALAR > * maximize (const MultiDimFunctionGraph< GUM_SCALAR > *f1, const MultiDimFunctionGraph< GUM_SCALAR > *f2, Idx del=3)
 
virtual MultiDimFunctionGraph< GUM_SCALAR > * minimize (const MultiDimFunctionGraph< GUM_SCALAR > *f1, const MultiDimFunctionGraph< GUM_SCALAR > *f2, Idx del=3)
 
virtual MultiDimFunctionGraph< GUM_SCALAR > * multiply (const MultiDimFunctionGraph< GUM_SCALAR > *f1, const MultiDimFunctionGraph< GUM_SCALAR > *f2, Idx del=3)
 
virtual MultiDimFunctionGraph< ArgMaxSet< GUM_SCALAR, Idx >, SetTerminalNodePolicy > * argmaximize (const MultiDimFunctionGraph< ArgMaxSet< GUM_SCALAR, Idx >, SetTerminalNodePolicy > *f1, const MultiDimFunctionGraph< ArgMaxSet< GUM_SCALAR, Idx >, SetTerminalNodePolicy > *f2, Idx del=3)
 ArgMaximizes between f2 and f1. More...
 
virtual MultiDimFunctionGraph< GUM_SCALAR > * add (const MultiDimFunctionGraph< GUM_SCALAR > *f1, const MultiDimFunctionGraph< GUM_SCALAR > *f2, Idx del=1)
 Adds reward to given function( whether a f2 or f1) More...
 
virtual MultiDimFunctionGraph< GUM_SCALAR > * subtract (const MultiDimFunctionGraph< GUM_SCALAR > *f1, const MultiDimFunctionGraph< GUM_SCALAR > *f2, Idx del=0)
 Subtract current f1 from old f1 to see if threshold is reached or not. More...
 

Detailed Description

template<typename GUM_SCALAR>
class gum::TreeOperatorStrategy< GUM_SCALAR >

<agrum/FMDP/planning/treeOperatorStrategy.h>

A class to find optimal policy for a given FMDP.

Perform a TreeOperatorStrategy planning on given in parameter factored markov decision process

Definition at line 50 of file treeOperatorStrategy.h.

Constructor & Destructor Documentation

◆ TreeOperatorStrategy()

template<typename GUM_SCALAR >
INLINE gum::TreeOperatorStrategy< GUM_SCALAR >::TreeOperatorStrategy ( )

Default constructor.

Definition at line 63 of file treeOperatorStrategy_tpl.h.

63  {
64  GUM_CONSTRUCTOR(TreeOperatorStrategy);
65  }
TreeOperatorStrategy()
Default constructor.

◆ ~TreeOperatorStrategy()

template<typename GUM_SCALAR >
INLINE gum::TreeOperatorStrategy< GUM_SCALAR >::~TreeOperatorStrategy ( )

Default destructor.

Definition at line 71 of file treeOperatorStrategy_tpl.h.

71  {
72  GUM_DESTRUCTOR(TreeOperatorStrategy);
73  }
TreeOperatorStrategy()
Default constructor.

Member Function Documentation

◆ _deleteFunctionGraph() [1/2]

template<typename GUM_SCALAR>
INLINE void gum::IOperatorStrategy< GUM_SCALAR >::_deleteFunctionGraph ( const MultiDimFunctionGraph< GUM_SCALAR > *  f1,
const MultiDimFunctionGraph< GUM_SCALAR > *  f2,
Idx  del 
)
inlineprotectedinherited

Definition at line 154 of file IOperatorStrategy.h.

156  {
157  if (del == 1 || del == 3) delete f1;
158  if (del >= 2) delete f2;
159  }

◆ _deleteFunctionGraph() [2/2]

template<typename GUM_SCALAR>
INLINE void gum::IOperatorStrategy< GUM_SCALAR >::_deleteFunctionGraph ( const MultiDimFunctionGraph< ArgMaxSet< GUM_SCALAR, Idx >, SetTerminalNodePolicy > *  f1,
const MultiDimFunctionGraph< ArgMaxSet< GUM_SCALAR, Idx >, SetTerminalNodePolicy > *  f2,
Idx  del 
)
inlineprotectedinherited

Definition at line 161 of file IOperatorStrategy.h.

166  {
167  if (del == 1 || del == 3) delete f1;
168  if (del >= 2) delete f2;
169  }

◆ add()

template<typename GUM_SCALAR >
MultiDimFunctionGraph< GUM_SCALAR > * gum::TreeOperatorStrategy< GUM_SCALAR >::add ( const MultiDimFunctionGraph< GUM_SCALAR > *  f1,
const MultiDimFunctionGraph< GUM_SCALAR > *  f2,
Idx  del = 1 
)
protectedvirtual

Adds reward to given function( whether a f2 or f1)

Warning
given function is deleted, returns the new one
Parameters
reward: R(s) or R(s,a)
function: either V(s) or Q(s,a)
Warning
given function is deleted, returns the new one

Implements gum::IOperatorStrategy< GUM_SCALAR >.

Definition at line 193 of file treeOperatorStrategy_tpl.h.

References gum::TreeOperator< GUM_SCALAR, COMBINEOPERATOR, TerminalNodePolicy >::compute().

Referenced by gum::TreeOperatorStrategy< GUM_SCALAR >::getAggregatorInstance().

196  {
197  TreeOperator< GUM_SCALAR, std::plus > opi(f1, f2);
198  MultiDimFunctionGraph< GUM_SCALAR >* ret = opi.compute();
199  this->_deleteFunctionGraph(f1, f2, del);
200  return ret;
201  }
INLINE void _deleteFunctionGraph(const MultiDimFunctionGraph< GUM_SCALAR > *f1, const MultiDimFunctionGraph< GUM_SCALAR > *f2, Idx del)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ argmaximize()

template<typename GUM_SCALAR >
MultiDimFunctionGraph< ArgMaxSet< GUM_SCALAR, Idx >, SetTerminalNodePolicy > * gum::TreeOperatorStrategy< GUM_SCALAR >::argmaximize ( const MultiDimFunctionGraph< ArgMaxSet< GUM_SCALAR, Idx >, SetTerminalNodePolicy > *  f1,
const MultiDimFunctionGraph< ArgMaxSet< GUM_SCALAR, Idx >, SetTerminalNodePolicy > *  f2,
Idx  del = 3 
)
protectedvirtual

ArgMaximizes between f2 and f1.

Warning
given vFunction and qAction are deleted, returns the new one
given f1 and f2 are deleted, returns the new one

Implements gum::IOperatorStrategy< GUM_SCALAR >.

Definition at line 170 of file treeOperatorStrategy_tpl.h.

References gum::TreeOperator< GUM_SCALAR, COMBINEOPERATOR, TerminalNodePolicy >::compute().

Referenced by gum::TreeOperatorStrategy< GUM_SCALAR >::getAggregatorInstance().

175  {
176  TreeOperator< ArgMaxSet< GUM_SCALAR, Idx >,
177  ArgumentMaximisesAction,
178  SetTerminalNodePolicy >
179  argmaxope(f1, f2);
180  MultiDimFunctionGraph< ArgMaxSet< GUM_SCALAR, Idx >, SetTerminalNodePolicy >*
181  ret = argmaxope.compute();
182  this->_deleteFunctionGraph(f1, f2, del);
183  return ret;
184  }
INLINE void _deleteFunctionGraph(const MultiDimFunctionGraph< GUM_SCALAR > *f1, const MultiDimFunctionGraph< GUM_SCALAR > *f2, Idx del)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAggregatorInstance()

template<typename GUM_SCALAR >
MultiDimFunctionGraph< ActionSet, SetTerminalNodePolicy >* gum::TreeOperatorStrategy< GUM_SCALAR >::getAggregatorInstance ( )
inlinevirtual

Implements gum::IOperatorStrategy< GUM_SCALAR >.

Definition at line 84 of file treeOperatorStrategy.h.

References gum::TreeOperatorStrategy< GUM_SCALAR >::add(), gum::TreeOperatorStrategy< GUM_SCALAR >::argmaximize(), gum::TreeOperatorStrategy< GUM_SCALAR >::maximize(), gum::TreeOperatorStrategy< GUM_SCALAR >::minimize(), gum::TreeOperatorStrategy< GUM_SCALAR >::multiply(), gum::TreeOperatorStrategy< GUM_SCALAR >::regress(), and gum::TreeOperatorStrategy< GUM_SCALAR >::subtract().

84  {
85  return MultiDimFunctionGraph< ActionSet,
86  SetTerminalNodePolicy >::getTreeInstance();
87  }
+ Here is the call graph for this function:

◆ getArgMaxFunctionInstance()

template<typename GUM_SCALAR >
MultiDimFunctionGraph< ArgMaxSet< GUM_SCALAR, Idx >, SetTerminalNodePolicy >* gum::TreeOperatorStrategy< GUM_SCALAR >::getArgMaxFunctionInstance ( )
inlinevirtual

Implements gum::IOperatorStrategy< GUM_SCALAR >.

Definition at line 79 of file treeOperatorStrategy.h.

79  {
80  return MultiDimFunctionGraph< ArgMaxSet< GUM_SCALAR, Idx >,
81  SetTerminalNodePolicy >::getTreeInstance();
82  }

◆ getFunctionInstance()

template<typename GUM_SCALAR >
MultiDimFunctionGraph< GUM_SCALAR, ExactTerminalNodePolicy >* gum::TreeOperatorStrategy< GUM_SCALAR >::getFunctionInstance ( )
inlinevirtual

Implements gum::IOperatorStrategy< GUM_SCALAR >.

Definition at line 75 of file treeOperatorStrategy.h.

References gum::MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >::getTreeInstance().

75  {
77  }
static MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * getTreeInstance()
Returns an arborescent instance.
+ Here is the call graph for this function:

◆ maximize()

template<typename GUM_SCALAR >
MultiDimFunctionGraph< GUM_SCALAR > * gum::TreeOperatorStrategy< GUM_SCALAR >::maximize ( const MultiDimFunctionGraph< GUM_SCALAR > *  f1,
const MultiDimFunctionGraph< GUM_SCALAR > *  f2,
Idx  del = 3 
)
protectedvirtual
Warning
given vFunction and qAction are deleted, returns the new one
given f1 and f2 are deleted, returns the new one

Implements gum::IOperatorStrategy< GUM_SCALAR >.

Definition at line 124 of file treeOperatorStrategy_tpl.h.

References gum::TreeOperator< GUM_SCALAR, COMBINEOPERATOR, TerminalNodePolicy >::compute().

Referenced by gum::TreeOperatorStrategy< GUM_SCALAR >::getAggregatorInstance().

127  {
128  TreeOperator< GUM_SCALAR, Maximizes > opi(f1, f2);
129  MultiDimFunctionGraph< GUM_SCALAR >* ret = opi.compute();
130  this->_deleteFunctionGraph(f1, f2, del);
131  return ret;
132  }
INLINE void _deleteFunctionGraph(const MultiDimFunctionGraph< GUM_SCALAR > *f1, const MultiDimFunctionGraph< GUM_SCALAR > *f2, Idx del)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ minimize()

template<typename GUM_SCALAR >
MultiDimFunctionGraph< GUM_SCALAR > * gum::TreeOperatorStrategy< GUM_SCALAR >::minimize ( const MultiDimFunctionGraph< GUM_SCALAR > *  f1,
const MultiDimFunctionGraph< GUM_SCALAR > *  f2,
Idx  del = 3 
)
protectedvirtual
Warning
Minimze the two given functions
given f1 and f2 are deleted, returns the new one

Implements gum::IOperatorStrategy< GUM_SCALAR >.

Definition at line 139 of file treeOperatorStrategy_tpl.h.

References gum::TreeOperator< GUM_SCALAR, COMBINEOPERATOR, TerminalNodePolicy >::compute().

Referenced by gum::TreeOperatorStrategy< GUM_SCALAR >::getAggregatorInstance().

142  {
143  TreeOperator< GUM_SCALAR, Minimizes > opi(f1, f2);
144  MultiDimFunctionGraph< GUM_SCALAR >* ret = opi.compute();
145  this->_deleteFunctionGraph(f1, f2, del);
146  return ret;
147  }
INLINE void _deleteFunctionGraph(const MultiDimFunctionGraph< GUM_SCALAR > *f1, const MultiDimFunctionGraph< GUM_SCALAR > *f2, Idx del)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ multiply()

template<typename GUM_SCALAR >
MultiDimFunctionGraph< GUM_SCALAR > * gum::TreeOperatorStrategy< GUM_SCALAR >::multiply ( const MultiDimFunctionGraph< GUM_SCALAR > *  f1,
const MultiDimFunctionGraph< GUM_SCALAR > *  f2,
Idx  del = 3 
)
protectedvirtual
Warning
given f1 and f2 are deleted, returns the new one

Implements gum::IOperatorStrategy< GUM_SCALAR >.

Definition at line 153 of file treeOperatorStrategy_tpl.h.

References gum::TreeOperator< GUM_SCALAR, COMBINEOPERATOR, TerminalNodePolicy >::compute().

Referenced by gum::TreeOperatorStrategy< GUM_SCALAR >::getAggregatorInstance().

156  {
157  TreeOperator< GUM_SCALAR, std::multiplies > opi(f1, f2);
158  MultiDimFunctionGraph< GUM_SCALAR >* ret = opi.compute();
159  this->_deleteFunctionGraph(f1, f2, del);
160  return ret;
161  }
INLINE void _deleteFunctionGraph(const MultiDimFunctionGraph< GUM_SCALAR > *f1, const MultiDimFunctionGraph< GUM_SCALAR > *f2, Idx del)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ regress()

template<typename GUM_SCALAR >
MultiDimFunctionGraph< GUM_SCALAR > * gum::TreeOperatorStrategy< GUM_SCALAR >::regress ( const MultiDimFunctionGraph< GUM_SCALAR > *  Vold,
Idx  actionId,
const FMDP< GUM_SCALAR > *  fmdp,
const Set< const DiscreteVariable * > &  elVarSeq 
)
protectedvirtual

Computes Qaction for given actionid.

Performs a multiplication/projection on given qAction.

Returns
qAction : the computed Q(s,a)
Parameters
qAction: the computed Q(s,a)
pxip: the transition probabilities for the xip variable
xip: the variable we eliminate on the projection
Warning
given qAction is deleted, return the new one

Implements gum::IOperatorStrategy< GUM_SCALAR >.

Definition at line 93 of file treeOperatorStrategy_tpl.h.

References gum::TreeRegress< GUM_SCALAR, COMBINEOPERATOR, PROJECTOPERATOR, TerminalNodePolicy >::compute(), gum::FMDP< GUM_SCALAR >::mapMainPrime(), RECAST, gum::FMDP< GUM_SCALAR >::transition(), and gum::MultiDimImplementation< GUM_SCALAR >::variablesSequence().

Referenced by gum::TreeOperatorStrategy< GUM_SCALAR >::getAggregatorInstance().

97  {
98  // ******************************************************************************
99  // Initialisation :
100  // Creating a copy of last Vfunction to deduce from the new Qaction
101  // And finding the first var to eleminate (the one at the end)
102  Bijection< const DiscreteVariable*,
104  pxi;
105  for (SequenceIteratorSafe< const DiscreteVariable* > varIter =
106  Vold->variablesSequence().beginSafe();
107  varIter != Vold->variablesSequence().endSafe();
108  ++varIter) {
109  pxi.insert(
110  *varIter,
111  RECAST(fmdp->transition(actionId, fmdp->mapMainPrime().first(*varIter))));
112  }
113 
114  TreeRegress< GUM_SCALAR, std::multiplies, std::plus > tr(
115  Vold, pxi); //, Vold->variablesSequence(), (GUM_SCALAR) 0.0 );
116  return tr.compute();
117  }
virtual const Sequence< const DiscreteVariable *> & variablesSequence() const override
Returns a const ref to the sequence of DiscreteVariable*.
#define RECAST(x)
For shorter line and hence more comprehensive code only.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ subtract()

template<typename GUM_SCALAR >
MultiDimFunctionGraph< GUM_SCALAR > * gum::TreeOperatorStrategy< GUM_SCALAR >::subtract ( const MultiDimFunctionGraph< GUM_SCALAR > *  f1,
const MultiDimFunctionGraph< GUM_SCALAR > *  f2,
Idx  del = 0 
)
protectedvirtual

Subtract current f1 from old f1 to see if threshold is reached or not.

Warning
this time, nothing is deleted
Parameters
oldand new VFuntion
Warning
this time, nothing is deleted

Implements gum::IOperatorStrategy< GUM_SCALAR >.

Definition at line 211 of file treeOperatorStrategy_tpl.h.

References gum::TreeOperator< GUM_SCALAR, COMBINEOPERATOR, TerminalNodePolicy >::compute().

Referenced by gum::TreeOperatorStrategy< GUM_SCALAR >::getAggregatorInstance().

214  {
215  TreeOperator< GUM_SCALAR, std::minus > opi(f1, f2);
216  MultiDimFunctionGraph< GUM_SCALAR >* ret = opi.compute();
217  this->_deleteFunctionGraph(f1, f2, del);
218  return ret;
219  }
INLINE void _deleteFunctionGraph(const MultiDimFunctionGraph< GUM_SCALAR > *f1, const MultiDimFunctionGraph< GUM_SCALAR > *f2, Idx del)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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