<s> """<STR_LIT>""" <EOL> from . Policy import Policy <EOL> import numpy as np <EOL> __copyright__ = "<STR_LIT>" <EOL> __credits__ = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ] <EOL> __license__ = "<STR_LIT>" <EOL> __author__ = "<STR_LIT>" <EOL> class eGreedy ( Policy ) : <EOL> """<STR_LIT>""" <EOL> epsilon = None <EOL> old_epsilon = None <EOL> forcedDeterministicAmongBestActions = None <EOL> def __init__ ( self , representation , epsilon = <NUM_LIT> , <EOL> forcedDeterministicAmongBestActions = False , seed = <NUM_LIT:1> ) : <EOL> self . epsilon = epsilon <EOL> self . forcedDeterministicAmongBestActions = forcedDeterministicAmongBestActions <EOL> super ( eGreedy , self ) . __init__ ( representation , seed ) <EOL> def pi ( self , s , terminal , p_actions ) : <EOL> coin = self . random_state . rand ( ) <EOL> if coin < self . epsilon : <EOL> return self . random_state . choice ( p_actions ) <EOL> else : <EOL> b_actions = self . representation . bestActions ( s , terminal , p_actions ) <EOL> if self . forcedDeterministicAmongBestActions : <EOL> return b_actions [ <NUM_LIT:0> ] <EOL> else : <EOL> return self . random_state . choice ( b_actions ) <EOL> def prob ( self , s , terminal , p_actions ) : <EOL> p = np . ones ( len ( p_actions ) ) / len ( p_actions ) <EOL> p *= self . epsilon <EOL> b_actions = self . representation . bestActions ( s , terminal , p_actions ) <EOL> if self . forcedDeterministicAmongBestActions : <EOL> p [ b_actions [ <NUM_LIT:0> ] ] += ( <NUM_LIT:1> - self . epsilon ) <EOL> else : <EOL> p [ b_actions ] += ( <NUM_LIT:1> - self . epsilon ) / len ( b_actions ) <EOL> return p <EOL> def turnOffExploration ( self ) : <EOL> self . old_epsilon = self . epsilon <EOL> self . epsilon = <NUM_LIT:0> <EOL> def turnOnExploration ( self ) : <EOL> self . epsilon = self . old_epsilon </s>
