Code for Keras plays catch blog post
python qlearn.py- Generate figures
| #Source code with the blog post at http://monik.in/a-noobs-guide-to-implementing-rnn-lstm-using-tensorflow/ | |
| import numpy as np | |
| import random | |
| from random import shuffle | |
| import tensorflow as tf | |
| # from tensorflow.models.rnn import rnn_cell | |
| # from tensorflow.models.rnn import rnn | |
| NUM_EXAMPLES = 10000 |
| '''This script goes along the blog post | |
| "Building powerful image classification models using very little data" | |
| from blog.keras.io. | |
| It uses data that can be downloaded at: | |
| https://www.kaggle.com/c/dogs-vs-cats/data | |
| In our setup, we: | |
| - created a data/ folder | |
| - created train/ and validation/ subfolders inside data/ | |
| - created cats/ and dogs/ subfolders inside train/ and validation/ | |
| - put the cat pictures index 0-999 in data/train/cats |
| '''This script goes along the blog post | |
| "Building powerful image classification models using very little data" | |
| from blog.keras.io. | |
| It uses data that can be downloaded at: | |
| https://www.kaggle.com/c/dogs-vs-cats/data | |
| In our setup, we: | |
| - created a data/ folder | |
| - created train/ and validation/ subfolders inside data/ | |
| - created cats/ and dogs/ subfolders inside train/ and validation/ | |
| - put the cat pictures index 0-999 in data/train/cats |
| """ 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 |
| # Install build tools | |
| sudo apt-get update | |
| sudo apt-get install -y build-essential git python-pip libfreetype6-dev libxft-dev libncurses-dev libopenblas-dev gfortran python3-matplotlib libblas-dev liblapack-dev libatlas-base-dev python3-dev python3-pydot linux-headers-generic linux-image-extra-virtual unzip python3-numpy swig python3-pandas python-sklearn unzip python3-pip python3-venv | |
| # Install CUDA 7 | |
| # wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1410/x86_64/cuda-repo-ubuntu1410_7.0-28_amd64.deb | |
| wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1504/x86_64/cuda-repo-ubuntu1504_7.5-18_amd64.deb | |
| sudo dpkg -i cuda-repo-ubuntu1504_7.5-18_amd64.deb && rm cuda-repo-ubuntu1504_7.5-18_amd64.deb | |
| sudo apt-get update | |
| sudo apt-get install -y cuda |
Code for Keras plays catch blog post
python qlearn.py| # Time series forecasting based on multiple time series, including the original one | |
| # This script is based on the following examples and discussions: | |
| # https://gist.github.com/lukovkin/1aefa4509e066690b892 | |
| # https://groups.google.com/forum/#!topic/keras-users/9GsDwkSdqBg | |
| import numpy as np | |
| import pandas as pd | |
| import matplotlib.pyplot as plt | |
| import random | |
| import theano |
| from ib.opt import Connection, message | |
| from ib.ext.Contract import Contract | |
| from ib.ext.Order import Order | |
| from random import randint | |
| import time | |
| def error_handler(msg): | |
| print ("Server Error: %s" % msg) |
| import pandas as pd | |
| from random import random | |
| flow = (list(range(1,10,1)) + list(range(10,1,-1)))*100 | |
| pdata = pd.DataFrame({"a":flow, "b":flow}) | |
| pdata.b = pdata.b.shift(9) | |
| data = pdata.iloc[10:] * random() # some noise | |
| import numpy as np |