diff options
author | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2024-04-21 11:21:31 +0200 |
---|---|---|
committer | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2024-04-21 11:21:31 +0200 |
commit | 4eadc4d7c85ad4e942a5280064c0072082d94026 (patch) | |
tree | 0dc5979f7aaa9cb7bf1ead8cc6f5ceb8e654f960 /least_squares.cpp | |
parent | 93bf3372797dcfb14c49de1b1c17a2c217cb9950 (diff) | |
download | code-4eadc4d7c85ad4e942a5280064c0072082d94026.tar.gz code-4eadc4d7c85ad4e942a5280064c0072082d94026.tar.bz2 code-4eadc4d7c85ad4e942a5280064c0072082d94026.zip |
Removed renaming of variable, and destruct first model to create second.
Diffstat (limited to 'least_squares.cpp')
-rw-r--r-- | least_squares.cpp | 13 |
1 files 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<unsigned, std::uniform_int_distribution>(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; |