From 74b0c4fa129a3a30f10ffb230459e351bedeb751 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Wed, 14 May 2025 13:43:48 -0300 Subject: Re-added γ adjuster MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- log-fourier_integrator.cpp | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'log-fourier_integrator.cpp') diff --git a/log-fourier_integrator.cpp b/log-fourier_integrator.cpp index 1b3cca4..7967142 100644 --- a/log-fourier_integrator.cpp +++ b/log-fourier_integrator.cpp @@ -17,17 +17,18 @@ int main(int argc, char* argv[]) { /* Iteration parameters */ Real ε = 1e-15; - Real γ = 1; + Real γ₀ = 1; Real x = 1; Real β₀ = 0; Real βₘₐₓ = 20; Real Δβ = 0.01; bool loadData = false; + unsigned stepsToRespond = 1e2; unsigned pad = 2; int opt; - while ((opt = getopt(argc, argv, "p:s:2:T:t:b:d:k:D:e:0:lg:x:P:h:")) != -1) { + while ((opt = getopt(argc, argv, "p:s:2:T:t:b:d:k:D:e:0:lg:S:x:P:h:")) != -1) { switch (opt) { case 'p': p = atoi(optarg); @@ -48,7 +49,7 @@ int main(int argc, char* argv[]) { Δβ = atof(optarg); break; case 'g': - γ = atof(optarg); + γ₀ = atof(optarg); break; case 'k': k = atof(optarg); @@ -74,6 +75,9 @@ int main(int argc, char* argv[]) { case 'l': loadData = true; break; + case 'S': + stepsToRespond = atoi(optarg); + break; default: exit(1); } @@ -130,7 +134,10 @@ int main(int argc, char* argv[]) { Real β = β₀ + Δβ; while (β < βₘₐₓ) { + Real γ = γ₀; + Real ΔCmin = 1000; Real ΔCₜ = 100; + unsigned stepsUp = 0; while (ΔCₜ > ε) { auto [RddfCt, dfCt] = RddfCtdfCt(fft, Cₜ, Rₜ, p, s, λ); @@ -172,6 +179,22 @@ int main(int argc, char* argv[]) { std::vector Cₜ₊₁ = fft.inverse(Ĉₜ₊₁); std::vector Rₜ₊₁ = fft.inverse(Ȓₜ₊₁); + if (ΔCₜ < 0.9 * ΔCmin) { + ΔCmin = ΔCₜ; + stepsUp = 0; + } else if (ΔCₜ > 10 * ΔCmin) { + ΔCmin = ΔCₜ; + stepsUp = 0; + } else { + stepsUp++; + } + + if (stepsUp > stepsToRespond) { + γ = std::max(γ/2, (Real)1e-3); + stepsUp = 0; + ΔCmin = ΔCₜ; + } + for (unsigned i = 0; i < N; i++) { Cₜ[i] += γ * (Cₜ₊₁[i] - Cₜ[i]); Rₜ[i] += γ * (Rₜ₊₁[i] - Rₜ[i]); -- cgit v1.2.3-70-g09d2