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

priv. ModifiedGradient -> pub. descentDirection

parent ed35fa82
No related branches found
No related tags found
No related merge requests found
...@@ -29,8 +29,38 @@ class SampleFunctional { ...@@ -29,8 +29,38 @@ class SampleFunctional {
return y * v + func_(v.two_norm()); // <1/2 Av - b,v> + H(|v|) return y * v + func_(v.two_norm()); // <1/2 Av - b,v> + H(|v|)
} }
SmallVector descentDirection(const SmallVector x) const {
if (x == SmallVector(0.0)) {
SmallVector d = SmoothGrad(x);
// Decline of the smooth part in the negative gradient direction
double smoothDecline = -(d * d);
double nonlinearDecline =
func_.rightDifferential(0.0) * d.two_norm(); // TODO: is this correct?
double combinedDecline = smoothDecline + nonlinearDecline;
return (combinedDecline < 0) ? d : SmallVector(0.0);
}
SmallVector const pg = PlusGrad(x);
SmallVector const mg = MinusGrad(x);
SmallVector ret;
// TODO: collinearity checks suck
if (pg * x == pg.two_norm() * x.two_norm() &&
-(mg * x) == mg.two_norm() * x.two_norm()) {
return SmallVector(0);
} else if (pg * x >= 0 && mg * x >= 0) {
ret = pg;
} else if (pg * x <= 0 && mg * x <= 0) {
ret = mg;
} else {
ret = project(SmoothGrad(x), x);
}
ret *= -1;
return ret;
}
SmallVector minimise(const SmallVector x) const { SmallVector minimise(const SmallVector x) const {
SmallVector descDir = ModifiedGradient(x); SmallVector descDir = descentDirection(x);
if (descDir == SmallVector(0.0)) if (descDir == SmallVector(0.0))
return SmallVector(0.0); return SmallVector(0.0);
...@@ -95,36 +125,6 @@ class SampleFunctional { ...@@ -95,36 +125,6 @@ class SampleFunctional {
return y; return y;
} }
SmallVector ModifiedGradient(const SmallVector x) const {
if (x == SmallVector(0.0)) {
SmallVector d = SmoothGrad(x);
// Decline of the smooth part in the negative gradient direction
double smoothDecline = -(d * d);
double nonlinearDecline =
func_.rightDifferential(0.0) * d.two_norm(); // TODO: is this correct?
double combinedDecline = smoothDecline + nonlinearDecline;
return (combinedDecline < 0) ? d : SmallVector(0.0);
}
SmallVector const pg = PlusGrad(x);
SmallVector const mg = MinusGrad(x);
SmallVector ret;
// TODO: collinearity checks suck
if (pg * x == pg.two_norm() * x.two_norm() &&
-(mg * x) == mg.two_norm() * x.two_norm()) {
return SmallVector(0);
} else if (pg * x >= 0 && mg * x >= 0) {
ret = pg;
} else if (pg * x <= 0 && mg * x <= 0) {
ret = mg;
} else {
ret = project(SmoothGrad(x), x);
}
ret *= -1;
return ret;
}
// No normalising is done! // No normalising is done!
SmallVector project(const SmallVector z, const SmallVector x) const { SmallVector project(const SmallVector z, const SmallVector x) const {
SmallVector y = z; SmallVector y = z;
......
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