From 9b327d1a9df0b222f39e62e9a22bd2844bcc5a84 Mon Sep 17 00:00:00 2001 From: Frank Dellaert Date: Thu, 31 Dec 2009 10:27:39 +0000 Subject: [PATCH] added reset --- cpp/iterative-inl.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cpp/iterative-inl.h b/cpp/iterative-inl.h index cd5bef43a..edfb73e81 100644 --- a/cpp/iterative-inl.h +++ b/cpp/iterative-inl.h @@ -18,6 +18,7 @@ namespace gtsam { size_t maxIterations, bool steepest = false) { if (maxIterations == 0) maxIterations = dim(x) * (steepest ? 10 : 1); + size_t reset = (size_t)(sqrt(dim(x))+0.5); // when to reset // Start with g0 = A'*(A*x0-b), d0 = - g0 // i.e., first step is in direction of negative gradient @@ -41,8 +42,8 @@ namespace gtsam { x = x + alpha * d; if (k==maxIterations) break; - // update gradient - g = g + alpha * (Ab ^ Ad); + // update gradient (or re-calculate at reset time) + g = (k%reset==0) ? Ab.gradient(x) : g + alpha * (Ab ^ Ad); // check for convergence double dotg = dot(g, g);