Skip to content

Instantly share code, notes, and snippets.

@kkweon
kkweon / simple_a3c.py
Created May 21, 2017 21:41
Simple A3C (distributed tensorflow version is preferred over threading)
import tensorflow as tf
import numpy as np
import threading
import gym
import os
from scipy.misc import imresize
def copy_src_to_dst(from_scope, to_scope):
"""Creates a copy variable weights operation
@hetelek
hetelek / noisy_cartpole.py
Created April 12, 2017 21:51
Attempt to solve Cart Pole by adding random noise to the best weights.
import tensorflow as tf
import gym
stddev = 1.0
render = True
monitor = True
best_weights = tf.Variable(tf.truncated_normal(shape=[4, 1]))
current_weights = tf.Variable(best_weights.initialized_value())
@ffrige
ffrige / CartPole-v1.py
Last active January 23, 2023 17:09
OpenAIGym\CartPole-v1
"""
Solves the cartpole-v1 enviroment on OpenAI gym using policy search
Same algorithm as for cartpole-v0
A neural network is used to store the policy
At the end of each episode the target value for each taken action is
updated with the total normalized reward (up to a learning rate)
@sparseinference
sparseinference / cartpolev1.py
Created March 9, 2017 15:05
Solution for OpenAI problem "CartPole-V1".
"""
File: cartpolev1.py
Created: 2017-03-09
By Peter Caven, peter@sparseinference.com
Description:
-- Python 3.6 --
Solve the CartPole-v1 problem:
- this is the same solution as for the 'CartPole-v0' problem, with the episode length extended.
@karpathy
karpathy / pg-pong.py
Created May 30, 2016 22:50
Training a Neural Network ATARI Pong agent with Policy Gradients from raw pixels
""" Trains an agent with (stochastic) Policy Gradients on Pong. Uses OpenAI Gym. """
import numpy as np
import cPickle as pickle
import gym
# hyperparameters
H = 200 # number of hidden layer neurons
batch_size = 10 # every how many episodes to do a param update?
learning_rate = 1e-4
gamma = 0.99 # discount factor for reward
@karpathy
karpathy / min-char-rnn.py
Last active May 17, 2024 12:51
Minimal character-level language model with a Vanilla Recurrent Neural Network, in Python/numpy
"""
Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy)
BSD License
"""
import numpy as np
# data I/O
data = open('input.txt', 'r').read() # should be simple plain text file
chars = list(set(data))
data_size, vocab_size = len(data), len(chars)