added reset

release/4.3a0
Frank Dellaert 2009-12-31 10:27:39 +00:00
parent bf85f10de7
commit 9b327d1a9d
1 changed files with 3 additions and 2 deletions

View File

@ -18,6 +18,7 @@ namespace gtsam {
size_t maxIterations, bool steepest = false) { size_t maxIterations, bool steepest = false) {
if (maxIterations == 0) maxIterations = dim(x) * (steepest ? 10 : 1); 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 // Start with g0 = A'*(A*x0-b), d0 = - g0
// i.e., first step is in direction of negative gradient // i.e., first step is in direction of negative gradient
@ -41,8 +42,8 @@ namespace gtsam {
x = x + alpha * d; x = x + alpha * d;
if (k==maxIterations) break; if (k==maxIterations) break;
// update gradient // update gradient (or re-calculate at reset time)
g = g + alpha * (Ab ^ Ad); g = (k%reset==0) ? Ab.gradient(x) : g + alpha * (Ab ^ Ad);
// check for convergence // check for convergence
double dotg = dot(g, g); double dotg = dot(g, g);