<jupyter_start><jupyter_text>Create environment<jupyter_code>env_name = "Pendulum-v0"
env = gym.make(env_name)
env.seed(0)

state_size =  env.observation_space.shape[0]
action_size = env.action_space.shape[0]

print("State size:", state_size, "\nAction size:", action_size)
print(env.action_space.high, env.action_space.low)<jupyter_output>State size: 3 
Action size: 1
[2.] [-2.]<jupyter_text>Define parameters<jupyter_code>tmax = 500
n_episodes = 500
seed = 0<jupyter_output><empty_output><jupyter_text>TD3 Test<jupyter_code>value_net1 = models.DDPGValueNetwork(state_size, action_size, 256, 256)
value_net2 = models.DDPGValueNetwork(state_size, action_size, 256, 256)
policy_net = models.DDPGPolicyNetwork(state_size, action_size, 256, 256)

max_act = env.action_space.high
min_act = env.action_space.low
print(max_act.shape)
noise_proc = Gaussian(x_size=env.action_space.shape, 
                      mu=0., sigma_init=0.1, sigma_final=1, 
                      sigma_horizon=1)

action = env.action_space.sample()
#noise_proc = OrnsteinUhlenbeck(x0=np.zeros_like(action))

lr_val = 1e-3
lr_pol = 1e-3

agent = TD3(policy_net=policy_net,
                 value_net1=value_net1,
                 value_net2=value_net2,
                 gamma=0.99, 
                 lr_val=1e-3,
                 lr_pol=1e-3,
                 buf_size=int(1e5),
                 batch_size=64,
                 tau=1e-3,
                 device="cpu",
                 max_grad_norm=0.5,
                 min_act=min_act,
                 max_act=max_act,
                 noise_process=None,
                 warm_up=1e2,
                 policy_delay=2,
                 learn_every=1,
                 seed=0)


alg_name = "td3_{}".format(env_name)
max_score = -20.
scores = agent.train(env, tmax, n_episodes, alg_name, max_score)
plot(scores, 50)<jupyter_output><empty_output><jupyter_text>Trained Agent Demonstration<jupyter_code>agent.test(env, tmax, render=True, n_episodes=5)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.112056028014007, 'fraction_numerical': 0.03851925962981491, 'mean_word_length': 2.9215686274509802, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '77891', 'license': 'MIT', 'n_tokens_mistral': 783, 'n_tokens_neox': 728, 'n_words': 101, 'path': 'tests/td3_test.ipynb', 'repo_name': 'selim-karaduman/pytorch-drl-algs', 'size': '1999'}