<jupyter_start><jupyter_text>Running agent on pretrained weights<jupyter_code>from unityagents import UnityEnvironment
from collections import deque
from ddpg_agent import Agent
import torch
import numpy as np<jupyter_output><empty_output><jupyter_text>Load environment<jupyter_code>env = UnityEnvironment(file_name="./Reacher_Windows_x86_64/Reacher.exe")
# get the default brain
brain_name = env.brain_names[0]
brain = env.brains[brain_name]<jupyter_output><empty_output><jupyter_text>Initialize agent and necessary variables<jupyter_code>params = {
"BUFFER_SIZE":int(1e5),  # replay buffer size
"BATCH_SIZE":128,       # minibatch size
"GAMMA":0.99,            # discount factor
"TAU":1e-3,              # for soft update of target parameters
"LR_ACTOR":0.0001,         # learning rate of the actor 
"LR_CRITIC":0.0001,        # learning rate of the critic
"WEIGHT_DECAY":0.0001   # L2 weight decay
}

agent = Agent(n = 20, state_size=33, action_size=4, random_seed=42, params=params)
# Load the weights from file
agent.actor_local.load_state_dict(torch.load('actor.pth'))
agent.critic_local.load_state_dict(torch.load('critic.pth'))
agent.actor_target.load_state_dict(torch.load('actor.pth'))
agent.critic_target.load_state_dict(torch.load('critic.pth'))
score = [] 
env_info = env.reset(train_mode=False)[brain_name]
states = env_info.vector_observations<jupyter_output><empty_output><jupyter_text>Let the agent do it's job<jupyter_code>while True:
    actions = agent.act(states)
    env_info = env.step(actions)[brain_name]            # send all actions to tne environment
    next_states = env_info.vector_observations          # get next states
    rewards = env_info.rewards                       # get reward
    dones = env_info.local_done                         # see if episode finished
    agent.step(states, actions, rewards, next_states, dones)
    states = next_states
    score += rewards                           # update the score 
    if np.any(dones):
        break 

print("Score: {}".format(np.mean(score)))
env.close()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10361445783132531, 'fraction_numerical': 0.018313253012048194, 'mean_word_length': 4.177057356608479, 'pattern_counts': {'":': 7, '<': 17, '<?xml version=': 0, '>': 17, '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': '549122', 'license': 'MIT', 'n_tokens_mistral': 707, 'n_tokens_neox': 675, 'n_words': 139, 'path': 'Watch_Agent.ipynb', 'repo_name': 'KrainskiL/UnityML_RoboticArm', 'size': '2075'}