<jupyter_start><jupyter_text>gym initilize<jupyter_code>env = gym.make('FrozenLake-v0')
Q = np.zeros([env.observation_space.n, env.action_space.n])
learning_rate = 0.85
alpha = 0.99
num_episodes = 2000
reward_log = []

for epoch in range(num_episodes):
    s = env.reset()   # episode initilize
    rAll = 0
    
    action_in_episode = 0
    while action_in_episode < 99:
        action_in_episode += 1
        
        # choose action & add noise
        noise_q_action = np.random.randn(1,env.action_space.n)*(1./(epoch+1))
        a = np.argmax(Q[s,:] + noise_q_action) 
        
        # get new state
        s1, reward, done, _ = env.step(a)
        
        # udpate Q table
        Q[s,a] = Q[s,a] + learning_rate * (reward + alpha*np.max(Q[s1,:]) - Q[s,a])
        rAll += reward
        s = s1
        
        # check done
        if done == True:
            break
    reward_log.append(rAll)
reward_log_mean = movingAverage(reward_log, 20)
plt.plot(reward_log_mean)
reward_log = []

for epoch in range(num_episodes):
    s = env.reset()   # episode initilize
    rAll = 0
    
    action_in_episode = 0
    while action_in_episode < 99:
        action_in_episode += 1
        
        # choose action & add noise
        a = np.argmax(Q[s,:]) 
        
        # get new state
        s1, reward, done, _ = env.step(a)
        
        # udpate Q table
        rAll += reward
        s = s1
        
        # check done
        if done == True:
            break
    reward_log.append(rAll)
reward_log_mean = movingAverage(reward_log, 20)
plt.plot(reward_log_mean)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11180124223602485, 'fraction_numerical': 0.020496894409937887, 'mean_word_length': 2.0511363636363638, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '588589', 'license': 'MIT', 'n_tokens_mistral': 629, 'n_tokens_neox': 594, 'n_words': 119, 'path': '0_Q_learning_agent/Q-Table_learning.ipynb', 'repo_name': 'hatter30/tutorial_reinforcement_learning', 'size': '1610'}