<commit_before>import multiprocessing as mp
import os
import argparse
import random

import numpy as np

import chainer
from chainer import optimizers

import policy
import nstep_q_learning
import xor
import random_seed
import async
import rmsprop_ones
import q_function


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('processes', type=int)
    parser.add_argument('--seed', type=int, default=None)
    parser.add_argument('--steps', type=int, default=1000)
    parser.add_argument('--lr', type=float, default=1e-3)
    parser.add_argument('--t-max', type=int, default=5)
    parser.add_argument('--gamma', type=float, default=0.9)
    parser.add_argument('--epsilon', type=float, default=0.1)
    args = parser.parse_args()

    if args.seed is not None:
        random_seed.set_random_seed(args.seed)

    def agent_func():
        q_func = q_function.FCSIQFunction(2, 2, 10, 2)
        opt = rmsprop_ones.RMSpropOnes(lr=args.lr)
        opt.setup(q_func)
        return nstep_q_learning.NStepQLearning(q_func, opt, args.t_max,
            args.gamma, args.epsilon)

    def env_func():
        return xor.XOR()

    def run_func(agent, env):
        total_r = 0
        episode_r = 0

        for i in xrange(args.steps):

            total_r += env.reward
            episode_r += env.reward

            action = agent.act(env.state, env.reward, env.is_terminal)

            if env.is_terminal:
                print 'i:{} episode_r:{}'.format(i, episode_r)<commit_msg>Confirm N-step Q-learning can solve DelayedXOR<commit_after>import multiprocessing as mp
import os
import argparse
import random

import numpy as np

import chainer
from chainer import optimizers

import policy
import nstep_q_learning
import xor
import delayed_xor
import random_seed
import async
import rmsprop_ones
import q_function


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('processes', type=int)
    parser.add_argument('--seed', type=int, default=None)
    parser.add_argument('--steps', type=int, default=1000)
    parser.add_argument('--lr', type=float, default=1e-3)
    parser.add_argument('--t-max', type=int, default=5)
    parser.add_argument('--gamma', type=float, default=0.9)
    parser.add_argument('--epsilon', type=float, default=0.1)
    args = parser.parse_args()

    if args.seed is not None:
        random_seed.set_random_seed(args.seed)

    def agent_func():
        q_func = q_function.FCSIQFunction(3, 2, 10, 2)
        opt = rmsprop_ones.RMSpropOnes(lr=args.lr)
        opt.setup(q_func)
        return nstep_q_learning.NStepQLearning(q_func, opt, args.t_max,
            args.gamma, args.epsilon, i_target=args.steps / 100)

    def env_func():
        return delayed_xor.DelayedXOR(5)

    def run_func(agent, env):
        total_r = 0
        episode_r = 0

        for i in xrange(args.steps):

            total_r += env.reward
            episode_r += env.reward

            action = agent.act(env.state, env.reward, env.is_terminal)

            if env.is_terminal:
                print 'i:{} episode_r:{}'.format(i, episode_r)
{'fraction_non_alphanumeric': 0.11207729468599034, 'fraction_numerical': 0.01288244766505636, 'mean_word_length': 3.028534370946822, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1291218', 'n_tokens_mistral': 1069, 'n_tokens_neox': 1025, 'n_words': 230}