Skip to content

Commit

Permalink
added ability to limit permutations by an integer value
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkokotila committed May 15, 2018
1 parent 4b88a8a commit fc80f0c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ before_script:
- sh -e /etc/init.d/xvfb start
- sleep 3
script:
- coverage run --source=hyperio ./test_script.py
- coverage run --source=talos ./test_script.py
after_success: coveralls

deploy:
Expand Down
21 changes: 11 additions & 10 deletions talos/scan.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from keras import backend as K
from tensorflow import get_default_graph, Session

from .utils.validation_split import validation_split

Expand All @@ -10,7 +11,6 @@
from .utils.estimators import time_estimator
from .parameters.handling import param_format, param_space, param_index, round_params
from .parameters.permutations import param_grid
from .utils.save_load import save_model
from .metrics.score_model import get_score
from .utils.pred_class import classify
from .utils.last_neuron import last_neuron
Expand All @@ -23,10 +23,9 @@ class Scan:

def __init__(self, x, y, params, dataset_name, experiment_no, model,
val_split=.3, shuffle=True, search_method='random',
save_best_model=False,
reduction_method=None, reduction_interval=100,
reduction_window=None, grid_downsample=None,
reduction_metric='val_acc',
reduction_metric='val_acc', round_limit=None,
talos_log_name='talos.log', debug=False):

self.dataset_name = dataset_name
Expand All @@ -50,7 +49,6 @@ def __init__(self, x, y, params, dataset_name, experiment_no, model,
self.grid_downsample = grid_downsample
self.val_split = val_split
self.shuffle = shuffle
self.save_model = save_best_model

self.p = param_format(self)
self.combinations = param_space(self)
Expand All @@ -61,6 +59,8 @@ def __init__(self, x, y, params, dataset_name, experiment_no, model,
self.round_counter = 0
self.peak_epochs = []
self.epoch_entropy = []
self.round_limit = round_limit
self.round_models = []

self.x = x
self.y = y
Expand All @@ -73,8 +73,13 @@ def __init__(self, x, y, params, dataset_name, experiment_no, model,
self = prediction_type(self)

self.result = []
while len(self.param_log) != 0:
self._null = self._run()

if self.round_limit != None:
for i in range(self.round_limit):
self._null = self._run()
else:
while len(self.param_log) != 0:
self._null = self._run()

self = result_todf(self)
self.peak_epochs_df = peak_epochs_todf(self)
Expand Down Expand Up @@ -104,13 +109,9 @@ def _run(self):
if self.reduction_method == 'spear':
self = spear_reducer(self)

if self.save_model == True:
save_model(self)

K.clear_session()
self.round_counter += 1


def _model(self):

return self.model(self.x_train,
Expand Down
37 changes: 19 additions & 18 deletions test_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def iris_model(x_train, y_train, x_val, y_val, params):
activation=params['last_activation']))

# here are using a learning rate boundary
model.compile(optimizer=params['optimizer'](lr=lr_normalizer(params['lr'], params['optimizer'])),
model.compile(optimizer=params['optimizer'](lr=lr_normalizer(params['lr'],
params['optimizer'])),
loss=params['losses'],
metrics=['acc'])

Expand Down Expand Up @@ -94,37 +95,37 @@ def cervix_model(x_train, y_train, x_val, y_val, params):
x, y = ta.datasets.iris()

h = ta.Scan(x, y,
params=p,
dataset_name='testing',
experiment_no='000',
model=iris_model,
grid_downsample=.0001,
reduction_method='spear',
reduction_interval=5)
params=p,
dataset_name='testing',
experiment_no='000',
model=iris_model,
grid_downsample=.0001,
reduction_method='spear',
reduction_interval=5)

r = ta.Reporting('testing_000.csv')

# here use a standard 2d dictionary for inputting the param boundaries

x, y = ta.datasets.cervical_cancer()
p = {'lr': (0.5, 5, 10),
'first_neuron':[4, 8, 16, 32, 64],
'hidden_layers':[2,3,4,5],
'first_neuron': [4, 8, 16, 32, 64],
'hidden_layers': [2,3,4,5],
'batch_size': (2, 30, 10),
'epochs': [3],
'dropout': (0, 0.5, 5),
'weight_regulizer':[None],
'weight_regulizer': [None],
'emb_output_dims': [None],
'optimizer': [Nadam],
'loss': [logcosh, binary_crossentropy],
'activation':[relu],
'activation': [relu],
'last_activation': [sigmoid]}

ta.Scan(x, y, save_best_model=False,
grid_downsample=0.001,
params=p,
dataset_name='cervix',
experiment_no='a',
model=cervix_model, reduction_method='spear', reduction_interval=5)
ta.Scan(x, y,
grid_downsample=0.001,
params=p,
dataset_name='cervix',
experiment_no='a',
model=cervix_model, reduction_method='spear', reduction_interval=5)

ta.Reporting('cervix_a.csv')

0 comments on commit fc80f0c

Please sign in to comment.