<s> __author__ = "<STR_LIT>" <EOL> from scipy import random , dot <EOL> from pybrain . structure . modules . module import Module <EOL> from pybrain . rl . explorers . explorer import Explorer <EOL> from pybrain . tools . functions import expln , explnPrime <EOL> from pybrain . structure . parametercontainer import ParameterContainer <EOL> class StateDependentExplorer ( Explorer , ParameterContainer ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , statedim , actiondim , sigma = - <NUM_LIT> ) : <EOL> Explorer . __init__ ( self , actiondim , actiondim ) <EOL> self . statedim = statedim <EOL> self . actiondim = actiondim <EOL> ParameterContainer . __init__ ( self , actiondim , stdParams = <NUM_LIT:0> ) <EOL> self . sigma = [ sigma ] * actiondim <EOL> self . explmatrix = random . normal ( <NUM_LIT:0.> , expln ( self . sigma ) , ( statedim , actiondim ) ) <EOL> self . state = None <EOL> def _setSigma ( self , sigma ) : <EOL> """<STR_LIT>""" <EOL> assert len ( sigma ) == self . actiondim <EOL> self . _params *= <NUM_LIT:0> <EOL> self . _params += sigma <EOL> def _getSigma ( self ) : <EOL> return self . params <EOL> sigma = property ( _getSigma , _setSigma ) <EOL> def newEpisode ( self ) : <EOL> """<STR_LIT>""" <EOL> self . explmatrix = random . normal ( <NUM_LIT:0.> , expln ( self . sigma ) , self . explmatrix . shape ) <EOL> def activate ( self , state , action ) : <EOL> """<STR_LIT>""" <EOL> self . state = state <EOL> return Module . activate ( self , action ) <EOL> def _forwardImplementation ( self , inbuf , outbuf ) : <EOL> outbuf [ : ] = inbuf + dot ( self . state , self . explmatrix ) <EOL> def _backwardImplementation ( self , outerr , inerr , outbuf , inbuf ) : <EOL> expln_params = expln ( self . params <EOL> ) . reshape ( len ( outbuf ) , len ( self . state ) ) <EOL> explnPrime_params = explnPrime ( self . params <EOL> ) . reshape ( len ( outbuf ) , len ( self . state ) ) <EOL> idx = <NUM_LIT:0> <EOL> for j in range ( len ( outbuf ) ) : <EOL> sigma_subst2 = dot ( self . state ** <NUM_LIT:2> , expln_params [ j , : ] ** <NUM_LIT:2> ) <EOL> for i in range ( len ( self . state ) ) : <EOL> self . _derivs [ idx ] = ( ( outbuf [ j ] - inbuf [ j ] ) ** <NUM_LIT:2> - sigma_subst2 ) / sigma_subst2 * self . state [ i ] ** <NUM_LIT:2> * expln_params [ j , i ] * explnPrime_params [ j , i ] <EOL> idx += <NUM_LIT:1> <EOL> inerr [ j ] = ( outbuf [ j ] - inbuf [ j ] ) </s>
