From 4f7ec4cf2e42d88c29a9f24d9862f6a4e94436fa Mon Sep 17 00:00:00 2001 From: OverLordGoldDragon Date: Mon, 16 Sep 2019 20:29:41 -0400 Subject: [PATCH 1/2] Add informative comments --- .../keras_examples/optimization_example.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/examples/keras_examples/optimization_example.py b/examples/keras_examples/optimization_example.py index 32401bf3..f255ccc4 100644 --- a/examples/keras_examples/optimization_example.py +++ b/examples/keras_examples/optimization_example.py @@ -7,7 +7,7 @@ from keras.models import Sequential from keras.wrappers.scikit_learn import KerasClassifier - +## INITIAL HYPERPARAMETERS MODEL def _build_fn_experiment(input_shape): model = Sequential( [ @@ -19,18 +19,20 @@ def _build_fn_experiment(input_shape): model.compile(optimizer="adam", loss="binary_crossentropy", metrics=["accuracy"]) return model - +## HYPERPARAMETER OPTIMIZER def _build_fn_optimization(input_shape): model = Sequential( [ Dense( - Integer(50, 150), - kernel_initializer="uniform", - input_shape=input_shape, - activation="relu", + Integer(50, 150), ## TO OPTIMIZE: Dense 'units', from 50 to 150, in integer values + kernel_initializer="uniform", ## FIXED (no optimization) + input_shape=input_shape, ## FIXED + activation="relu", ## FIXED ), - Dropout(Real(0.2, 0.7)), - Dense(1, kernel_initializer="uniform", activation=Categorical(["sigmoid", "relu"])), + Dropout(Real(0.2, 0.7)), ## TO OPTIMIZE: Dropout rate, from 0.2 to 0.7, in real values + Dense(1, ## FIXED + kernel_initializer="uniform", ## FIXED + activation=Categorical(["sigmoid", "relu"])), ## TO OPTIMIZE: Dense activation, one of "sigmoid", "relu" ] ) model.compile( From cdba2164a72ab5fcd5a63f55938f64934d25536f Mon Sep 17 00:00:00 2001 From: OverLordGoldDragon Date: Tue, 17 Sep 2019 18:31:09 -0400 Subject: [PATCH 2/2] Inserted spaces to appease Travis --- examples/keras_examples/optimization_example.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/keras_examples/optimization_example.py b/examples/keras_examples/optimization_example.py index f255ccc4..9aca02eb 100644 --- a/examples/keras_examples/optimization_example.py +++ b/examples/keras_examples/optimization_example.py @@ -24,15 +24,15 @@ def _build_fn_optimization(input_shape): model = Sequential( [ Dense( - Integer(50, 150), ## TO OPTIMIZE: Dense 'units', from 50 to 150, in integer values - kernel_initializer="uniform", ## FIXED (no optimization) - input_shape=input_shape, ## FIXED - activation="relu", ## FIXED + Integer(50, 150), # TO OPTIMIZE: Dense 'units', from 50 to 150, in integer values + kernel_initializer="uniform", # FIXED (no optimization) + input_shape=input_shape, # FIXED + activation="relu", # FIXED ), - Dropout(Real(0.2, 0.7)), ## TO OPTIMIZE: Dropout rate, from 0.2 to 0.7, in real values - Dense(1, ## FIXED - kernel_initializer="uniform", ## FIXED - activation=Categorical(["sigmoid", "relu"])), ## TO OPTIMIZE: Dense activation, one of "sigmoid", "relu" + Dropout(Real(0.2, 0.7)), # TO OPTIMIZE: Dropout rate, from 0.2 to 0.7, in real values + Dense(1, # FIXED + kernel_initializer="uniform", # FIXED + activation=Categorical(["sigmoid", "relu"])), # TO OPTIMIZE: Dense activation, one of "sigmoid", "relu" ] ) model.compile(