added reset
parent
bf85f10de7
commit
9b327d1a9d
|
@ -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);
|
||||||
|
|
Loading…
Reference in New Issue