From 370abcdff5a8646be5910441ccba1dcdb1092ec5 Mon Sep 17 00:00:00 2001 From: Kessler Date: Wed, 19 Jun 2019 13:56:45 -0400 Subject: [PATCH 1/3] Early stopping callback added for termination based on validation performance --- ecnet/models/mlp.py | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/ecnet/models/mlp.py b/ecnet/models/mlp.py index c33b287..ee44557 100644 --- a/ecnet/models/mlp.py +++ b/ecnet/models/mlp.py @@ -19,6 +19,7 @@ stderr = sys.stderr sys.stderr = open(devnull, 'w') from keras.backend import clear_session, reset_uids +from keras.callbacks import EarlyStopping from keras.layers import Dense from keras.losses import mean_squared_error from keras.metrics import mae @@ -109,24 +110,20 @@ def fit(self, l_x: array, l_y: array, v_x: array=None, v_y: array=None, ) if v_x is not None and v_y is not None: - valid_mae_lowest = self._model.evaluate(v_x, v_y, verbose=v)[1] - steps = int(epochs / 250) - for e in range(steps): - h = self._model.fit( - l_x, - l_y, - validation_data=(v_x, v_y), - epochs=250, - verbose=v - ) - valid_mae = h.history['val_mean_absolute_error'][-1] - if valid_mae < valid_mae_lowest: - valid_mae_lowest = valid_mae - elif valid_mae > (valid_mae_lowest + 0.05 * valid_mae_lowest): - logger.log('debug', 'Validation cutoff after {} epochs' - .format(e * 250), call_loc='MLP') - return - + self._model.fit( + l_x, + l_y, + validation_data=(v_x, v_y), + callbacks=[EarlyStopping( + monitor='val_loss', + patience=250, + verbose=v, + mode='min', + restore_best_weights=True + )], + epochs=epochs, + verbose=v + ) else: self._model.fit( l_x, @@ -134,6 +131,7 @@ def fit(self, l_x: array, l_y: array, v_x: array=None, v_y: array=None, epochs=epochs, verbose=v ) + logger.log('debug', 'Training complete after {} epochs'.format(epochs), call_loc='MLP') From ea1e42240c44c0e11bf52adf3836535af5c74a83 Mon Sep 17 00:00:00 2001 From: Travis Kessler Date: Sat, 22 Jun 2019 10:50:00 -0400 Subject: [PATCH 2/3] Moved set_start_method to multiprocessed tasks --- ecnet/server.py | 7 ------- ecnet/tasks/training.py | 6 +++++- ecnet/tasks/tuning.py | 7 +++++++ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/ecnet/server.py b/ecnet/server.py index f07c537..87741b7 100644 --- a/ecnet/server.py +++ b/ecnet/server.py @@ -24,10 +24,6 @@ resave_df, resave_model, save_config, save_df, save_project, train_model,\ use_model, use_project -# Stdlib imports -from multiprocessing import set_start_method -from os import name - class Server: @@ -52,9 +48,6 @@ def __init__(self, model_config: str='config.yml', prj_file: str=None, self._num_processes = num_processes - if name != 'nt': - set_start_method('spawn', force=True) - if prj_file is not None: self._prj_name, self._num_pools, self._num_candidates, self._df,\ self._cf_file, self._vars = open_project(prj_file) diff --git a/ecnet/tasks/training.py b/ecnet/tasks/training.py index fc3a891..89e6ca8 100644 --- a/ecnet/tasks/training.py +++ b/ecnet/tasks/training.py @@ -13,8 +13,9 @@ # # stdlib. imports -from multiprocessing import Pool +from multiprocessing import Pool, set_start_method from operator import itemgetter +from os import name # ECNet imports from ecnet.utils.logging import logger @@ -48,6 +49,9 @@ def train_project(prj_name: str, num_pools: int, num_candidates: int, num_processes (int): number of concurrent processes used to train ''' + if name != 'nt': + set_start_method('spawn', force=True) + logger.log('info', 'Training {}x{} models'.format( num_pools, num_candidates ), call_loc='TRAIN') diff --git a/ecnet/tasks/tuning.py b/ecnet/tasks/tuning.py index e3bc266..5f3af00 100644 --- a/ecnet/tasks/tuning.py +++ b/ecnet/tasks/tuning.py @@ -8,6 +8,10 @@ # Contains functions/fitness functions for tuning hyperparameters # +# stdlib. imports +from multiprocessing import set_start_method +from os import name + # 3rd party imports from ecabc.abc import ABC @@ -42,6 +46,9 @@ def tune_hyperparameters(df: DataFrame, vars: dict, num_employers: int, dict: tuned hyperparameters ''' + if name != 'nt': + set_start_method('spawn', force=True) + logger.log('info', 'Tuning architecture/learning hyperparameters', call_loc='TUNE') logger.log('debug', 'Arguments:\n\t| num_employers:\t{}\n\t| ' From 86305f3f1c4286100272e6f956f3fda8b5d509fb Mon Sep 17 00:00:00 2001 From: Travis Kessler Date: Sat, 22 Jun 2019 10:52:55 -0400 Subject: [PATCH 3/3] Version bump: 3.2.0 -> 3.2.1 --- docs/conf.py | 2 +- ecnet/__init__.py | 2 +- ecnet/models/mlp.py | 2 +- ecnet/server.py | 2 +- ecnet/tasks/limit_inputs.py | 2 +- ecnet/tasks/remove_outliers.py | 2 +- ecnet/tasks/training.py | 10 +++------- ecnet/tasks/tuning.py | 2 +- ecnet/tools/database.py | 2 +- ecnet/tools/plotting.py | 2 +- ecnet/tools/project.py | 2 +- ecnet/utils/data_utils.py | 2 +- ecnet/utils/error_utils.py | 2 +- ecnet/utils/logging.py | 2 +- ecnet/utils/server_utils.py | 2 +- setup.py | 2 +- 16 files changed, 18 insertions(+), 22 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 01479cb..12b1000 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -32,7 +32,7 @@ # The short X.Y version version = '' # The full version, including alpha/beta/rc tags -release = '3.2.0' +release = '3.2.1' # -- General configuration --------------------------------------------------- diff --git a/ecnet/__init__.py b/ecnet/__init__.py index d469ff2..8c0bfab 100644 --- a/ecnet/__init__.py +++ b/ecnet/__init__.py @@ -1,2 +1,2 @@ from ecnet.server import Server -__version__ = '3.2.0' +__version__ = '3.2.1' diff --git a/ecnet/models/mlp.py b/ecnet/models/mlp.py index ee44557..d5c0e6b 100644 --- a/ecnet/models/mlp.py +++ b/ecnet/models/mlp.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # # ecnet/models/mlp.py -# v.3.2.0 +# v.3.2.1 # Developed in 2019 by Travis Kessler # # Contains the "MultilayerPerceptron" (feed-forward neural network) class diff --git a/ecnet/server.py b/ecnet/server.py index 87741b7..43f3bc9 100644 --- a/ecnet/server.py +++ b/ecnet/server.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # # ecnet/server.py -# v.3.2.0 +# v.3.2.1 # Developed in 2019 by Travis Kessler # # Contains the "Server" class, which handles ECNet project creation, neural diff --git a/ecnet/tasks/limit_inputs.py b/ecnet/tasks/limit_inputs.py index a053e5b..9c269e3 100644 --- a/ecnet/tasks/limit_inputs.py +++ b/ecnet/tasks/limit_inputs.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # # ecnet/tasks/limit_inputs.py -# v.3.2.0 +# v.3.2.1 # Developed in 2019 by Travis Kessler # # Contains functions for selecting influential input parameters diff --git a/ecnet/tasks/remove_outliers.py b/ecnet/tasks/remove_outliers.py index b87bd16..9d1110f 100644 --- a/ecnet/tasks/remove_outliers.py +++ b/ecnet/tasks/remove_outliers.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # # ecnet/tasks/remove_outliers.py -# v.3.2.0 +# v.3.2.1 # Developed in 2019 by Travis Kessler # # Contains function for removing outliers from ECNet DataFrame diff --git a/ecnet/tasks/training.py b/ecnet/tasks/training.py index 89e6ca8..b7cd0ac 100644 --- a/ecnet/tasks/training.py +++ b/ecnet/tasks/training.py @@ -1,15 +1,11 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- # -# ecnet/server.py -# v.3.2.0 +# ecnet/tasks/training.py +# v.3.2.1 # Developed in 2019 by Travis Kessler # -# Contains the "Server" class, which handles ECNet project creation, neural -# network model creation, data hand-off to models, prediction error -# calculation, input parameter selection, hyperparameter tuning. -# -# For example scripts, refer to https://ecnet.readthedocs.io/en/latest/ +# Contains function for project training (multiprocessed training) # # stdlib. imports diff --git a/ecnet/tasks/tuning.py b/ecnet/tasks/tuning.py index 5f3af00..afbcf56 100644 --- a/ecnet/tasks/tuning.py +++ b/ecnet/tasks/tuning.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # # ecnet/tasks/tuning.py -# v.3.2.0 +# v.3.2.1 # Developed in 2019 by Travis Kessler # # Contains functions/fitness functions for tuning hyperparameters diff --git a/ecnet/tools/database.py b/ecnet/tools/database.py index 77fecd2..545a811 100644 --- a/ecnet/tools/database.py +++ b/ecnet/tools/database.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # # ecnet/tools/database.py -# v.3.2.0 +# v.3.2.1 # Developed in 2019 by Travis Kessler # # Contains functions for creating ECNet-formatted databases diff --git a/ecnet/tools/plotting.py b/ecnet/tools/plotting.py index 4c9732a..b81aba9 100644 --- a/ecnet/tools/plotting.py +++ b/ecnet/tools/plotting.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # # ecnet/tools/plotting.py -# v.3.2.0 +# v.3.2.1 # Developed in 2019 by Travis Kessler # # Contains functions/classes for creating various plots diff --git a/ecnet/tools/project.py b/ecnet/tools/project.py index 2e7713a..45fdd5d 100644 --- a/ecnet/tools/project.py +++ b/ecnet/tools/project.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # # ecnet/tools/project.py -# v.3.2.0 +# v.3.2.1 # Developed in 2019 by Travis Kessler # # Contains functions for predicting data using pre-existing .prj files diff --git a/ecnet/utils/data_utils.py b/ecnet/utils/data_utils.py index a4d4d79..661dd97 100644 --- a/ecnet/utils/data_utils.py +++ b/ecnet/utils/data_utils.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # # ecnet/utils/data_utils.py -# v.3.2.0 +# v.3.2.1 # Developed in 2019 by Travis Kessler # # Contains functions/classes for loading data, saving data, saving results diff --git a/ecnet/utils/error_utils.py b/ecnet/utils/error_utils.py index fa9f928..476fac3 100644 --- a/ecnet/utils/error_utils.py +++ b/ecnet/utils/error_utils.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # # ecnet/utils/error_utils.py -# v.3.2.0 +# v.3.2.1 # Developed in 2019 by Travis Kessler # # Contains functions for error calculations diff --git a/ecnet/utils/logging.py b/ecnet/utils/logging.py index 260a46d..4640cc0 100644 --- a/ecnet/utils/logging.py +++ b/ecnet/utils/logging.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # # ecnet/utils/logging.py -# v.3.2.0 +# v.3.2.1 # Developed in 2019 by Travis Kessler # # Contains logger used by ECNet diff --git a/ecnet/utils/server_utils.py b/ecnet/utils/server_utils.py index 41ad757..76d320b 100644 --- a/ecnet/utils/server_utils.py +++ b/ecnet/utils/server_utils.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # # ecnet/utils/server_utils.py -# v.3.2.0 +# v.3.2.1 # Developed in 2019 by Travis Kessler # # Contains functions used by ecnet.Server diff --git a/setup.py b/setup.py index b323d6a..75f0568 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='ecnet', - version='3.2.0', + version='3.2.1', description='UMass Lowell Energy and Combustion Research Laboratory Neural' ' Network Software', url='http://github.com/tjkessler/ecnet',