Skip to content

Instantly share code, notes, and snippets.

@nagataka
nagataka / math_in_english.md
Created February 28, 2021 15:06
数学表現 in English
@nagataka
nagataka / study_lstm.md
Last active February 6, 2021 01:24
Studying LSTM
@nagataka
nagataka / blocking_maze_env01.py
Last active January 15, 2021 05:33
Blocking Maze for OpenAI Gym
# OpenAI gym custom environment mimicking Blocking Maze
# See Sutton and Barto "Reinforcement Learning an Introduction"
# Example 8.2: Blocking Maze
from enum import Enum
import sys
import copy
import gym
from gym import error, spaces, utils
from gym.utils import seeding
@nagataka
nagataka / settings.json
Created September 4, 2020 22:55
VS Code settings.json
{
"python.formatting.provider": "black",
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.linting.flake8Args": [
"--ignore=E501,W503"
],
"python.sortImports.args": [
"-m 3"
],
@nagataka
nagataka / kelly_criterion.py
Created May 11, 2020 05:34
Experiment on coin flipping game
import random
import numpy as np
np.random.seed(0)
def kerri(p, b):
"""https://en.wikipedia.org/wiki/Kelly_criterion
"""
return (p*(b+1)-1 )/b
N = 300
@nagataka
nagataka / minimal_rllib.py
Created April 21, 2020 22:15
Initial example of using RLlib
import gym
import ray
from ray.rllib.agents.ppo import PPOTrainer, DEFAULT_CONFIG
import pprint as pp
#tune.run(PPOTrainer, config={"env": "Breakout-v0", "use_pytorch": True})
ray.init(num_gpus=1, ignore_reinit_error=True, log_to_driver=False)
# https://github.com/ray-project/ray/blob/master/rllib/agents/ppo/ppo.py#L15
@nagataka
nagataka / notify_slack.sh
Created March 4, 2020 19:28
Send a slack notification
#!/bin/bash
set -eu
### Incoming WebHooks URL
WEBHOOKURL="https://hooks.slack.com/services/FILL_YOUR_WEBHOOKURL"
### channel
CHANNEL=${CHANNEL:-"#notifications"}
@nagataka
nagataka / README.md
Last active November 20, 2019 19:23
README_template.md

The repository is organized as follows:

  • src : Contains the source codes for all .... The source code is written in Python and it takes advantage of Numpy and Matplotlib. In order to run a simulation you have to use the file run_xxxx.py.

  • tools: In this folder you can find some tools for.... With yyy.py you can reproduce the figures found in ().

  • data: Here are saved all the results once you run a simulation.

  • params: Here you can find all the configuration files containing all the parameters (for each experiments).

@nagataka
nagataka / gym_template.py
Last active April 10, 2020 01:13
A template to start a project using OpenAI gym with PyTorch
"""A template to implement RL agent with OpenAI Gym
Usage: python ./gym_template.py --env=CarRacing-v0 --algo=policy_gradient --epochs 1
implementation of algorithms need to be ./algorithms/ directory, or change the following line to your env
> algo = import_module('algorithms.'+args.algo)
"""
import argparse
import numpy as np
@nagataka
nagataka / policy_evaluation.py
Created September 5, 2019 02:12
RL book: Grid World example (Figure 4.1)
import gym
import sys
sys.path.append("reinforcement-learning/lib/envs")
import gridworld
import random
import numpy as np
import copy
NUM_EPOCHS = 10000
GAMMA = 1.0