aGrUM  0.14.2
gum::E_GreedyDecider Class Reference

<agrum/FMDP/decision/E_GreedyDecider.h> More...

#include <E_GreedyDecider.h>

+ Inheritance diagram for gum::E_GreedyDecider:
+ Collaboration diagram for gum::E_GreedyDecider:

Public Member Functions

Constructor & destructor.
 E_GreedyDecider ()
 Constructor. More...
 
 ~E_GreedyDecider ()
 Destructor. More...
 
Initialization
void initialize (const FMDP< double > *fmdp)
 Initializes the learner. More...
 
Incremental methods
void checkState (const Instantiation &newState, Idx actionId)
 
ActionSet stateOptimalPolicy (const Instantiation &curState)
 

Incremental methods

void setOptimalStrategy (const MultiDimFunctionGraph< ActionSet, SetTerminalNodePolicy > *optPol)
 
const MultiDimFunctionGraph< ActionSet, SetTerminalNodePolicy > * _optPol
 
ActionSet _allActions
 

Detailed Description

<agrum/FMDP/decision/E_GreedyDecider.h>

Class to make decision following an epsilon-greedy compromise between exploration and exploitation

Definition at line 53 of file E_GreedyDecider.h.

Constructor & Destructor Documentation

◆ E_GreedyDecider()

gum::E_GreedyDecider::E_GreedyDecider ( )

Constructor.

Definition at line 45 of file E_GreedyDecider.cpp.

References __sss.

45  {
46  GUM_CONSTRUCTOR(E_GreedyDecider);
47 
48  __sss = 1.0;
49  }
E_GreedyDecider()
Constructor.

◆ ~E_GreedyDecider()

gum::E_GreedyDecider::~E_GreedyDecider ( )

Destructor.

Definition at line 57 of file E_GreedyDecider.cpp.

57 { GUM_DESTRUCTOR(E_GreedyDecider); }
E_GreedyDecider()
Constructor.

Member Function Documentation

◆ checkState()

void gum::E_GreedyDecider::checkState ( const Instantiation newState,
Idx  actionId 
)
virtual

Implements gum::IDecisionStrategy.

Definition at line 88 of file E_GreedyDecider.cpp.

References __statecpt, gum::StatesChecker::addState(), gum::StatesChecker::checkState(), gum::StatesChecker::nbVisitedStates(), and gum::StatesChecker::reset().

89  {
90  if (__statecpt.nbVisitedStates() == 0)
91  __statecpt.reset(reachedState);
92  else if (!__statecpt.checkState(reachedState))
93  __statecpt.addState(reachedState);
94  }
bool checkState(const Instantiation &state)
Definition: statesChecker.h:70
StatesChecker __statecpt
void addState(const Instantiation &)
void reset(const Instantiation &)
+ Here is the call graph for this function:

◆ initialize()

void gum::E_GreedyDecider::initialize ( const FMDP< double > *  fmdp)
virtual

Initializes the learner.

Reimplemented from gum::IDecisionStrategy.

Definition at line 69 of file E_GreedyDecider.cpp.

References __sss, gum::FMDP< GUM_SCALAR >::beginVariables(), gum::FMDP< GUM_SCALAR >::endVariables(), and gum::IDecisionStrategy::initialize().

69  {
71  for (auto varIter = fmdp->beginVariables(); varIter != fmdp->endVariables();
72  ++varIter)
73  __sss *= (double)(*varIter)->domainSize();
74  }
virtual void initialize(const FMDP< double > *fmdp)
Initializes the learner.
SequenceIteratorSafe< const DiscreteVariable *> beginVariables() const
Returns an iterator reference to he beginning of the list of variables.
Definition: fmdp.h:92
SequenceIteratorSafe< const DiscreteVariable *> endVariables() const
Returns an iterator reference to the end of the list of variables.
Definition: fmdp.h:99
+ Here is the call graph for this function:

◆ setOptimalStrategy()

void gum::IDecisionStrategy::setOptimalStrategy ( const MultiDimFunctionGraph< ActionSet, SetTerminalNodePolicy > *  optPol)
inlineinherited

Definition at line 87 of file IDecisionStrategy.h.

References gum::IDecisionStrategy::_optPol.

Referenced by gum::SDYNA::makePlanning().

88  {
89  _optPol =
90  const_cast< MultiDimFunctionGraph< ActionSet, SetTerminalNodePolicy >* >(
91  optPol);
92  }
const MultiDimFunctionGraph< ActionSet, SetTerminalNodePolicy > * _optPol
+ Here is the caller graph for this function:

◆ stateOptimalPolicy()

ActionSet gum::E_GreedyDecider::stateOptimalPolicy ( const Instantiation curState)
virtual

Reimplemented from gum::IDecisionStrategy.

Definition at line 102 of file E_GreedyDecider.cpp.

References __sss, __statecpt, gum::IDecisionStrategy::_allActions, gum::StatesChecker::nbVisitedStates(), gum::ActionSet::size(), and gum::IDecisionStrategy::stateOptimalPolicy().

102  {
103  double explo = (double)std::rand() / (double)RAND_MAX;
104  double temp =
105  std::pow((__sss - (double)__statecpt.nbVisitedStates()) / __sss, 3.0);
106  double exploThreshold = temp < 0.1 ? 0.1 : temp;
107 
108  // std::cout << exploThreshold << std::endl;
109 
110  ActionSet optimalSet = IDecisionStrategy::stateOptimalPolicy(curState);
111  if (explo > exploThreshold) {
112  // std::cout << "Exploit : " << optimalSet << std::endl;
113  return optimalSet;
114  }
115 
116  if (_allActions.size() > optimalSet.size()) {
117  ActionSet ret(_allActions);
118  ret -= optimalSet;
119  // std::cout << "Explore : " << ret << std::endl;
120  return ret;
121  }
122 
123  // std::cout << "Explore : " << _allActions << std::endl;
124  return _allActions;
125  }
Size size() const
Gives the size.
Definition: actionSet.h:208
virtual ActionSet stateOptimalPolicy(const Instantiation &curState)
StatesChecker __statecpt
+ Here is the call graph for this function:

Member Data Documentation

◆ __sss

double gum::E_GreedyDecider::__sss
private

Definition at line 97 of file E_GreedyDecider.h.

Referenced by E_GreedyDecider(), initialize(), and stateOptimalPolicy().

◆ __statecpt

StatesChecker gum::E_GreedyDecider::__statecpt
private

Definition at line 96 of file E_GreedyDecider.h.

Referenced by checkState(), and stateOptimalPolicy().

◆ _allActions

◆ _optPol


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