Skip to content

Instantly share code, notes, and snippets.

@ozancaglayan
Created December 9, 2015 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ozancaglayan/c04a78f410ea94c97b2d to your computer and use it in GitHub Desktop.
Save ozancaglayan/c04a78f410ea94c97b2d to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from keras.layers.core import Dense
from keras.models import Sequential
from keras.optimizers import RMSprop, Adadelta, Adagrad, Adam, SGD
from keras.callbacks import Callback
import numpy as np
class Test(Callback):
test = np.matrix('1 2; 2 4; 4 2; 2 1; 1 1')
def on_epoch_end(self, epoch, logs={}):
print self.test
print self.model.predict(self.test, self.test.shape[0])
if __name__ == '__main__':
np.random.seed(1)
X = np.random.randint(-100, 100, size=(100000, 2))# + np.random.normal()
y = X[:, 0] / X[:, 1]
model = Sequential()
model.add(Dense(128, activation='sigmoid', input_dim=X.shape[1]))
model.add(Dense(64, activation='linear'))
model.add(Dense(32, activation='sigmoid'))
#model.add(Dense(32, activation='tanh'))
#model.add(Dense(16, activation='tanh'))
#model.add(Dense(1000, activation='tanh'))
#model.add(Dense(1000, activation='tanh'))
model.add(Dense(1))
opt = Adadelta()
TestCallback = Test()
model.compile(optimizer=opt, loss='mse')
history = model.fit(X, y, batch_size=100, nb_epoch=100, verbose=1, validation_split=0.2, shuffle=True, callbacks=[TestCallback])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment