Skip to content

Instantly share code, notes, and snippets.

View sharavsambuu's full-sized avatar

sharavsambuu sharavsambuu

View GitHub Profile
@sharavsambuu
sharavsambuu / PG.py
Created November 10, 2018 02:55 — forked from MikeOuimet/PG.py
Vanilla policy gradient with tensorflow
import numpy as np
import gym
import tensorflow as tf
import matplotlib.pyplot as plt
def weight_variable(shape):
initial = tf.truncated_normal(shape, stddev=0.1)
return tf.Variable(initial)
def bias_variable(shape):
@sharavsambuu
sharavsambuu / beamsearch_decoder.py
Created July 9, 2018 13:57 — forked from chao-ji/beamsearch_decoder.py
Easy to understand implementation of beam search algorithm used in decoder of seq2seq models
"""
Easy-to-understand implementation of Beam Search algorithm used in decoder of
seq2seq models (e.g. NMT). Results compared with tensorflow implementation
(1.5.0) (`tf.contrib.seq2seq.BeamSearchDecoder`)
"""
import tensorflow as tf
import numpy as np
import heapq
import collections
brew install autoconf automake libtool protobuf
git clone --depth=1 https://github.com/google/sentencepiece.git /tmp/sentencepiece
cd /tmp/sentencepiece
./autogen.sh
./configure
make
make check
sudo make install
@sharavsambuu
sharavsambuu / montecarlointegration.py
Last active June 13, 2018 20:16
Monte Carlo Integration
import math
import numpy as np
def f(x):
return (
float(3*x*x*x-x*x+2*x-4)/
float(math.sqrt(x*x-3*x+2)))
def montecarlo_integration(
floor_value,
@sharavsambuu
sharavsambuu / Matrix.md
Created May 27, 2018 18:43 — forked from nadavrot/Matrix.md
Efficient matrix multiplication

High-Performance Matrix Multiplication

This is a short post that explains how to write a high-performance matrix multiplication program on modern processors. In this tutorial I will use a single core of the Skylake-client CPU with AVX2, but the principles in this post also apply to other processors with different instruction sets (such as AVX512).

Intro

Matrix multiplication is a mathematical operation that defines the product of

# source : https://www.electricmonk.nl/log/2011/09/28/evolutionary-algorithm-evolving-hello-world/
import random
import string
source = "jijvdvnmertnj"
target = "Hello, World!"
def calc_fitness(source, target):
fitval = 0
for i in range(0, len(source)):
@sharavsambuu
sharavsambuu / CartPole-REINFORCE-MCMC.py
Created May 5, 2018 03:40 — forked from Adriel-M/CartPole-REINFORCE-MCMC.py
REINFORCE: Monte Carlo Policy Gradient solution to Cartpole-v0 with a hidden layer.
# REINFORCE: Monte Carlo Policy Gradient Implementation
# Learn more from Reinforcement Learning: An Introduction (p271)
# by Sutton & Barto
import tensorflow as tf
import gym
import numpy as np
from gym import wrappers
@sharavsambuu
sharavsambuu / smallpt_tf.py
Created May 5, 2018 02:31
small pathtracer implemented by using tensorflow
# coding: utf-8
"""
シンプルなパストレーサー
cf. http://www.kevinbeason.com/smallpt/
"""
import shutil
import numpy as np
import tensorflow as tf
@sharavsambuu
sharavsambuu / keras_pg.py
Created May 1, 2018 04:18 — forked from calclavia/keras_pg.py
Monte Carlo Policy Gradient in Keras
import gym
import numpy as np
from keras.models import Model
from keras.layers import *
from keras import backend as K
from collections import deque
def one_hot(index, categories):
@sharavsambuu
sharavsambuu / rl_pong.py
Last active April 30, 2018 09:15 — forked from greydanus/rl_pong.py
Solves Pong with Policy Gradients in Tensorflow.
'''Solves Pong with Policy Gradients in Tensorflow.'''
# written October 2016 by Sam Greydanus
# inspired by karpathy's gist.github.com/karpathy/a4166c7fe253700972fcbc77e4ea32c5
import numpy as np
import gym
import tensorflow as tf
# hyperparameters
n_obs = 80 * 80 # dimensionality of observations
h = 200 # number of hidden layer neurons