summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2024-04-21 18:29:34 +0200
committerJaron Kent-Dobias <jaron@kent-dobias.com>2024-04-21 18:29:34 +0200
commit5d014d68d8e56519d8c07f8acaf09195ff3da861 (patch)
tree5ea71a4f02b722fa84712b6ccbe85dd265910d83
parentbbc56fde4cffb5fc85dbb5d78a2994a3b14bdb7e (diff)
downloadcode-5d014d68d8e56519d8c07f8acaf09195ff3da861.tar.gz
code-5d014d68d8e56519d8c07f8acaf09195ff3da861.tar.bz2
code-5d014d68d8e56519d8c07f8acaf09195ff3da861.zip
Changed allocation of models to save memory.
-rw-r--r--least_squares.cpp18
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;