<s> """<STR_LIT>""" <EOL> import numpy as np <EOL> from . Representation import Representation <EOL> from rlpy . Tools import svm <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 BEBF ( Representation ) : <EOL> """<STR_LIT>""" <EOL> maxBatchDiscovery = <NUM_LIT:1> <EOL> svm_epsilon = None <EOL> features = [ ] <EOL> batchThreshold = None <EOL> initial_features_num = <NUM_LIT:0> <EOL> def __init__ ( self , domain , discretization = <NUM_LIT:20> , <EOL> batchThreshold = <NUM_LIT:10> ** - <NUM_LIT:3> , svm_epsilon = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> self . setBinsPerDimension ( domain , discretization ) <EOL> self . initial_features_num = int ( sum ( self . bins_per_dim ) ) <EOL> self . features_num = self . initial_features_num <EOL> self . svm_epsilon = svm_epsilon <EOL> self . batchThreshold = batchThreshold <EOL> self . addInitialFeatures ( ) <EOL> super ( BEBF , self ) . __init__ ( domain , discretization ) <EOL> self . isDynamic = True <EOL> def getFunctionApproximation ( self , X , y ) : <EOL> """<STR_LIT>""" <EOL> bebfApprox = svm . SVR ( <EOL> kernel = '<STR_LIT>' , <EOL> degree = <NUM_LIT:3> , <EOL> C = <NUM_LIT:1.0> , <EOL> epsilon = self . svm_epsilon ) <EOL> bebfApprox . fit ( X , y ) <EOL> return bebfApprox <EOL> def addInitialFeatures ( self ) : <EOL> pass <EOL> def phi_nonTerminal ( self , s ) : <EOL> F_s = np . zeros ( self . features_num ) <EOL> F_s [ self . activeInitialFeatures ( s ) ] = <NUM_LIT:1> <EOL> bebf_features_num = self . features_num - self . initial_features_num <EOL> for features_ind , F_s_ind in enumerate ( np . arange ( bebf_features_num ) + self . initial_features_num ) : <EOL> F_s [ F_s_ind ] = self . features [ features_ind ] . predict ( s ) <EOL> return F_s <EOL> def batchDiscover ( self , td_errors , all_phi_s , s ) : <EOL> addedFeature = False <EOL> norm = max ( abs ( td_errors ) ) <EOL> for j in xrange ( self . maxBatchDiscovery ) : <EOL> self . features . append ( self . getFunctionApproximation ( s , td_errors ) ) <EOL> if norm > self . batchThreshold : <EOL> self . addNewWeight ( ) <EOL> addedFeature = True <EOL> self . features_num += <NUM_LIT:1> <EOL> self . logger . debug ( <EOL> '<STR_LIT>' % <EOL> self . features_num ) <EOL> else : <EOL> break <EOL> return addedFeature <EOL> def featureType ( self ) : <EOL> return float </s>
