Skip to content

Commit

Permalink
it works time, time to tune
Browse files Browse the repository at this point in the history
  • Loading branch information
vicentebolea committed Jun 18, 2018
1 parent 6101d2c commit 6548c32
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 17 deletions.
4 changes: 3 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[[source]]
name = "pypi"
verify_ssl = true
url = "https://pypi.tuna.tsinghua.edu.cn/simple"
url = "https://pypi.python.org/simple/"

[dev-packages]

Expand All @@ -11,6 +11,8 @@ keras = "==1.2.1"
ipython = "==4.1.2"
scipy = "*"
numpy = "*"
sklearn = "*"
pandas = "*"

[requires]
python_version = "2.7"
12 changes: 7 additions & 5 deletions driver.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
from model_factory_method import model_create
from extract_features import prepare_features
from IPython import embed

tests = [
["model_time", "./dataset/NN_test_Y_ADO.mat", "sWave_ADO"],
Expand All @@ -17,19 +18,20 @@

for setup in tests:
train_x, train_y, test_x, test_y = prepare_features(setup[1], setup[2])
model = model_create(setup[0])
model.set_dim(40)
model = model.create_model()

model_factory = model_create(setup[0],39)
model = model_factory.model

model.compile(loss='mean_squared_error', optimizer='adam', metrics=['accuracy'])

model.fit(train_x, train_y,
batch_size=BATCH_SIZE,
shuffle=True,
nb_epochs=EPOCHS,
nb_epoch=EPOCHS,
verbose=1,
validation_data=(test_x, test_y))

score = model.evaluate(test_x, test_y, verbose=0)
print('Test loss:', score[0])
print('Test accuracy:', score[1])

embed()
2 changes: 1 addition & 1 deletion extract_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ def prepare_features(labels_file, filekey):

train_x, test_x, train_y, test_y = train_test_split(dataset_x, dataset_y, test_size=0.2)

return train_x.as_matrix(), train_y, test_x.as_matrix(), test_y
return train_x, train_y, test_x, test_y
2 changes: 1 addition & 1 deletion model_depth.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ModelDepth(ModelFactory):
def create(self):
self.model = Sequential()
model = Sequential()
model.add(Dense(46, input_shape=(self.dim,), activation='selu'))
model.add(Dense(46, input_shape=(self.dim,), activation='relu'))
model.add(Dense(512, activation='sigmoid'))
model.add(Dense(1, activation='softmax'))
return model
2 changes: 1 addition & 1 deletion model_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ class ModelFactory:
"""

def __init__(self, dim):
self.model = self.create()
self.dim = dim
self.model = self.create()

def create(self):
pass
Expand Down
10 changes: 5 additions & 5 deletions model_factory_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
from model_magnitude import ModelMagnitude


def model_create(which):
def model_create(which, dim):
if which == 'model_depth':
return ModelDepth()
return ModelDepth(dim)

if which == 'model_time':
return ModelTime()
return ModelTime(dim)

if which == 'model_location':
return ModelLocation()
return ModelLocation(dim)

if which == 'model_magnitude':
return ModelMagnitude()
return ModelMagnitude(dim)
2 changes: 1 addition & 1 deletion model_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ModelLocation(ModelFactory):
def create(self):
self.model = Sequential()
model = Sequential()
model.add(Dense(46, input_shape=(self.input_dim,), activation='selu'))
model.add(Dense(46, input_shape=(self.dim,), activation='relu'))
model.add(Dense(512, activation='sigmoid'))
model.add(Dense(1, activation='softmax'))
return model
2 changes: 1 addition & 1 deletion model_magnitude.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ModelMagnitude(ModelFactory):
def create(self):
self.model = Sequential()
model = Sequential()
model.add(Dense(46, input_shape=(self.input_dim,), activation='selu'))
model.add(Dense(46, input_shape=(self.input_dim,), activation='relu'))
model.add(Dense(512, activation='sigmoid'))
model.add(Dense(1, activation='softmax'))
return model
2 changes: 1 addition & 1 deletion model_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ModelTime(ModelFactory):
def create(self):
self.model = Sequential()
model = Sequential()
model.add(Dense(46, input_shape=(self.input_dim,), activation='selu'))
model.add(Dense(46, input_shape=(self.dim,), activation='relu'))
model.add(Dense(512, activation='sigmoid'))
model.add(Dense(1, activation='softmax'))
return model

0 comments on commit 6548c32

Please sign in to comment.