Skip to content

Instantly share code, notes, and snippets.

@talolard
talolard / prepare_dataset.py
Last active March 8, 2018 14:16
Making a dataset
import tensorflow as tf
from preppy import BibPreppy
def expand(x):
'''
Hack. Because padded_batch doesn't play nice with scalres, so we expand the scalar to a vector of length 1
:param x:
:return:
@talolard
talolard / UsingIterators.py
Last active February 19, 2018 14:04
Example of using dataset and iterators to the train and val
if __name__=="__main__":
#make the iterators and next element op
next_element, training_init_op, validation_init_op = prepare_dataset_iterators(batch_size=32)
...
for epoch in range(1000):
#Initialize the iterator to consume training data
sess.run(training_init_op)
while True:
#As long as the iterator is not empty
@talolard
talolard / convert_to_json.py
Created March 23, 2018 17:10
Converting csv to json
import pandas as pd
D = pd.read_csv('./my_csv_file.csv')
D.to_json('./my_new_json_file.json',orient="records")
@talolard
talolard / last_semver.py
Created June 5, 2018 19:46
Get the most recent semver tag for an ECR repo
import pprint
import boto3
import sys
repo_name = sys.argv[1]
print(repo_name)
client = boto3.client('ecr')
response = client.list_images(
repositoryName=repo_name,
filter={
'tagStatus': 'TAGGED'
@talolard
talolard / magic_market.py
Created January 14, 2019 10:36
How to make a market that is complex but learnable
import numpy as np
def make_stock(length=100, num_stocks=2):
alpha = 0.9
k = 2
cov = np.random.normal(0, 5, [num_stocks, num_stocks])
cov = cov.dot(cov.T) # This is a positive semidefinite matrix, e.g. a covariance matrix
A = np.random.multivariate_normal(np.zeros(num_stocks), cov, size=[length]) # sample noise, with covariance
B = np.random.multivariate_normal(np.zeros(num_stocks), cov, size=[length]) # sample another noise, with covariance
bs = [np.zeros(shape=num_stocks)] #
ps = [np.zeros(shape=num_stocks)] # The prices
@talolard
talolard / crappy_env.py
Created January 14, 2019 10:54
A crappy environemtn for RL on a portfolio of stocks
import numpy as np
from collections import defaultdict
from env.priceGenerator import make_stock
costPerShare = 0 # 0.01
class Env:
'''
A simple environemnt for our agent,
the action our agent gives is weighting over the stocks + cash
@talolard
talolard / dirichlet.py
Created January 14, 2019 11:10
Sampling a portfolio from a dirichlet distribution
self.alphas= tf.contrib.layers.fully_connected(
inputs=l2,
num_outputs=num_stocks+1,
activation_fn=tf.nn.relu,
weights_initializer=tf.initializers.glorot_uniform)
self.alphas +=1
self.dirichlet = tfp.distributions.Dirichlet(self.alphas)
self.action = self.dirichlet._sample_n(1)
@talolard
talolard / al.ipynb
Created January 17, 2019 09:35
Notebok showing active learning is dumb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@talolard
talolard / replacingWordsWithTags.ipynb
Last active February 28, 2019 12:07
replacingWordsWithTags.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@talolard
talolard / install-docker-compose.sh
Last active September 19, 2019 13:15 — forked from benfogel/install-docker-compose.sh
Installing docker-compose on Amazon Linux AMI
sudo yum update -y
sudo yum install -y docker
sudo usermod -a -G docker ec2-user
sudo curl -L https://github.com/docker/compose/releases/download/1.21.0/docker-compose-`uname -s`-`uname -m` | sudo tee /usr/local/bin/docker-compose > /dev/null
sudo chmod +x /usr/local/bin/docker-compose
sudo service docker start
sudo chkconfig docker on
sudo systemctl enable docker