From 4eadc4d7c85ad4e942a5280064c0072082d94026 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Sun, 21 Apr 2024 11:21:31 +0200 Subject: Removed renaming of variable, and destruct first model to create second. --- least_squares.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/least_squares.cpp b/least_squares.cpp index b294679..49100b4 100644 --- a/least_squares.cpp +++ b/least_squares.cpp @@ -158,7 +158,7 @@ Vector gradientDescent(const QuadraticModel& M, const Vector& x0, Real ε = 1e-7 return x; } -Vector findMinimum(const QuadraticModel& M, const Vector& x0, Real ε = 1e-5) { +Vector levenbergMarquardt(const QuadraticModel& M, const Vector& x0, Real ε = 1e-5) { Vector x = x0; Real λ = 100; @@ -182,7 +182,7 @@ Vector findMinimum(const QuadraticModel& M, const Vector& x0, Real ε = 1e-5) { return x; } -Vector subagAlgorithm(const QuadraticModel& M, Rng& r, unsigned k, unsigned m) { +Vector subagAlgorithm(const QuadraticModel& M, Rng& r, unsigned k) { Vector σ = Vector::Zero(M.N); unsigned axis = r.variate(0, M.N - 1); σ(axis) = sqrt(M.N / k); @@ -243,10 +243,11 @@ int main(int argc, char* argv[]) { QuadraticModel leastSquares(N, M, r, σ, A, J); x = gradientDescent(leastSquares, x); std::cout << leastSquares.getHamiltonian(x) / N; - QuadraticModel leastSquares2(N, M, r, σ, A, J); - Vector σ = subagAlgorithm(leastSquares2, r, N, 15); - σ = gradientDescent(leastSquares2, σ); - std::cout << " " << leastSquares2.getHamiltonian(σ) / N << std::endl; + + leastSquares = QuadraticModel(N, M, r, σ, A, J); + x = subagAlgorithm(leastSquares, r, N); + x = gradientDescent(leastSquares, x); + std::cout << " " << leastSquares.getHamiltonian(x) / N << std::endl; } return 0; -- cgit v1.2.3-70-g09d2