From 5d014d68d8e56519d8c07f8acaf09195ff3da861 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Sun, 21 Apr 2024 18:29:34 +0200 Subject: Changed allocation of models to save memory. --- least_squares.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/least_squares.cpp b/least_squares.cpp index d80fd2d..827ede0 100644 --- a/least_squares.cpp +++ b/least_squares.cpp @@ -225,14 +225,16 @@ int main(int argc, char* argv[]) { x(0) = sqrt(N); for (unsigned sample = 0; sample < samples; sample++) { - QuadraticModel ls(N, M, r, σ², μA, μJ); - Vector xGD = gradientAscent(ls, x); - std::cout << ls.getHamiltonian(xGD) / N << " " << ls.maxEigenvalue(xGD) << " "; - - ls = QuadraticModel(N, M, r, σ², μA, μJ); - Vector xMP = subagAlgorithm(ls, r, N); - xMP = gradientAscent(ls, xMP); - std::cout << ls.getHamiltonian(xMP) / N << " " << ls.maxEigenvalue(xMP) << std::endl; + QuadraticModel* ls = new QuadraticModel(N, M, r, σ², μA, μJ); + Vector xGD = gradientAscent(*ls, x); + std::cout << ls->getHamiltonian(xGD) / N << " " << ls->maxEigenvalue(xGD) << " "; + delete ls; + + ls = new QuadraticModel(N, M, r, σ², μA, μJ); + Vector xMP = subagAlgorithm(*ls, r, N); + xMP = gradientAscent(*ls, xMP); + std::cout << ls->getHamiltonian(xMP) / N << " " << ls->maxEigenvalue(xMP) << std::endl; + delete ls; } return 0; -- cgit v1.2.3-70-g09d2