From 34d8514804636dc06e2f2299b6044a53586931db Mon Sep 17 00:00:00 2001 From: kjei Date: Tue, 2 Dec 2025 11:47:13 +0100 Subject: [PATCH 1/2] Fix name for steepest descent (had wrong name some places) --- docs/tutorials/popt/tutorial_popt.ipynb | 2 +- pipt/loop/ensemble.py | 2 +- popt/update_schemes/enopt.py | 4 ++-- popt/update_schemes/genopt.py | 2 +- popt/update_schemes/smcopt.py | 2 +- popt/update_schemes/subroutines/optimizers.py | 14 +++++++------- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/tutorials/popt/tutorial_popt.ipynb b/docs/tutorials/popt/tutorial_popt.ipynb index 4137950..1b110ed 100644 --- a/docs/tutorials/popt/tutorial_popt.ipynb +++ b/docs/tutorials/popt/tutorial_popt.ipynb @@ -404,7 +404,7 @@ " - restart: restart optimization from a restart file (default false)\n", " - restartsave: save a restart file after each successful iteration (defalut false)\n", " - tol: convergence tolerance for the objective function (default 1e-6)\n", - " - alpha: step size for the steepest decent method (default 0.1)\n", + " - alpha: step size for the steepest descent method (default 0.1)\n", " - beta: momentum coefficient for running accelerated optimization (default 0.0)\n", " - alpha_maxiter: maximum number of backtracing trials (default 5)\n", " - resample: number indicating how many times resampling is tried if no improvement is found\n", diff --git a/pipt/loop/ensemble.py b/pipt/loop/ensemble.py index 1d997a1..839f259 100644 --- a/pipt/loop/ensemble.py +++ b/pipt/loop/ensemble.py @@ -174,7 +174,7 @@ def check_assimindex_simultaneous(self): def _org_obs_data(self): """ Organize the input true observed data. The obs_data will be a list of length equal length of "TRUEDATAINDEX", - and each entery in the list will be a dictionary with keys equal to the "DATATYPE". + and each entry in the list will be a dictionary with keys equal to the "DATATYPE". Also, the pred_data variable (predicted data or forward simulation) will be initialized here with the same structure as the obs_data variable. diff --git a/popt/update_schemes/enopt.py b/popt/update_schemes/enopt.py index e982d93..7f267ce 100644 --- a/popt/update_schemes/enopt.py +++ b/popt/update_schemes/enopt.py @@ -63,7 +63,7 @@ def __init__(self, fun, x, args, jac, hess, bounds=None, **options): - restart: restart optimization from a restart file (default false) - restartsave: save a restart file after each successful iteration (defalut false) - tol: convergence tolerance for the objective function (default 1e-6) - - alpha: step size for the steepest decent method (default 0.1) + - alpha: step size for the steepest descent method (default 0.1) - beta: momentum coefficient for running accelerated optimization (default 0.0) - alpha_maxiter: maximum number of backtracing trials (default 5) - resample: number indicating how many times resampling is tried if no improvement is found @@ -130,7 +130,7 @@ def __set__variable(var_name=None, defalut=None): # Initialize optimizer optimizer = __set__variable('optimizer', 'GA') if optimizer == 'GA': - self.optimizer = opt.GradientAscent(self.alpha, self.beta) + self.optimizer = opt.GradientDescent(self.alpha, self.beta) elif optimizer == 'Adam': self.optimizer = opt.Adam(self.alpha, self.beta) elif optimizer == 'AdaMax': diff --git a/popt/update_schemes/genopt.py b/popt/update_schemes/genopt.py index 1af0c75..d42992b 100644 --- a/popt/update_schemes/genopt.py +++ b/popt/update_schemes/genopt.py @@ -103,7 +103,7 @@ def __set__variable(var_name=None, defalut=None): # Initialize optimizer optimizer = __set__variable('optimizer', 'GA') if optimizer == 'GA': - self.optimizer = opt.GradientAscent(self.alpha, self.beta) + self.optimizer = opt.GradientDescent(self.alpha, self.beta) elif optimizer == 'Adam': self.optimizer = opt.Adam(self.alpha, self.beta) diff --git a/popt/update_schemes/smcopt.py b/popt/update_schemes/smcopt.py index 336d424..e0ea9fe 100644 --- a/popt/update_schemes/smcopt.py +++ b/popt/update_schemes/smcopt.py @@ -93,7 +93,7 @@ def __set__variable(var_name=None, defalut=None): self.logger.info(info_str) self.logger.info(' {:<21} {:<15.4e}'.format(self.iteration, np.mean(self.obj_func_values))) - self.optimizer = opt.GradientAscent(self.alpha, 0) + self.optimizer = opt.GradientDescent(self.alpha, 0) # The SmcOpt class self-ignites self.run_loop() # run_loop resides in the Optimization class (super) diff --git a/popt/update_schemes/subroutines/optimizers.py b/popt/update_schemes/subroutines/optimizers.py index a211093..d5b2b72 100644 --- a/popt/update_schemes/subroutines/optimizers.py +++ b/popt/update_schemes/subroutines/optimizers.py @@ -1,12 +1,12 @@ """Gradient acceleration.""" import numpy as np -__all__ = ['GradientAscent', 'Adam', 'AdaMax', 'Steihaug', ] +__all__ = ['GradientDescent', 'Adam', 'AdaMax', 'Steihaug', ] -class GradientAscent: +class GradientDescent: r""" - A class for performing gradient ascent optimization with momentum and backtracking. + A class for performing gradient descent optimization with momentum and backtracking. The gradient descent update equation with momentum is given by: $$ \begin{align} @@ -52,7 +52,7 @@ def __init__(self, step_size, momentum): Parameters ---------- step_size : float - The step size (learning rate) for the gradient ascent. + The step size (learning rate) for the gradient descent. momentum : float The momentum factor to apply during updates. @@ -72,7 +72,7 @@ def apply_update(self, control, gradient, **kwargs): Apply a gradient update to the control parameter. !!! note - This is the steepest decent update: x_new = x_old - x_step. + This is the steepest descent update: x_new = x_old - x_step. Parameters ------------------------------------------------------------------------------------- @@ -240,7 +240,7 @@ def apply_update(self, control, gradient, **kwargs): Apply a gradient update to the control parameter. !!! note - This is the steepest decent update: x_new = x_old - x_step. + This is the steepest descent update: x_new = x_old - x_step. Parameters ------------------------------------------------------------------------------------- @@ -269,7 +269,7 @@ def apply_update(self, control, gradient, **kwargs): vel2_hat = self.temp_vel2/(1-beta2**iter) step = alpha*vel1_hat/(np.sqrt(vel2_hat)+self.eps) - new_control = control - step # steepest decent + new_control = control - step # steepest descent return new_control, step def apply_backtracking(self): From fc0543519ee97a96517b0f23c0c5edbf9473ba34 Mon Sep 17 00:00:00 2001 From: kjei Date: Tue, 2 Dec 2025 11:52:14 +0100 Subject: [PATCH 2/2] Write initial objective function value in each epf iteration --- popt/loop/optimize.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/popt/loop/optimize.py b/popt/loop/optimize.py index b2c4a82..989c22d 100644 --- a/popt/loop/optimize.py +++ b/popt/loop/optimize.py @@ -205,6 +205,10 @@ def run_loop(self): self.ftol *= self.epf['tol_factor'] # decrease tolerance self.obj_func_values = self.fun(self.xk, epf = self.epf) self.iteration = 0 + info_str = ' {:<10} {:<10} {:<15} {:<15} {:<15} '.format('iter', 'alpha_iter', + 'obj_func', 'step-size', 'cov[0,0]') + self.logger.info(info_str) + self.logger.info(' {:<21} {:<15.4e}'.format(self.iteration, np.mean(self.obj_func_values))) self.epf_iteration += 1 optimize_result = ot.get_optimize_result(self) ot.save_optimize_results(optimize_result)