From 1aa2170ada247b0b7963d26daeb8d9b1ae98a52a Mon Sep 17 00:00:00 2001 From: Gaspard Jankowiak Date: Thu, 16 May 2024 09:39:28 +0200 Subject: [PATCH] =?UTF-8?q?use=20residuals=20and=20not=20=CF=872=20for=20G?= =?UTF-8?q?auss-Newton?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Utils.jl | 4 ++++ test.jl | 11 +++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Utils.jl b/Utils.jl index 80748f1..2756c42 100644 --- a/Utils.jl +++ b/Utils.jl @@ -77,6 +77,10 @@ function lowpass_filter(i; σ=1) return r end +function residuals(I_data, I_model, err) + return (I_data .- I_model ./ err) .^ 2 +end + function chi2(I_data, I_model, err) return sum((I_data .- I_model ./ err) .^ 2) end diff --git a/test.jl b/test.jl index 2f602fb..b3e4885 100644 --- a/test.jl +++ b/test.jl @@ -68,14 +68,21 @@ padding_factor[18] = 10.0 bounds = MH.boxconstraints(lb=lb_reduced, ub=ub_reduced) -function obj(P) +function obj_χ2(P) I_model, neg_H20 = intensity_reduced(P) χ2 = Utils.chi2(I_data, I_model, err) factor = (neg_H20 == 0 ? 1.0 : 5.0 * (neg_H20 + 1)) return factor * χ2 end -barriered_obj = Utils.add_log_barriers(obj, simple_bounds; padding_factor=padding_factor) +function obj_residuals(P) + I_model, neg_H20 = intensity_reduced(P) + residuals = Utils.residuals(I_data, I_model, err) + factor = (neg_H20 == 0 ? 1.0 : 5.0 * (neg_H20 + 1)) + return factor * residuals +end + +barriered_obj = Utils.add_log_barriers(obj_residuals, simple_bounds; padding_factor=padding_factor) information = MH.Information(f_optimum=0.0) information = MH.Information()