<s> from __future__ import print_function <EOL> from __future__ import absolute_import <EOL> from rllab . envs . base import Env , Step <EOL> from rllab . policies . gaussian_mlp_policy import GaussianMLPPolicy <EOL> from rllab . baselines . zero_baseline import ZeroBaseline <EOL> from rllab . algos . trpo import TRPO <EOL> from rllab . spaces . box import Box <EOL> import lasagne . nonlinearities <EOL> import numpy as np <EOL> import theano . tensor as TT <EOL> class DummyEnv ( Env ) : <EOL> @ property <EOL> def observation_space ( self ) : <EOL> return Box ( low = - np . inf , high = np . inf , shape = ( <NUM_LIT:1> , ) ) <EOL> @ property <EOL> def action_space ( self ) : <EOL> return Box ( low = - <NUM_LIT> , high = <NUM_LIT> , shape = ( <NUM_LIT:1> , ) ) <EOL> def reset ( self ) : <EOL> return np . zeros ( <NUM_LIT:1> ) <EOL> def step ( self , action ) : <EOL> return Step ( observation = np . zeros ( <NUM_LIT:1> ) , reward = np . random . normal ( ) , done = True ) <EOL> def naive_relu ( x ) : <EOL> return TT . max ( x , <NUM_LIT:0> ) <EOL> def test_trpo_relu_nan ( ) : <EOL> env = DummyEnv ( ) <EOL> policy = GaussianMLPPolicy ( <EOL> env_spec = env . spec , <EOL> hidden_nonlinearity = naive_relu , <EOL> hidden_sizes = ( <NUM_LIT:1> , ) ) <EOL> baseline = ZeroBaseline ( env_spec = env . spec ) <EOL> algo = TRPO ( <EOL> env = env , policy = policy , baseline = baseline , n_itr = <NUM_LIT:1> , batch_size = <NUM_LIT:1000> , max_path_length = <NUM_LIT:100> , <EOL> step_size = <NUM_LIT> <EOL> ) <EOL> algo . train ( ) <EOL> assert not np . isnan ( np . sum ( policy . get_param_values ( ) ) ) <EOL> def test_trpo_deterministic_nan ( ) : <EOL> env = DummyEnv ( ) <EOL> policy = GaussianMLPPolicy ( <EOL> env_spec = env . spec , <EOL> hidden_sizes = ( <NUM_LIT:1> , ) ) <EOL> policy . _l_log_std . param . set_value ( [ np . float32 ( np . log ( <NUM_LIT> ) ) ] ) <EOL> baseline = ZeroBaseline ( env_spec = env . spec ) <EOL> algo = TRPO ( <EOL> env = env , policy = policy , baseline = baseline , n_itr = <NUM_LIT:10> , batch_size = <NUM_LIT:1000> , max_path_length = <NUM_LIT:100> , <EOL> step_size = <NUM_LIT> <EOL> ) <EOL> algo . train ( ) <EOL> assert not np . isnan ( np . sum ( policy . get_param_values ( ) ) ) </s>
