From b097aebfd8672d59dfb8ae2b1cbf777e09ae1eb7 Mon Sep 17 00:00:00 2001 From: Adam Lowet Date: Tue, 7 Apr 2026 14:17:32 -0700 Subject: [PATCH 1/2] Fix optimizer reset using wrong variable names The optimizer reset logic was checking `opt` (the optimizer object) instead of `self.optimizer` (the string config), and assigning to `optimizer` instead of `opt`. This would cause the reset to malfunction during training restarts. Co-Authored-By: Claude Opus 4.6 --- code/glm_class.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/code/glm_class.py b/code/glm_class.py index 8bed712..8b48881 100644 --- a/code/glm_class.py +++ b/code/glm_class.py @@ -527,12 +527,12 @@ def _fit(self, Xt, Yt, w, w0, avg_dev, prev_w_series=None, verbose=True): w.assign(random_w) # reset optimizer - if opt == "adam": - optimizer = tf.keras.optimizers.Adam( + if self.optimizer == "adam": + opt = tf.keras.optimizers.Adam( learning_rate=self.learning_rate ) - elif opt == "sgdm": - optimizer = tf.keras.optimizers.SGD( + elif self.optimizer == "sgdm": + opt = tf.keras.optimizers.SGD( learning_rate=self.learning_rate, momentum=self.momentum ) From 3f1c0a7b7d057ac085324f3d93032f416b68a9c6 Mon Sep 17 00:00:00 2001 From: Adam Lowet Date: Tue, 7 Apr 2026 14:32:35 -0700 Subject: [PATCH 2/2] Update tf.log to tf.math.log for TF2 compatibility tf.log was deprecated in TensorFlow 2.x in favor of tf.math.log. Co-Authored-By: Claude Opus 4.6 --- code/glm_class.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/glm_class.py b/code/glm_class.py index 8b48881..c166a30 100644 --- a/code/glm_class.py +++ b/code/glm_class.py @@ -178,7 +178,7 @@ def __init__( elif np.logical_and(self.loss_type == "poisson", self.activation != "exp"): self.loss_func = lambda Y, Y_hat, Y_act: tf.reduce_sum( - Y_act - Y * tf.log(Y_act + 1e-33) + Y_act - Y * tf.math.log(Y_act + 1e-33) ) elif self.loss_type == "gaussian":