Skip to content

Instantly share code, notes, and snippets.

@lukovkin
lukovkin / keras_deconvolution2d_example.py
Created December 10, 2016 15:54
Working Deconv2D example for Keras 1.1.2 and TensorFlow 0.11-0.12
import os
os.environ["KERAS_BACKEND"] = "tensorflow"
import numpy as np
from keras.models import Sequential
from keras.layers import Deconvolution2D
import warnings
@lukovkin
lukovkin / optimal_strategy.py
Last active January 30, 2018 07:41 — forked from nmayorov/optimal_strategy.py
Compute optimal trading strategy for the algorithm described in http://arxiv.org/abs/1508.00317
import numpy as np
import pandas as pd
def compute_market_prices(prices):
"""Compute market prices according to the trading competition recipe.
Parameters
----------
prices : DataFrame
steps_ahead = 5 # how much steps ahead to predict
dim = 1 # dimension of the input series
X_multi = X # copy input sequence to the separate variable in order not to add garbage to the original sequence
for i in range(0, steps_ahead):
predicted = model_train_dict['model'].predict(X_multi, batch_size=batch_size)
X_multi = np.append(X_multi, np.reshape(predicted[-1:], (1, 1, dim)), axis=0)
from __future__ import absolute_import
from __future__ import print_function
import numpy as np
from keras.preprocessing import sequence
from keras.optimizers import SGD, RMSprop, Adagrad, Adadelta
from keras.utils import np_utils
from keras.models import Sequential
from keras.layers.core import Dense, Dropout, Activation, TimeDistributedDense, Flatten, Permute, Reshape
from keras.layers.embeddings import Embedding
from keras.layers.recurrent import LSTM, GRU, SimpleRNN
@lukovkin
lukovkin / mem-ts-RNN.py
Created December 2, 2015 08:19
Memory-efficient training of RNNs (modified example) - see https://groups.google.com/forum/#!topic/keras-users/vnGMtKPu1Xc for the discussion
# Code for Jupyter/IPython Notebook environment
from keras.models import Sequential
from keras.layers.core import TimeDistributedDense, Activation, Dropout
from keras.layers.recurrent import GRU
import numpy as np
from keras.utils.layer_utils import print_layer_shapes
%matplotlib inline
import matplotlib.pyplot as plt
@lukovkin
lukovkin / multi-ts-lstm.py
Last active November 25, 2022 16:23
Time series prediction with multiple sequences input - LSTM - 1
# Time Series Testing
import keras.callbacks
from keras.models import Sequential
from keras.layers.core import Dense, Activation, Dense, Dropout
from keras.layers.recurrent import LSTM
# Call back to capture losses
class LossHistory(keras.callbacks.Callback):
def on_train_begin(self, logs={}):
self.losses = []