diff options
author | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2025-05-14 22:52:14 -0300 |
---|---|---|
committer | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2025-05-14 22:52:14 -0300 |
commit | 4c045af4a3d3a12b1e4e73bc9ab1789ceb7b4d7e (patch) | |
tree | 98ecbd90a29fb8a56270dcc4b5f959681b297d77 | |
parent | 800a3a73161af1ceb58feefc6e6808cbcfaf0c9a (diff) | |
download | code-4c045af4a3d3a12b1e4e73bc9ab1789ceb7b4d7e.tar.gz code-4c045af4a3d3a12b1e4e73bc9ab1789ceb7b4d7e.tar.bz2 code-4c045af4a3d3a12b1e4e73bc9ab1789ceb7b4d7e.zip |
Reintroduced smoothing
-rw-r--r-- | log-fourier.cpp | 22 | ||||
-rw-r--r-- | log-fourier.hpp | 2 | ||||
-rw-r--r-- | log-fourier_integrator.cpp | 25 |
3 files changed, 27 insertions, 22 deletions
diff --git a/log-fourier.cpp b/log-fourier.cpp index cb57229..1fa57c3 100644 --- a/log-fourier.cpp +++ b/log-fourier.cpp @@ -254,3 +254,25 @@ Real C0(const LogarithmicFourierTransform& fft, const std::vector<Complex>& Ĉ) return C * pow(fft.shift, 2) / M_PI; } +void smooth(std::vector<Real>& C, Real ε) { + unsigned N = C.size(); + bool trigger0 = false; + bool trigger1 = false; + for (unsigned i = 0; i < N; i++) { + if (C[i] < ε || trigger0) { + C[i] = 0; + trigger0 = true; + } + if (C[N-1-i] > 1 - ε || trigger1) { + C[N-1-i] = 1; + trigger1 = true; + } + } + + Real Cmax = 0; + for (unsigned i = 0; i < N; i++) { + if (C[N-1-i] > Cmax) Cmax = C[N-1-i]; + C[N-1-i] = Cmax; + } +} + diff --git a/log-fourier.hpp b/log-fourier.hpp index 3abc379..29717cd 100644 --- a/log-fourier.hpp +++ b/log-fourier.hpp @@ -53,3 +53,5 @@ Real estimateZ(LogarithmicFourierTransform& fft, const std::vector<Real>& C, con Real energy(const LogarithmicFourierTransform& fft, const std::vector<Real>& C, const std::vector<Real>& R, unsigned p, unsigned s, Real λ, Real β); Real C0(const LogarithmicFourierTransform& fft, const std::vector<Complex>& Ĉ); + +void smooth(std::vector<Real>& C, Real ε); diff --git a/log-fourier_integrator.cpp b/log-fourier_integrator.cpp index b2a16af..b4b705f 100644 --- a/log-fourier_integrator.cpp +++ b/log-fourier_integrator.cpp @@ -23,12 +23,11 @@ int main(int argc, char* argv[]) { Real βₘₐₓ = 20; Real Δβ = 0.01; bool loadData = false; - unsigned stepsToRespond = 1e5; unsigned pad = 2; int opt; - while ((opt = getopt(argc, argv, "p:s:2:T:t:b:d:k:D:e:0:lg:S:x:P:h:")) != -1) { + while ((opt = getopt(argc, argv, "p:s:2:T:t:b:d:k:D:e:0:lg:x:P:h:")) != -1) { switch (opt) { case 'p': p = atoi(optarg); @@ -75,9 +74,6 @@ int main(int argc, char* argv[]) { case 'l': loadData = true; break; - case 'S': - stepsToRespond = atoi(optarg); - break; default: exit(1); } @@ -135,9 +131,7 @@ 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, λ); @@ -179,21 +173,8 @@ int main(int argc, char* argv[]) { std::vector<Real> Cₜ₊₁ = fft.inverse(Ĉₜ₊₁); std::vector<Real> 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ₜ; - } + smooth(Cₜ₊₁, ε); + smooth(Rₜ₊₁, ε); for (unsigned i = 0; i < N; i++) { Cₜ[i] += γ * (Cₜ₊₁[i] - Cₜ[i]); |