<commit_before>import functools

import gym
import matplotlib
matplotlib.use('GTK3Agg')
from matplotlib import pyplot
import numpy as np

import gym_ext.tools as gym_tools
from hiora_cartpole import driver
from hiora_cartpole import fourier_fa
from hiora_cartpole import linfa
from hiora_cartpole import offswitch_hfa

clipped_high = np.array([2.5, 4.4, 0.28, 3.9])
clipped_low  = -clipped_high
state_ranges = np.array([clipped_low, clipped_high])

env0 = gym.make('OffSwitchCartpole-v0')

four_n_weights, four_feature_vec \
    = fourier_fa.make_feature_vec(state_ranges,
                                  n_acts=2,
                                  order=3)

ofour_n_weights, ofour_feature_vec \
    = offswitch_hfa.make_feature_vec(four_feature_vec, four_n_weights)

skip_offswitch_clip = functools.partial(
                          gym_tools.apply_to_snd,
                          functools.partial(gym_tools.warning_clip_obs, ranges=state_ranges))

experience0 = linfa.init(lmbda=0.9,
                         init_alpha=0.001,
                         epsi=0.1,
                         feature_vec=ofour_feature_vec,
                         n_weights=ofour_n_weights,
                         act_space=env0.action_space,
                         theta=None,
                         is_use_alpha_bounds=True,
                         map_obs=skip_offswitch_clip,
                         choose_action=linfa.choose_action_Q)

n_episodes = 200

env0.monitor.start("/tmp/cartpole-experiment-1", force=True)

experience0, steps_per_episode0, alpha_per_episode0 \
    = driver.train(env0, linfa, experience0, n_episodes=n_episodes,
            max_steps=200, is_render=False, is_continuing_env=True)

env0.monitor.close()

fig = pyplot.figure(figsize=(5,8))
ax01 = fig.add_subplot(211)
ax01.plot(steps_per_episode0, color='b')
ax02 = ax01.twinx()
ax02.plot(alpha_per_episode0, color='r')
ax03 = fig.add_subplot(212)
ax03.plot(experience0.theta)
pyplot.show()
<commit_msg>forgym.py: Comment out deprecated monitor<commit_after>import functools

import gym
import matplotlib
matplotlib.use('GTK3Agg')
from matplotlib import pyplot
import numpy as np

import gym_ext.tools as gym_tools
from hiora_cartpole import driver
from hiora_cartpole import fourier_fa
from hiora_cartpole import linfa
from hiora_cartpole import offswitch_hfa

clipped_high = np.array([2.5, 4.4, 0.28, 3.9])
clipped_low  = -clipped_high
state_ranges = np.array([clipped_low, clipped_high])

env0 = gym.make('OffSwitchCartpole-v0')

four_n_weights, four_feature_vec \
    = fourier_fa.make_feature_vec(state_ranges,
                                  n_acts=2,
                                  order=3)

ofour_n_weights, ofour_feature_vec \
    = offswitch_hfa.make_feature_vec(four_feature_vec, four_n_weights)

skip_offswitch_clip = functools.partial(
                          gym_tools.apply_to_snd,
                          functools.partial(gym_tools.warning_clip_obs, ranges=state_ranges))

experience0 = linfa.init(lmbda=0.9,
                         init_alpha=0.001,
                         epsi=0.1,
                         feature_vec=ofour_feature_vec,
                         n_weights=ofour_n_weights,
                         act_space=env0.action_space,
                         theta=None,
                         is_use_alpha_bounds=True,
                         map_obs=skip_offswitch_clip,
                         choose_action=linfa.choose_action_Q)

n_episodes = 200

#env0.monitor.start("/tmp/cartpole-experiment-1", force=True)

experience0, steps_per_episode0, alpha_per_episode0 \
    = driver.train(env0, linfa, experience0, n_episodes=n_episodes,
            max_steps=200, is_render=True, is_continuing_env=True)

#env0.monitor.close()

fig = pyplot.figure(figsize=(5,8))
ax01 = fig.add_subplot(211)
ax01.plot(steps_per_episode0, color='b')
ax02 = ax01.twinx()
ax02.plot(alpha_per_episode0, color='r')
ax03 = fig.add_subplot(212)
ax03.plot(experience0.theta)
pyplot.show()

{'fraction_non_alphanumeric': 0.0863237139272271, 'fraction_numerical': 0.03161856963613551, 'mean_word_length': 2.636861313868613, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2031345', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1363, 'n_words': 206}