Skip to content

Instantly share code, notes, and snippets.

@yardenas
yardenas / insert_slow_numpy.py
Last active December 15, 2021 20:47
insert to a big numpy array
import argparse
import timeit
from typing import Mapping, Union
import numpy as np
Transition = Mapping[str, Union[np.ndarray, dict]]
Batch = Mapping[str, np.ndarray]
@yardenas
yardenas / insert_slow_jax.py
Last active December 15, 2021 20:46
insert to big jax array
import argparse
import timeit
from typing import Mapping, Union
import jax
import jax.numpy as jnp
import numpy as np
Transition = Mapping[str, Union[np.ndarray, dict]]
Batch = Mapping[str, jnp.ndarray]
@yardenas
yardenas / nes.py
Created December 3, 2019 19:53 — forked from karpathy/nes.py
Natural Evolution Strategies (NES) toy example that optimizes a quadratic function
"""
A bare bones examples of optimizing a black-box function (f) using
Natural Evolution Strategies (NES), where the parameter distribution is a
gaussian of fixed standard deviation.
"""
import numpy as np
np.random.seed(0)
# the function we want to optimize
@yardenas
yardenas / pg-pong.py
Created December 3, 2019 19:50 — forked from karpathy/pg-pong.py
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