<s> class TabularQAgent ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , observation_space , action_space , ** userconfig ) : <EOL> if not isinstance ( observation_space , discrete . Discrete ) : <EOL> raise UnsupportedSpace ( '<STR_LIT>' . format ( observation_space , self ) ) <EOL> if not isinstance ( action_space , discrete . Discrete ) : <EOL> raise UnsupportedSpace ( '<STR_LIT>' . format ( action_space , self ) ) <EOL> self . observation_space = observation_space <EOL> self . action_space = action_space <EOL> self . action_n = action_space . n <EOL> self . config = { <EOL> "<STR_LIT>" : <NUM_LIT:0.0> , <EOL> "<STR_LIT>" : <NUM_LIT:0.0> , <EOL> "<STR_LIT>" : <NUM_LIT:0.1> , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT> } <EOL> self . config . update ( userconfig ) <EOL> self . q = defaultdict ( lambda : self . config [ "<STR_LIT>" ] * np . random . randn ( self . action_n ) + self . config [ "<STR_LIT>" ] ) <EOL> def act ( self , observation , eps = None ) : <EOL> if eps is None : <EOL> eps = self . config [ "<STR_LIT>" ] <EOL> action = np . argmax ( self . q [ observation . item ( ) ] ) if np . random . random ( ) > eps else self . action_space . sample ( ) <EOL> return action <EOL> def learn ( self , env ) : <EOL> config = self . config <EOL> obs = env . reset ( ) <EOL> q = self . q <EOL> for t in xrange ( config [ "<STR_LIT>" ] ) : <EOL> action , _ = self . act ( obs ) <EOL> obs2 , reward , done , _ = env . step ( action ) <EOL> future = <NUM_LIT:0.0> <EOL> if not done : <EOL> future = np . max ( q [ obs2 . item ( ) ] ) <EOL> q [ obs . item ( ) ] [ action ] -= self . config [ "<STR_LIT>" ] * ( q [ obs . item ( ) ] [ action ] - reward - config [ "<STR_LIT>" ] * future ) <EOL> obs = obs2 </s>
