<s> from __future__ import print_function <EOL> __author__ = '<STR_LIT>' <EOL> from pybrain . rl . learners . directsearch . policygradient import PolicyGradientLearner <EOL> from scipy import ones , dot , ravel <EOL> from scipy . linalg import pinv <EOL> class ENAC ( PolicyGradientLearner ) : <EOL> """<STR_LIT>""" <EOL> def calculateGradient ( self ) : <EOL> R = ones ( ( self . dataset . getNumSequences ( ) , <NUM_LIT:1> ) , float ) <EOL> X = ones ( ( self . dataset . getNumSequences ( ) , self . loglh . getDimension ( '<STR_LIT>' ) + <NUM_LIT:1> ) , float ) <EOL> print ( ( self . dataset . getNumSequences ( ) ) ) <EOL> for n in range ( self . dataset . getNumSequences ( ) ) : <EOL> _state , _action , reward = self . dataset . getSequence ( n ) <EOL> seqidx = ravel ( self . dataset [ '<STR_LIT>' ] ) <EOL> if n == self . dataset . getNumSequences ( ) - <NUM_LIT:1> : <EOL> loglh = self . loglh [ '<STR_LIT>' ] [ seqidx [ n ] : , : ] <EOL> else : <EOL> loglh = self . loglh [ '<STR_LIT>' ] [ seqidx [ n ] : seqidx [ n + <NUM_LIT:1> ] , : ] <EOL> X [ n , : - <NUM_LIT:1> ] = sum ( loglh , <NUM_LIT:0> ) <EOL> R [ n , <NUM_LIT:0> ] = sum ( reward , <NUM_LIT:0> ) <EOL> beta = dot ( pinv ( X ) , R ) <EOL> return beta [ : - <NUM_LIT:1> ] </s>
