Skip to content

Commit

Permalink
ENH: Add lr for hyperparameter search
Browse files Browse the repository at this point in the history
  • Loading branch information
pschultzendorff committed Jul 1, 2024
1 parent 4637d92 commit 4081e1a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/pyopmnearwell/ml/nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ def build_model(
hp: keras_tuner.HyperParameters,
ninputs: int,
noutputs: int,
lr_tune: float = 0.1,
) -> tf.Module:
"""Build and compile a FCNN with the given hyperparameters.
Expand Down Expand Up @@ -623,7 +624,7 @@ def build_model(
)
model.compile(
loss=loss,
optimizer=tf.keras.optimizers.Adam(learning_rate=0.1),
optimizer=tf.keras.optimizers.Adam(learning_rate=lr_tune),
)
return model

Expand All @@ -638,6 +639,7 @@ def tune(
max_trials: int = 5,
executions_per_trial: int = 1,
sample_weight: ArrayLike = np.array([1.0]),
lr_tune: float = 0.1,
**kwargs,
) -> tuple[keras.Model, keras_tuner.Tuner]:
"""
Expand Down Expand Up @@ -667,7 +669,12 @@ def tune(
"""
# Define the tuner and start a search.
tuner = keras_tuner.RandomSearch(
hypermodel=partial(build_model, ninputs=ninputs, noutputs=noutputs),
hypermodel=partial(
build_model,
ninputs=ninputs,
noutputs=noutputs,
lr_tune=lr_tune,
),
objective=objective,
max_trials=max_trials,
executions_per_trial=executions_per_trial,
Expand Down

0 comments on commit 4081e1a

Please sign in to comment.