aGrUM  0.16.0
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 56 of file E_GreedyDecider.h.

Constructor & Destructor Documentation

◆ E_GreedyDecider()

gum::E_GreedyDecider::E_GreedyDecider ( )

Constructor.

Definition at line 48 of file E_GreedyDecider.cpp.

References __sss.

48  {
49  GUM_CONSTRUCTOR(E_GreedyDecider);
50 
51  __sss = 1.0;
52  }
E_GreedyDecider()
Constructor.

◆ ~E_GreedyDecider()

gum::E_GreedyDecider::~E_GreedyDecider ( )

Destructor.

Definition at line 60 of file E_GreedyDecider.cpp.

60 { 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 91 of file E_GreedyDecider.cpp.

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

92  {
93  if (__statecpt.nbVisitedStates() == 0)
94  __statecpt.reset(reachedState);
95  else if (!__statecpt.checkState(reachedState))
96  __statecpt.addState(reachedState);
97  }
bool checkState(const Instantiation &state)
Definition: statesChecker.h:73
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 72 of file E_GreedyDecider.cpp.

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

72  {
74  for (auto varIter = fmdp->beginVariables(); varIter != fmdp->endVariables();
75  ++varIter)
76  __sss *= (double)(*varIter)->domainSize();
77  }
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:95
SequenceIteratorSafe< const DiscreteVariable *> endVariables() const
Returns an iterator reference to the end of the list of variables.
Definition: fmdp.h:102
+ Here is the call graph for this function:

◆ setOptimalStrategy()

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

Definition at line 90 of file IDecisionStrategy.h.

References gum::IDecisionStrategy::_optPol.

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

91  {
92  _optPol =
93  const_cast< MultiDimFunctionGraph< ActionSet, SetTerminalNodePolicy >* >(
94  optPol);
95  }
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 105 of file E_GreedyDecider.cpp.

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

105  {
106  double explo = (double)std::rand() / (double)RAND_MAX;
107  double temp =
108  std::pow((__sss - (double)__statecpt.nbVisitedStates()) / __sss, 3.0);
109  double exploThreshold = temp < 0.1 ? 0.1 : temp;
110 
111  // std::cout << exploThreshold << std::endl;
112 
113  ActionSet optimalSet = IDecisionStrategy::stateOptimalPolicy(curState);
114  if (explo > exploThreshold) {
115  // std::cout << "Exploit : " << optimalSet << std::endl;
116  return optimalSet;
117  }
118 
119  if (_allActions.size() > optimalSet.size()) {
120  ActionSet ret(_allActions);
121  ret -= optimalSet;
122  // std::cout << "Explore : " << ret << std::endl;
123  return ret;
124  }
125 
126  // std::cout << "Explore : " << _allActions << std::endl;
127  return _allActions;
128  }
Size size() const
Gives the size.
Definition: actionSet.h:211
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 100 of file E_GreedyDecider.h.

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

◆ __statecpt

StatesChecker gum::E_GreedyDecider::__statecpt
private

Definition at line 99 of file E_GreedyDecider.h.

Referenced by checkState(), and stateOptimalPolicy().

◆ _allActions

◆ _optPol


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