<s> """<STR_LIT>""" <EOL> from . Domain import Domain <EOL> import numpy as np <EOL> from scipy . integrate import odeint <EOL> from rlpy . Tools import plt <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 HIVTreatment ( Domain ) : <EOL> """<STR_LIT>""" <EOL> state_names = ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:E>" ) <EOL> discount_factor = <NUM_LIT> <EOL> continuous_dims = np . arange ( <NUM_LIT:6> ) <EOL> actions = np . array ( [ [ <NUM_LIT:0.> , <NUM_LIT:0.> ] , [ <NUM_LIT> , <NUM_LIT:0.> ] , [ <NUM_LIT:0.> , <NUM_LIT> ] , [ <NUM_LIT> , <NUM_LIT> ] ] ) <EOL> actions_num = <NUM_LIT:4> <EOL> episodeCap = <NUM_LIT:200> <EOL> dt = <NUM_LIT:5> <EOL> logspace = True <EOL> show_domain_every = <NUM_LIT:20> <EOL> episode_data = np . zeros ( ( <NUM_LIT:7> , episodeCap + <NUM_LIT:1> ) ) <EOL> if logspace : <EOL> statespace_limits = np . array ( [ [ - <NUM_LIT:5> , <NUM_LIT:8> ] ] * <NUM_LIT:6> ) <EOL> else : <EOL> statespace_limits = np . array ( [ [ <NUM_LIT:0.> , <NUM_LIT> ] ] * <NUM_LIT:6> ) <EOL> def step ( self , a ) : <EOL> self . t += <NUM_LIT:1> <EOL> eps1 , eps2 = self . actions [ a ] <EOL> ns = odeint ( dsdt , self . state , [ <NUM_LIT:0> , self . dt ] , <EOL> args = ( eps1 , eps2 ) , mxstep = <NUM_LIT:1000> ) [ - <NUM_LIT:1> ] <EOL> T1 , T2 , T1s , T2s , V , E = ns <EOL> reward = - <NUM_LIT:0.1> * V - <NUM_LIT> * eps1 ** <NUM_LIT:2> - <NUM_LIT> * eps2 ** <NUM_LIT:2> + <NUM_LIT> * E <EOL> self . state = ns . copy ( ) <EOL> if self . logspace : <EOL> ns = np . log10 ( ns ) <EOL> self . episode_data [ : - <NUM_LIT:1> , self . t ] = self . state <EOL> self . episode_data [ - <NUM_LIT:1> , self . t - <NUM_LIT:1> ] = a <EOL> return reward , ns , False , self . possibleActions ( ) <EOL> def possibleActions ( self ) : <EOL> return np . arange ( <NUM_LIT:4> ) <EOL> def s0 ( self ) : <EOL> self . t = <NUM_LIT:0> <EOL> self . episode_data [ : ] = np . nan <EOL> s = np . array ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> self . state = s . copy ( ) <EOL> if self . logspace : <EOL> return np . log10 ( s ) , self . isTerminal ( ) , self . possibleActions ( ) <EOL> self . episode_data [ : - <NUM_LIT:1> , <NUM_LIT:0> ] = s <EOL> return s , self . isTerminal ( ) , self . possibleActions ( ) <EOL> def showDomain ( self , a = <NUM_LIT:0> , s = None ) : <EOL> """<STR_LIT>""" <EOL> if self . t % self . show_domain_every != <NUM_LIT:0> and not self . t >= self . episodeCap : <EOL> return <EOL> n = self . state_space_dims + <NUM_LIT:1> <EOL> names = list ( self . state_names ) + [ "<STR_LIT>" ] <EOL> colors = [ "<STR_LIT:b>" , "<STR_LIT:b>" , "<STR_LIT:b>" , "<STR_LIT:b>" , "<STR_LIT:r>" , "<STR_LIT:g>" , "<STR_LIT:k>" ] <EOL> handles = getattr ( self , "<STR_LIT>" , None ) <EOL> plt . figure ( "<STR_LIT>" , figsize = ( <NUM_LIT:12> , <NUM_LIT:10> ) ) <EOL> if handles is None : <EOL> handles = [ ] <EOL> f , axes = plt . subplots ( <EOL> n , sharex = True , num = "<STR_LIT>" , figsize = ( <NUM_LIT:12> , <NUM_LIT:10> ) ) <EOL> f . subplots_adjust ( hspace = <NUM_LIT:0.1> ) <EOL> for i in range ( n ) : <EOL> ax = axes [ i ] <EOL> d = np . arange ( self . episodeCap + <NUM_LIT:1> ) * <NUM_LIT:5> <EOL> ax . set_ylabel ( names [ i ] ) <EOL> ax . locator_params ( tight = True , nbins = <NUM_LIT:4> ) <EOL> handles . append ( <EOL> ax . plot ( d , <EOL> self . episode_data [ i ] , <EOL> color = colors [ i ] ) [ <NUM_LIT:0> ] ) <EOL> self . _state_graph_handles = handles <EOL> ax . set_xlabel ( "<STR_LIT>" ) <EOL> for i in range ( n ) : <EOL> handles [ i ] . set_ydata ( self . episode_data [ i ] ) <EOL> ax = handles [ i ] . get_axes ( ) <EOL> ax . relim ( ) <EOL> ax . autoscale_view ( ) <EOL> plt . draw ( ) <EOL> def dsdt ( s , t , eps1 , eps2 ) : <EOL> """<STR_LIT>""" <EOL> lambda1 = <NUM_LIT> <EOL> lambda2 = <NUM_LIT> <EOL> d1 = <NUM_LIT> <EOL> d2 = <NUM_LIT> <EOL> f = <NUM_LIT> <EOL> k1 = <NUM_LIT> <EOL> k2 = <NUM_LIT> <EOL> delta = <NUM_LIT> <EOL> m1 = <NUM_LIT> <EOL> m2 = <NUM_LIT> <EOL> NT = <NUM_LIT> <EOL> c = <NUM_LIT> <EOL> rho1 = <NUM_LIT:1.> <EOL> rho2 = <NUM_LIT:1.> <EOL> lambdaE = <NUM_LIT:1> <EOL> bE = <NUM_LIT> <EOL> Kb = <NUM_LIT:100> <EOL> d_E = <NUM_LIT> <EOL> Kd = <NUM_LIT> <EOL> deltaE = <NUM_LIT:0.1> <EOL> T1 , T2 , T1s , T2s , V , E = s <EOL> tmp1 = ( <NUM_LIT:1.> - eps1 ) * k1 * V * T1 <EOL> tmp2 = ( <NUM_LIT:1.> - f * eps1 ) * k2 * V * T2 <EOL> dT1 = lambda1 - d1 * T1 - tmp1 <EOL> dT2 = lambda2 - d2 * T2 - tmp2 <EOL> dT1s = tmp1 - delta * T1s - m1 * E * T1s <EOL> dT2s = tmp2 - delta * T2s - m2 * E * T2s <EOL> dV = ( <NUM_LIT:1.> - eps2 ) * NT * delta * ( T1s + T2s ) - c * V - ( ( <NUM_LIT:1.> - eps1 ) * rho1 * k1 * T1 + <EOL> ( <NUM_LIT:1.> - f * eps1 ) * rho2 * k2 * T2 ) * V <EOL> dE = lambdaE + bE * ( T1s + T2s ) / ( T1s + T2s + Kb ) * E - d_E * ( T1s + T2s ) / ( T1s + T2s + Kd ) * E - deltaE * E <EOL> return np . array ( [ dT1 , dT2 , dT1s , dT2s , dV , dE ] ) <EOL> try : <EOL> from HIVTreatment_dynamics import dsdt <EOL> except Exception as e : <EOL> print e <EOL> print "<STR_LIT>" </s>
