<s> import numpy as np <EOL> import pybrain . rl . environments <EOL> from pybrain . utilities import one_to_n <EOL> from environment import Environment <EOL> class BalanceTask ( pybrain . rl . environments . EpisodicTask ) : <EOL> """<STR_LIT>""" <EOL> max_tilt = np . pi / <NUM_LIT> <EOL> nactions = <NUM_LIT:9> <EOL> def __init__ ( self , butt_disturbance_amplitude = <NUM_LIT> , only_steer = False , <EOL> max_time = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> super ( BalanceTask , self ) . __init__ ( Environment ( ) ) <EOL> self . _butt_disturbance_amplitude = butt_disturbance_amplitude <EOL> self . only_steer = only_steer <EOL> self . max_time = max_time <EOL> self . t = <NUM_LIT:0> <EOL> self . action_history = np . zeros ( self . nactions ) <EOL> @ property <EOL> def indim ( self ) : <EOL> return <NUM_LIT:1> <EOL> @ property <EOL> def outdim ( self ) : <EOL> return <NUM_LIT:5> <EOL> def reset ( self ) : <EOL> super ( BalanceTask , self ) . reset ( ) <EOL> self . t = <NUM_LIT:0> <EOL> def performAction ( self , action ) : <EOL> """<STR_LIT>""" <EOL> self . t += <NUM_LIT:1> <EOL> self . action_history += one_to_n ( action [ <NUM_LIT:0> ] , self . nactions ) <EOL> assert round ( action [ <NUM_LIT:0> ] ) == action [ <NUM_LIT:0> ] <EOL> if self . only_steer : <EOL> T = <NUM_LIT:2> * ( action [ <NUM_LIT:0> ] / <NUM_LIT> - <NUM_LIT:1.0> ) <EOL> d = <NUM_LIT:0.> <EOL> else : <EOL> torque_selector = np . floor ( action [ <NUM_LIT:0> ] / <NUM_LIT> ) - <NUM_LIT:1.0> <EOL> T = <NUM_LIT:2> * torque_selector <EOL> p = <NUM_LIT> * np . random . rand ( ) - <NUM_LIT:1.0> <EOL> disp_selector = action [ <NUM_LIT:0> ] % <NUM_LIT:3> - <NUM_LIT:1.0> <EOL> d = <NUM_LIT> * disp_selector + self . _butt_disturbance_amplitude * p <EOL> super ( BalanceTask , self ) . performAction ( [ T , d ] ) <EOL> def getObservation ( self ) : <EOL> ( theta , thetad , omega , omegad , omegadd , <EOL> xf , yf , xb , yb , psi ) = self . env . getSensors ( ) <EOL> return self . env . getSensors ( ) [ <NUM_LIT:0> : <NUM_LIT:5> ] <EOL> def isFinished ( self ) : <EOL> if np . abs ( self . env . getTilt ( ) ) > self . max_tilt : <EOL> return True <EOL> elapsed_time = self . env . time_step * self . t <EOL> if elapsed_time > self . max_time : <EOL> print '<STR_LIT>' , self . t , elapsed_time <EOL> return True <EOL> return False <EOL> def getReward ( self ) : <EOL> if np . abs ( self . env . getTilt ( ) ) > self . max_tilt : <EOL> return - <NUM_LIT:1.0> <EOL> return <NUM_LIT:0.0> <EOL> class GotoTask ( BalanceTask ) : <EOL> """<STR_LIT>""" <EOL> x_goal = <NUM_LIT> <EOL> y_goal = <NUM_LIT> <EOL> r_goal = <NUM_LIT> <EOL> @ property <EOL> def outdim ( self ) : <EOL> return <NUM_LIT:8> <EOL> def getObservation ( self ) : <EOL> ( theta , thetad , omega , omegad , omegadd , <EOL> xf , yf , xb , yb , psi ) = self . env . getSensors ( ) <EOL> return [ self . env . getSensors ( ) [ i ] for i in [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:9> ] ] <EOL> def isFinished ( self ) : <EOL> dist_to_goal = self . calc_dist_to_goal ( ) <EOL> heading = self . calc_angle_to_goal ( ) <EOL> heading2 = self . env . getPsi ( ) <EOL> if np . abs ( self . env . getTilt ( ) ) > self . max_tilt : <EOL> print '<STR_LIT>' , dist_to_goal <EOL> return True <EOL> if dist_to_goal < <NUM_LIT> : <EOL> print '<STR_LIT>' <EOL> return True <EOL> return False <EOL> def getReward ( self ) : <EOL> r_factor = <NUM_LIT> <EOL> if np . abs ( self . env . getTilt ( ) ) > self . max_tilt : <EOL> return - <NUM_LIT:1.0> <EOL> else : <EOL> temp = self . calc_dist_to_goal ( ) <EOL> heading = self . calc_angle_to_goal ( ) <EOL> if ( temp < <NUM_LIT> ) : <EOL> return <NUM_LIT> <EOL> else : <EOL> return ( <NUM_LIT> - heading ** <NUM_LIT:2> ) * r_factor <EOL> def calc_dist_to_goal ( self ) : <EOL> x_goal = self . x_goal <EOL> y_goal = self . y_goal <EOL> r_goal = self . r_goal <EOL> xf = self . env . getXF ( ) <EOL> yf = self . env . getYF ( ) <EOL> sqrd_dist_to_goal = ( x_goal - xf ) ** <NUM_LIT:2> + ( y_goal - yf ) ** <NUM_LIT:2> <EOL> temp = np . max ( [ <NUM_LIT:0> , sqrd_dist_to_goal - r_goal ** <NUM_LIT:2> ] ) <EOL> temp = np . sqrt ( temp ) <EOL> return temp <EOL> def calc_angle_to_goal ( self ) : <EOL> x_goal = self . x_goal <EOL> y_goal = self . y_goal <EOL> xf = self . env . getXF ( ) <EOL> xb = self . env . getXB ( ) <EOL> yf = self . env . getYF ( ) <EOL> yb = self . env . getYB ( ) <EOL> temp = ( xf - xb ) * ( x_goal - xf ) + ( yf - yb ) * ( y_goal - yf ) <EOL> scalar = temp / ( <NUM_LIT:1> * np . sqrt ( ( x_goal - xf ) ** <NUM_LIT:2> + ( y_goal - yf ) ** <NUM_LIT:2> ) ) <EOL> tvaer = ( - yf + yb ) * ( x_goal - xf ) + ( xf - xb ) * ( y_goal - yf ) <EOL> if tvaer <= <NUM_LIT:0> : <EOL> temp = scalar - <NUM_LIT:1> <EOL> else : <EOL> temp = np . abs ( scalar - <NUM_LIT:1> ) <EOL> return temp <EOL> class LinearFATileCoding3456BalanceTask ( BalanceTask ) : <EOL> """<STR_LIT>""" <EOL> theta_bounds = np . array ( <EOL> [ - <NUM_LIT:0.5> * np . pi , - <NUM_LIT:1.0> , - <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:1.0> , <NUM_LIT:0.5> * np . pi ] ) <EOL> thetad_bounds = np . array ( <EOL> [ - np . inf , - <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT> , np . inf ] ) <EOL> omega_bounds = np . array ( <EOL> [ - BalanceTask . max_tilt , - <NUM_LIT> , - <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> , <EOL> BalanceTask . max_tilt ] ) <EOL> omegad_bounds = np . array ( <EOL> [ - np . inf , - <NUM_LIT:0.5> , - <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:0.5> , np . inf ] ) <EOL> omegadd_bounds = np . array ( <EOL> [ - np . inf , - <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT> , np . inf ] ) <EOL> nbins_across_dims = [ <EOL> len ( theta_bounds ) - <NUM_LIT:1> , <EOL> len ( thetad_bounds ) - <NUM_LIT:1> , <EOL> len ( omega_bounds ) - <NUM_LIT:1> , <EOL> len ( omegad_bounds ) - <NUM_LIT:1> , <EOL> len ( omegadd_bounds ) - <NUM_LIT:1> ] <EOL> magic_array = np . cumprod ( [ <NUM_LIT:1> ] + nbins_across_dims ) [ : - <NUM_LIT:1> ] <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( LinearFATileCoding3456BalanceTask , self ) . __init__ ( * args , ** kwargs ) <EOL> self . bin_count = np . zeros ( self . outdim ) <EOL> @ property <EOL> def outdim ( self ) : <EOL> return <NUM_LIT> <EOL> def getBin ( self , theta , thetad , omega , omegad , omegadd ) : <EOL> bin_indices = [ <EOL> np . digitize ( [ theta ] , self . theta_bounds ) [ <NUM_LIT:0> ] - <NUM_LIT:1> , <EOL> np . digitize ( [ thetad ] , self . thetad_bounds ) [ <NUM_LIT:0> ] - <NUM_LIT:1> , <EOL> np . digitize ( [ omega ] , self . omega_bounds ) [ <NUM_LIT:0> ] - <NUM_LIT:1> , <EOL> np . digitize ( [ omegad ] , self . omegad_bounds ) [ <NUM_LIT:0> ] - <NUM_LIT:1> , <EOL> np . digitize ( [ omegadd ] , self . omegadd_bounds ) [ <NUM_LIT:0> ] - <NUM_LIT:1> , <EOL> ] <EOL> linear_index = np . dot ( self . magic_array , bin_indices ) <EOL> if linear_index > self . outdim : <EOL> print self . isFinished ( ) <EOL> print self . env . getTilt ( ) <EOL> print np . abs ( self . env . getTilt ( ) ) <EOL> print self . max_tilt <EOL> print np . abs ( self . env . getTilt ( ) ) > self . max_tilt <EOL> print self . env . getSensors ( ) [ <NUM_LIT:0> : <NUM_LIT:5> ] <EOL> print self . magic_array <EOL> print bin_index_for_each_dim <EOL> print linear_index <EOL> return linear_index <EOL> def getBinIndices ( self , linear_index ) : <EOL> """<STR_LIT>""" <EOL> return linear_index / self . magic_array % self . nbins_across_dims <EOL> def getObservation ( self ) : <EOL> ( theta , thetad , omega , omegad , omegadd , <EOL> xf , yf , xb , yb , psi ) = self . env . getSensors ( ) <EOL> state = one_to_n ( self . getBin ( theta , thetad , omega , omegad , omegadd ) , <EOL> self . outdim ) <EOL> self . bin_count += state <EOL> return state <EOL> class LSPIBalanceTask ( BalanceTask ) : <EOL> """<STR_LIT>""" <EOL> @ property <EOL> def outdim ( self ) : <EOL> return <NUM_LIT> <EOL> def getPhi ( self , theta , thetad , omega , omegad , omegadd ) : <EOL> return np . array ( [ <EOL> <NUM_LIT:1> , omega , omegad , omega ** <NUM_LIT:2> , omegad ** <NUM_LIT:2> , omega * omegad , <EOL> theta , thetad , theta ** <NUM_LIT:2> , thetad ** <NUM_LIT:2> , theta * thetad , <EOL> omega * theta , omega * theta ** <NUM_LIT:2> , omega ** <NUM_LIT:2> * theta , <EOL> ] ) <EOL> def getObservation ( self ) : <EOL> ( theta , thetad , omega , omegad , omegadd , <EOL> xf , yf , xb , yb , psi ) = self . env . getSensors ( ) <EOL> return self . getPhi ( theta , thetad , omega , omegad , omegadd ) <EOL> class LinearFATileCoding3456GoToTask ( BalanceTask ) : <EOL> """<STR_LIT>""" <EOL> x_goal = <NUM_LIT> <EOL> y_goal = <NUM_LIT> <EOL> r_goal = <NUM_LIT> <EOL> theta_bounds = np . array ( <EOL> [ - <NUM_LIT:0.5> * np . pi , - <NUM_LIT:1.0> , - <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:1.0> , <NUM_LIT:0.5> * np . pi ] ) <EOL> thetad_bounds = np . array ( <EOL> [ - np . inf , - <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT> , np . inf ] ) <EOL> omega_bounds = np . array ( <EOL> [ - BalanceTask . max_tilt , - <NUM_LIT> , - <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> , <EOL> BalanceTask . max_tilt ] ) <EOL> omegad_bounds = np . array ( <EOL> [ - np . inf , - <NUM_LIT:0.5> , - <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:0.5> , np . inf ] ) <EOL> omegadd_bounds = np . array ( <EOL> [ - np . inf , - <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT> , np . inf ] ) <EOL> psi_bounds = ( np . pi / <NUM_LIT> ) * np . array ( range ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> ) ) <EOL> nbins_across_dims = [ <EOL> len ( theta_bounds ) - <NUM_LIT:1> , <EOL> len ( thetad_bounds ) - <NUM_LIT:1> , <EOL> len ( omega_bounds ) - <NUM_LIT:1> , <EOL> len ( omegad_bounds ) - <NUM_LIT:1> , <EOL> len ( omegadd_bounds ) - <NUM_LIT:1> ] <EOL> magic_array = np . cumprod ( [ <NUM_LIT:1> ] + nbins_across_dims ) [ : - <NUM_LIT:1> ] <EOL> @ property <EOL> def outdim ( self ) : <EOL> return <NUM_LIT> + <NUM_LIT:20> <EOL> def getBin ( self , theta , thetad , omega , omegad , omegadd ) : <EOL> bin_indices = [ <EOL> np . digitize ( [ theta ] , self . theta_bounds ) [ <NUM_LIT:0> ] - <NUM_LIT:1> , <EOL> np . digitize ( [ thetad ] , self . thetad_bounds ) [ <NUM_LIT:0> ] - <NUM_LIT:1> , <EOL> np . digitize ( [ omega ] , self . omega_bounds ) [ <NUM_LIT:0> ] - <NUM_LIT:1> , <EOL> np . digitize ( [ omegad ] , self . omegad_bounds ) [ <NUM_LIT:0> ] - <NUM_LIT:1> , <EOL> np . digitize ( [ omegadd ] , self . omegadd_bounds ) [ <NUM_LIT:0> ] - <NUM_LIT:1> , <EOL> ] <EOL> linear_index = np . dot ( self . magic_array , bin_indices ) <EOL> if linear_index > self . outdim - <NUM_LIT:20> : <EOL> print "<STR_LIT>" <EOL> print self . isFinished ( ) <EOL> print self . env . getTilt ( ) <EOL> print np . abs ( self . env . getTilt ( ) ) <EOL> print self . max_tilt <EOL> print np . abs ( self . env . getTilt ( ) ) > self . max_tilt <EOL> print self . env . getSensors ( ) <EOL> print self . magic_array <EOL> print self . getBinIndices ( linear_index ) <EOL> print linear_index <EOL> return linear_index <EOL> def getBinIndices ( self , linear_index ) : <EOL> """<STR_LIT>""" <EOL> return linear_index / self . magic_array % self . nbins_across_dims <EOL> def getObservation ( self ) : <EOL> ( theta , thetad , omega , omegad , omegadd , <EOL> xf , yf , xb , yb , psi ) = self . env . getSensors ( ) <EOL> top_half = one_to_n ( self . getBin ( theta , thetad , omega , omegad , omegadd ) , <EOL> self . outdim - <NUM_LIT:20> ) <EOL> bot_half = one_to_n ( np . digitize ( [ psi ] , self . psi_bounds ) [ <NUM_LIT:0> ] - <NUM_LIT:1> , <NUM_LIT:20> ) <EOL> return np . concatenate ( ( top_half , bot_half ) ) <EOL> def isFinished ( self ) : <EOL> if np . abs ( self . env . getTilt ( ) ) > self . max_tilt : <EOL> return True <EOL> dist_to_goal = self . calc_dist_to_goal ( ) <EOL> if dist_to_goal == <NUM_LIT:0> : <EOL> print '<STR_LIT>' <EOL> return True <EOL> return False <EOL> def getReward ( self ) : <EOL> r_factor = <NUM_LIT> <EOL> if np . abs ( self . env . getTilt ( ) ) > self . max_tilt : <EOL> return - <NUM_LIT:1.0> <EOL> else : <EOL> temp = self . calc_dist_to_goal ( ) <EOL> heading = self . calc_angle_to_goal ( ) <EOL> if ( temp < <NUM_LIT> ) : <EOL> return <NUM_LIT> <EOL> else : <EOL> return ( <NUM_LIT> - heading ** <NUM_LIT:2> ) * r_factor <EOL> def calc_dist_to_goal ( self ) : <EOL> x_goal = self . x_goal <EOL> y_goal = self . y_goal <EOL> r_goal = self . r_goal <EOL> xf = self . env . getXF ( ) <EOL> yf = self . env . getYF ( ) <EOL> sqrd_dist_to_goal = ( x_goal - xf ) ** <NUM_LIT:2> + ( y_goal - yf ) ** <NUM_LIT:2> <EOL> temp = np . max ( [ <NUM_LIT:0> , sqrd_dist_to_goal - r_goal ** <NUM_LIT:2> ] ) <EOL> temp = np . sqrt ( temp ) <EOL> return temp <EOL> def calc_angle_to_goal ( self ) : <EOL> x_goal = self . x_goal <EOL> y_goal = self . y_goal <EOL> xf = self . env . getXF ( ) <EOL> xb = self . env . getXB ( ) <EOL> yf = self . env . getYF ( ) <EOL> yb = self . env . getYB ( ) <EOL> temp = ( xf - xb ) * ( x_goal - xf ) + ( yf - yb ) * ( y_goal - yf ) <EOL> scalar = temp / ( <NUM_LIT:1> * np . sqrt ( ( x_goal - xf ) ** <NUM_LIT:2> + ( y_goal - yf ) ** <NUM_LIT:2> ) ) <EOL> tvaer = ( - yf + yb ) * ( x_goal - xf ) + ( xf - xb ) * ( y_goal - yf ) <EOL> if tvaer <= <NUM_LIT:0> : <EOL> temp = scalar - <NUM_LIT:1> <EOL> else : <EOL> temp = np . abs ( scalar - <NUM_LIT:1> ) <EOL> return temp <EOL> class Proportional3456ControlBalanceTask ( LinearFATileCoding3456BalanceTask ) : <EOL> def getReward ( self ) : <EOL> if np . abs ( self . env . getTilt ( ) ) > self . max_tilt : <EOL> return - <NUM_LIT:1.0> <EOL> return - np . abs ( self . env . getSensors ( ) [ <NUM_LIT:0> ] ) <EOL> class LinearFATileCoding3456GoToTaskReward1 ( LinearFATileCoding3456GoToTask ) : <EOL> e = <NUM_LIT> <EOL> def getReward ( self ) : <EOL> r_factor = <NUM_LIT> <EOL> x = np . abs ( self . env . getTilt ( ) ) <EOL> PrevTilt = np . abs ( self . env . TempTilt ) <EOL> if x > LinearFATileCoding3456BalanceTask . max_tilt : <EOL> R = - <NUM_LIT> <EOL> else : <EOL> if x < <NUM_LIT:1.0> / <NUM_LIT:3> * LinearFATileCoding3456BalanceTask . max_tilt : <EOL> R = <NUM_LIT> <EOL> elif <NUM_LIT:1.0> / <NUM_LIT:3> * LinearFATileCoding3456BalanceTask . max_tilt <= x and x <= <NUM_LIT> / <NUM_LIT:3> * LinearFATileCoding3456BalanceTask . max_tilt : <EOL> R = <NUM_LIT:1.0> <EOL> elif <NUM_LIT> / <NUM_LIT:3> * LinearFATileCoding3456BalanceTask . max_tilt <= x and x <= LinearFATileCoding3456BalanceTask . max_tilt : <EOL> R = - <NUM_LIT> <EOL> if PrevTilt > x : <EOL> R += <NUM_LIT> * ( PrevTilt - x ) <EOL> if PrevTilt > <NUM_LIT> / <NUM_LIT:3> * LinearFATileCoding3456BalanceTask . max_tilt : <EOL> R *= <NUM_LIT:2> <EOL> if PrevTilt < x : <EOL> R += <NUM_LIT> * ( PrevTilt - x ) <EOL> temp = self . calc_dist_to_goal ( ) <EOL> heading = self . calc_angle_to_goal ( ) <EOL> if ( temp < <NUM_LIT> ) : <EOL> R *= <NUM_LIT> <EOL> else : <EOL> R -= <NUM_LIT> * np . abs ( heading ) <EOL> return R <EOL> class LinearFATileCoding3456GoToTaskReward2 ( LinearFATileCoding3456GoToTask ) : <EOL> e = <NUM_LIT> <EOL> def getReward ( self ) : <EOL> r_factor = <NUM_LIT> <EOL> x = np . abs ( self . env . getTilt ( ) ) <EOL> PrevTilt = np . abs ( self . env . TempTilt ) <EOL> if x > LinearFATileCoding3456BalanceTask . max_tilt : <EOL> R = - <NUM_LIT> <EOL> else : <EOL> if x < <NUM_LIT:1.0> / <NUM_LIT:3> * LinearFATileCoding3456BalanceTask . max_tilt : <EOL> R = <NUM_LIT> <EOL> elif <NUM_LIT:1.0> / <NUM_LIT:3> * LinearFATileCoding3456BalanceTask . max_tilt <= x and x <= <NUM_LIT> / <NUM_LIT:3> * LinearFATileCoding3456BalanceTask . max_tilt : <EOL> R = <NUM_LIT:1.0> <EOL> elif <NUM_LIT> / <NUM_LIT:3> * LinearFATileCoding3456BalanceTask . max_tilt <= x and x <= LinearFATileCoding3456BalanceTask . max_tilt : <EOL> R = - <NUM_LIT> <EOL> if PrevTilt > x : <EOL> R += <NUM_LIT> * ( PrevTilt - x ) <EOL> if PrevTilt > <NUM_LIT> / <NUM_LIT:3> * LinearFATileCoding3456BalanceTask . max_tilt : <EOL> R *= <NUM_LIT:2> <EOL> if PrevTilt < x : <EOL> R += <NUM_LIT> * ( PrevTilt - x ) <EOL> temp = self . calc_dist_to_goal ( ) <EOL> heading = self . calc_angle_to_goal ( ) <EOL> if ( temp < <NUM_LIT> ) : <EOL> R *= <NUM_LIT> <EOL> else : <EOL> R -= <NUM_LIT:200> * np . abs ( heading ) <EOL> return R <EOL> class LinearFATileCoding3456GoToTaskReward3 ( LinearFATileCoding3456GoToTask ) : <EOL> e = <NUM_LIT> <EOL> def getReward ( self ) : <EOL> temp = self . calc_dist_to_goal ( ) <EOL> heading = self . calc_angle_to_goal ( ) <EOL> x = np . abs ( self . env . getTilt ( ) ) <EOL> PrevTilt = np . abs ( self . env . TempTilt ) <EOL> if x > LinearFATileCoding3456BalanceTask . max_tilt : <EOL> R = - <NUM_LIT> <EOL> else : <EOL> if x < <NUM_LIT:1.0> / <NUM_LIT:3> * LinearFATileCoding3456BalanceTask . max_tilt : <EOL> R = <NUM_LIT> <EOL> elif <NUM_LIT:1.0> / <NUM_LIT:3> * LinearFATileCoding3456BalanceTask . max_tilt <= x and x <= <NUM_LIT> / <NUM_LIT:3> * LinearFATileCoding3456BalanceTask . max_tilt : <EOL> R = <NUM_LIT:1.0> <EOL> elif <NUM_LIT> / <NUM_LIT:3> * LinearFATileCoding3456BalanceTask . max_tilt <= x and x <= LinearFATileCoding3456BalanceTask . max_tilt : <EOL> R = - <NUM_LIT> <EOL> if PrevTilt > x : <EOL> R += <NUM_LIT> * ( ( PrevTilt - x ) - np . abs ( heading ) ) <EOL> if PrevTilt > <NUM_LIT> / <NUM_LIT:3> * LinearFATileCoding3456BalanceTask . max_tilt : <EOL> R *= <NUM_LIT:2> <EOL> if PrevTilt < x : <EOL> R += <NUM_LIT> * ( PrevTilt - x ) <EOL> if ( temp < <NUM_LIT> ) : <EOL> R *= <NUM_LIT> <EOL> return R <EOL> class LinearFATileCoding3456GoToTaskReward4 ( LinearFATileCoding3456GoToTask ) : <EOL> e = <NUM_LIT> <EOL> def getReward ( self ) : <EOL> temp = self . calc_dist_to_goal ( ) <EOL> heading = self . calc_angle_to_goal ( ) <EOL> x = np . abs ( self . env . getTilt ( ) ) <EOL> PrevTilt = np . abs ( self . env . TempTilt ) <EOL> if x > LinearFATileCoding3456BalanceTask . max_tilt : <EOL> R = - <NUM_LIT> <EOL> else : <EOL> if x < <NUM_LIT:1.0> / <NUM_LIT:3> * LinearFATileCoding3456BalanceTask . max_tilt : <EOL> R = <NUM_LIT> <EOL> elif <NUM_LIT:1.0> / <NUM_LIT:3> * LinearFATileCoding3456BalanceTask . max_tilt <= x and x <= <NUM_LIT> / <NUM_LIT:3> * LinearFATileCoding3456BalanceTask . max_tilt : <EOL> R = <NUM_LIT:1.0> <EOL> elif <NUM_LIT> / <NUM_LIT:3> * LinearFATileCoding3456BalanceTask . max_tilt <= x and x <= LinearFATileCoding3456BalanceTask . max_tilt : <EOL> R = - <NUM_LIT> <EOL> if PrevTilt > x : <EOL> R += <NUM_LIT> * ( ( PrevTilt - x ) - <NUM_LIT:1.0> / <NUM_LIT:10> * np . abs ( heading ) ) <EOL> if PrevTilt > <NUM_LIT> / <NUM_LIT:3> * LinearFATileCoding3456BalanceTask . max_tilt : <EOL> R *= <NUM_LIT:2> <EOL> if PrevTilt < x : <EOL> R += <NUM_LIT> * ( PrevTilt - x ) <EOL> if ( temp < <NUM_LIT> ) : <EOL> R *= <NUM_LIT> <EOL> return R </s>
