diff options
author | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2024-04-21 18:29:34 +0200 |
---|---|---|
committer | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2024-04-21 18:29:34 +0200 |
commit | 5d014d68d8e56519d8c07f8acaf09195ff3da861 (patch) | |
tree | 5ea71a4f02b722fa84712b6ccbe85dd265910d83 /least_squares.cpp | |
parent | bbc56fde4cffb5fc85dbb5d78a2994a3b14bdb7e (diff) | |
download | code-5d014d68d8e56519d8c07f8acaf09195ff3da861.tar.gz code-5d014d68d8e56519d8c07f8acaf09195ff3da861.tar.bz2 code-5d014d68d8e56519d8c07f8acaf09195ff3da861.zip |
Changed allocation of models to save memory.
Diffstat (limited to 'least_squares.cpp')
-rw-r--r-- | least_squares.cpp | 18 |
1 files 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; |