Skip to content

Instantly share code, notes, and snippets.

View rayheberer's full-sized avatar
🏠
Working from home

Ray Heberer rayheberer

🏠
Working from home
View GitHub Profile
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split
from sklearn.ensemble import GradientBoostingRegressor
from collections import defaultdict
import numpy as np
import tensorflow as tf
def dense(x, weights, bias, activation=tf.identity, **activation_kwargs):
"""Dense layer."""
z = tf.matmul(x, weights) + bias
return activation(z, **activationn_kwargs)
@rayheberer
rayheberer / dqn_template_inprogress2.py
Last active January 1, 2020 01:51
Train step implemented
import numpy as np
import tensorflow as tf
def dense(x, weights, bias, activation=tf.identity, **activation_kwargs):
"""Dense layer."""
z = tf.matmul(x, weights) + bias
return activation(z, **activation_kwargs)
@rayheberer
rayheberer / dqn_template_inprogress01.py
Last active January 1, 2020 16:55
Mostly empty template, basic network implemented
import numpy as np
import tensorflow as tf
def dense(x, weights, bias, activation=tf.identity, **activation_kwargs):
"""Dense layer."""
z = tf.matmul(x, weights) + bias
return activation(z, **activation_kwargs)
df_lagged = df.copy()
trailing_window_size = 10
for window in range(1, trailing_window_size + 1):
shifted = df.shift(window)
shifted.columns = [x + "_lag" + str(window) for x in df.columns]
df_lagged = pd.concat((df_lagged, shifted), axis=1)
df_lagged = df_lagged.dropna()
df_lagged.head()
import numpy as np
import pandas as pd
import pandas_datareader.data as web
import datetime
start = datetime.datetime(2012, 1, 1)
end = datetime.datetime(2019, 1, 1)
df = web.DataReader("TSLA", 'yahoo', start, end)
class AtariNet(object):
# ...
# ...
def _build_optimization(self):
# ...
# ...
self.advantage = tf.subtract(
self.returns,
tf.squeeze(tf.stop_gradient(self.value_estimate)),
name="advantage")
class A2CAtari(base_agent.BaseAgent):
# ...
# ...
def _get_batch(self, terminal):
# ...
# ...
# calculate discounted rewards
raw_rewards = list(self.reward_buffer)
if terminal:
value = 0
class A2CAtari(base_agent.BaseAgent):
# ...
# ...
def _sample_action(self,
screen_features,
minimap_features,
flat_features,
available_actions):
"""Sample actions and arguments from policy output layers."""
screen_features = np.expand_dims(screen_features, 0)
class AtariNet(object):
# ...
# ...
def _build(self):
# ...
# ...
# action function identifier policy
self.function_policy = tf.squeeze(tf.layers.dense(
inputs=self.state_representation,
units=NUM_ACTIONS,