<s> from rlpy . Domains import GridWorld <EOL> from rlpy . Representations import Tabular <EOL> from scipy . optimize import check_grad , approx_fprime <EOL> from rlpy . Policies . gibbs import GibbsPolicy <EOL> import numpy as np <EOL> def test_fdcheck_dlogpi ( ) : <EOL> """<STR_LIT>""" <EOL> logger = Logger ( ) <EOL> domain = GridWorld ( ) <EOL> representation = Tabular ( logger = logger , domain = domain , discretization = <NUM_LIT:20> ) <EOL> policy = GibbsPolicy ( representation = representation , logger = logger ) <EOL> def f ( theta , s , a ) : <EOL> policy . representation . theta = theta <EOL> return np . log ( policy . prob ( s , a ) ) <EOL> def df ( theta , s , a ) : <EOL> policy . representation . theta = theta <EOL> return policy . dlogpi ( s , a ) <EOL> def df_approx ( theta , s , a ) : <EOL> return approx_fprime ( theta , f , <NUM_LIT> , s , a ) <EOL> thetas = np . random . rand ( <NUM_LIT:10> , len ( representation . theta ) ) <EOL> for i in range ( <NUM_LIT:10> ) : <EOL> s = np . array ( [ np . random . randint ( <NUM_LIT:4> ) , np . random . randint ( <NUM_LIT:5> ) ] ) <EOL> a = np . random . choice ( domain . possibleActions ( s ) ) <EOL> for theta in thetas : <EOL> error = check_grad ( f , df , theta , s , a ) <EOL> print error <EOL> assert np . abs ( error ) < <NUM_LIT> </s>
