aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
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 49 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.

References gum::Set< Key, Alloc >::emplace().

63  {
64  GUM_CONSTRUCTOR(TreeOperatorStrategy);
65  }
TreeOperatorStrategy()
Default constructor.
+ Here is the call graph for this function:

◆ ~TreeOperatorStrategy()

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

Default destructor.

Definition at line 71 of file treeOperatorStrategy_tpl.h.

References gum::Set< Key, Alloc >::emplace().

71  {
72  GUM_DESTRUCTOR(TreeOperatorStrategy);
73  }
TreeOperatorStrategy()
Default constructor.
+ Here is the call graph for this function:

Member Function Documentation

◆ 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 185 of file treeOperatorStrategy_tpl.h.

References gum::Set< Key, Alloc >::emplace().

187  {
188  TreeOperator< GUM_SCALAR, std::plus > opi(f1, f2);
189  MultiDimFunctionGraph< GUM_SCALAR >* ret = opi.compute();
190  this->deleteFunctionGraph_(f1, f2, del);
191  return ret;
192  }
INLINE void deleteFunctionGraph_(const MultiDimFunctionGraph< GUM_SCALAR > *f1, const MultiDimFunctionGraph< GUM_SCALAR > *f2, Idx del)
+ Here is the call 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 165 of file treeOperatorStrategy_tpl.h.

References gum::Set< Key, Alloc >::emplace().

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

168  {
169  TreeOperator< ArgMaxSet< GUM_SCALAR, Idx >, ArgumentMaximisesAction, SetTerminalNodePolicy >
170  argmaxope(f1, f2);
171  MultiDimFunctionGraph< ArgMaxSet< GUM_SCALAR, Idx >, SetTerminalNodePolicy >* ret
172  = argmaxope.compute();
173  this->deleteFunctionGraph_(f1, f2, del);
174  return ret;
175  }
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:

◆ 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 156 of file IOperatorStrategy.h.

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

◆ 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 163 of file IOperatorStrategy.h.

Referenced by gum::IOperatorStrategy< double >::deleteFunctionGraph_().

166  {
167  if (del == 1 || del == 3) delete f1;
168  if (del >= 2) delete f2;
169  }
+ 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 81 of file treeOperatorStrategy.h.

References gum::TreeOperatorStrategy< GUM_SCALAR >::argmaximize().

81  {
83  }
static MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * getTreeInstance()
Returns an arborescent instance.
+ 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 77 of file treeOperatorStrategy.h.

References gum::TreeOperatorStrategy< GUM_SCALAR >::argmaximize().

77  {
78  return MultiDimFunctionGraph< ArgMaxSet< GUM_SCALAR, Idx >,
79  SetTerminalNodePolicy >::getTreeInstance();
80  }
+ Here is the call graph for this function:

◆ getFunctionInstance()

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

Implements gum::IOperatorStrategy< GUM_SCALAR >.

Definition at line 73 of file treeOperatorStrategy.h.

73  {
75  }
static MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * getTreeInstance()
Returns an arborescent instance.

◆ 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 122 of file treeOperatorStrategy_tpl.h.

References gum::Set< Key, Alloc >::emplace().

124  {
125  TreeOperator< GUM_SCALAR, Maximizes > opi(f1, f2);
126  MultiDimFunctionGraph< GUM_SCALAR >* ret = opi.compute();
127  this->deleteFunctionGraph_(f1, f2, del);
128  return ret;
129  }
INLINE void deleteFunctionGraph_(const MultiDimFunctionGraph< GUM_SCALAR > *f1, const MultiDimFunctionGraph< GUM_SCALAR > *f2, Idx del)
+ Here is the call 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 136 of file treeOperatorStrategy_tpl.h.

References gum::Set< Key, Alloc >::emplace().

138  {
139  TreeOperator< GUM_SCALAR, Minimizes > opi(f1, f2);
140  MultiDimFunctionGraph< GUM_SCALAR >* ret = opi.compute();
141  this->deleteFunctionGraph_(f1, f2, del);
142  return ret;
143  }
INLINE void deleteFunctionGraph_(const MultiDimFunctionGraph< GUM_SCALAR > *f1, const MultiDimFunctionGraph< GUM_SCALAR > *f2, Idx del)
+ Here is the call 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 149 of file treeOperatorStrategy_tpl.h.

References gum::Set< Key, Alloc >::emplace().

151  {
152  TreeOperator< GUM_SCALAR, std::multiplies > opi(f1, f2);
153  MultiDimFunctionGraph< GUM_SCALAR >* ret = opi.compute();
154  this->deleteFunctionGraph_(f1, f2, del);
155  return ret;
156  }
INLINE void deleteFunctionGraph_(const MultiDimFunctionGraph< GUM_SCALAR > *f1, const MultiDimFunctionGraph< GUM_SCALAR > *f2, Idx del)
+ Here is the call 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 94 of file treeOperatorStrategy_tpl.h.

References gum::Set< Key, Alloc >::emplace().

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*, const MultiDimFunctionGraph< GUM_SCALAR >* > pxi;
103  for (SequenceIteratorSafe< const DiscreteVariable* > varIter
104  = Vold->variablesSequence().beginSafe();
105  varIter != Vold->variablesSequence().endSafe();
106  ++varIter) {
107  pxi.insert(*varIter,
108  RECAST(fmdp->transition(actionId, fmdp->mapMainPrime().first(*varIter))));
109  }
110 
111  TreeRegress< GUM_SCALAR, std::multiplies, std::plus > tr(
112  Vold,
113  pxi); //, Vold->variablesSequence(), (GUM_SCALAR) 0.0 );
114  return tr.compute();
115  }
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:

◆ 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 202 of file treeOperatorStrategy_tpl.h.

References gum::Set< Key, Alloc >::emplace().

204  {
205  TreeOperator< GUM_SCALAR, std::minus > opi(f1, f2);
206  MultiDimFunctionGraph< GUM_SCALAR >* ret = opi.compute();
207  this->deleteFunctionGraph_(f1, f2, del);
208  return ret;
209  }
INLINE void deleteFunctionGraph_(const MultiDimFunctionGraph< GUM_SCALAR > *f1, const MultiDimFunctionGraph< GUM_SCALAR > *f2, Idx del)
+ Here is the call graph for this function:

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