From 20ce741f0575b8240bdde3b139353961569662fc Mon Sep 17 00:00:00 2001 From: Gabriel E Kreindler Date: Mon, 1 Jan 2024 11:44:56 -0500 Subject: [PATCH] theta_factor: also adjust bounds --- Wstep2.csv | 2 -- src/optimization_backends.jl | 10 ++++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) delete mode 100644 Wstep2.csv diff --git a/Wstep2.csv b/Wstep2.csv deleted file mode 100644 index 15adc1d..0000000 --- a/Wstep2.csv +++ /dev/null @@ -1,2 +0,0 @@ -0.7196188813433798,-0.043635684224973915 --0.043635684224973915,0.002721272140333472 diff --git a/src/optimization_backends.jl b/src/optimization_backends.jl index e80fd4d..a610c06 100644 --- a/src/optimization_backends.jl +++ b/src/optimization_backends.jl @@ -21,14 +21,24 @@ function backend_optimizer( @assert in(opts.optimizer, [:optim, :lsqfit]) "Optimizer " * string(opts.optimizer) * " not supported. Stopping." + opts = deepcopy(opts) + # * we could also have this block in the gateway fit() function, because we only need to do this once. But this seems a more logical place, and this cannot take much time at all. # pre-processing: factors if isa(opts.theta_factors, Vector) @assert !any(opts.theta_factors .≈ 0.0) "theta_factors cannot be zero" + # adjust initial conditions @assert isa(theta0, Vector) theta0 = theta0 .* opts.theta_factors + + # adjust bounds (if specified) + if !isnothing(opts.theta_lower) + @assert !isnothing(opts.theta_upper) "if theta_lower is specified, theta_upper must be specified as well" + opts.theta_lower = opts.theta_lower .* opts.theta_factors + opts.theta_upper = opts.theta_upper .* opts.theta_factors + end mom_fn_scaled = (data, theta) -> mom_fn(data, theta ./ opts.theta_factors)