This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sample code for building a multi-layer perceptron | |
# that predicts the brightness of a light bulb based | |
# on the month, weekday, hour and minute. | |
import numpy as np | |
from keras.models import Sequential | |
from keras.layers.core import Dense, Activation | |
from keras.utils import np_utils | |
from sklearn import preprocessing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from flask import Flask | |
from flask import request | |
from flask import jsonify | |
# A simple implementation of a multi-armed bandit using Thompson Sampling. | |
class ThompsonBandit(object): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
class ContextualThompson(object): | |
def __init__(self, d=10, R=0.01, epsilon=0.5, delta=1.0, n_arms=10): | |
self.n_arms = n_arms | |
self.d = d | |
self.R = R | |
self.delta = delta | |
self.epsilon = epsilon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import sys | |
import numpy | |
from keras.models import Sequential | |
from keras.layers import Dense, Activation, Embedding, TimeDistributed, RepeatVector | |
from keras.layers import LSTM | |
from keras.callbacks import ModelCheckpoint, TensorBoard | |
from keras.utils import to_categorical |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Evolution Strategies for Reinforcement Learning | |
# See: https://blog.openai.com/evolution-strategies/ | |
import numpy as np | |
from keras.layers import Dense | |
from keras.models import Sequential | |
np.random.seed(0) | |
model = Sequential() | |
layer1 = Dense(2,input_dim=5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Skeleton pseudocode for implementation of Evolved Policy Gradients | |
# Original paper: https://arxiv.org/pdf/1802.04821.pdf | |
import numpy as np | |
lr_delta = 0.01 | |
lr_alpha = 0.01 | |
noise_stddev = 0.5 | |
K = 10 | |
discount_factor = 0.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from sklearn import linear_model | |
n_samples, n_features = 1, 500 | |
y = np.random.randn(n_samples) | |
X = np.random.randn(n_samples, n_features) | |
clf = linear_model.SGDRegressor() | |
import time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import types | |
from pandas.api.types import is_string_dtype | |
from pandas.api.types import is_numeric_dtype | |
from tqdm import tqdm | |
def df_to_vw_regression(df, filepath='in.txt', sample_weights=None, columns=None, target=None, namespace='namespace'): | |
if columns is None: | |
columns = df.columns.tolist() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python implementation of the EXP3 (Exponential weight for Exploration and Exploitation) | |
# algorithm for solving adversarial bandit problems. Based on the original paper: | |
# http://rob.schapire.net/papers/AuerCeFrSc01.pdf | |
import numpy as np | |
import time | |
np.random.seed(12345) | |
n_arms = 4 |
OlderNewer