Skip to content
Snippets Groups Projects
Commit a1823d67 authored by Elias Pipping's avatar Elias Pipping Committed by Elias Pipping
Browse files

Use the pseudo directional derivative

In most cases (x != 0) this is a lot faster than normalising the direction and computing the actual directional derivative
parent ae7a3bb2
No related branches found
No related tags found
No related merge requests found
...@@ -63,7 +63,7 @@ class SampleFunctional { ...@@ -63,7 +63,7 @@ class SampleFunctional {
while (true) { while (true) {
tmp = x; tmp = x;
tmp.axpy(r, descDir); tmp.axpy(r, descDir);
if (directionalDerivative(tmp, descDir) >= 0) if (pseudoDirectionalDerivative(tmp, descDir) >= 0)
break; break;
l = r; l = r;
...@@ -91,12 +91,13 @@ class SampleFunctional { ...@@ -91,12 +91,13 @@ class SampleFunctional {
middle = descDir; middle = descDir;
middle *= m; middle *= m;
double derivative = directionalDerivative(x + middle, descDir); double pseudoDerivative =
pseudoDirectionalDerivative(x + middle, descDir);
if (derivative < 0) { if (pseudoDerivative < 0) {
l = m; l = m;
m = (m + r) / 2; m = (m + r) / 2;
} else if (derivative > 0) { } else if (pseudoDerivative > 0) {
r = m; r = m;
m = (l + m) / 2; m = (l + m) / 2;
} else } else
...@@ -131,7 +132,9 @@ class SampleFunctional { ...@@ -131,7 +132,9 @@ class SampleFunctional {
return y; return y;
} }
// |dir|-times the directional derivative wrt dir/|dir|. // |dir|-times the directional derivative wrt dir/|dir|. If only
// the sign of the directionalDerivative matters, this saves the
// cost of normalising.
double pseudoDirectionalDerivative(const SmallVector x, double pseudoDirectionalDerivative(const SmallVector x,
const SmallVector dir) const { const SmallVector dir) const {
if (x == SmallVector(0.0)) if (x == SmallVector(0.0))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment