From 6c5b7f58f154c2ef19747e6eb22b82e661c96604 Mon Sep 17 00:00:00 2001 From: Elias Pipping <elias.pipping@fu-berlin.de> Date: Sat, 10 Sep 2011 22:17:10 +0200 Subject: [PATCH] priv. ModifiedGradient -> pub. descentDirection --- src/bisection-example-new.cc | 62 ++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/src/bisection-example-new.cc b/src/bisection-example-new.cc index 8269baf7..30366162 100644 --- a/src/bisection-example-new.cc +++ b/src/bisection-example-new.cc @@ -29,8 +29,38 @@ class SampleFunctional { 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 descDir = ModifiedGradient(x); + SmallVector descDir = descentDirection(x); if (descDir == SmallVector(0.0)) return SmallVector(0.0); @@ -95,36 +125,6 @@ class SampleFunctional { 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! SmallVector project(const SmallVector z, const SmallVector x) const { SmallVector y = z; -- GitLab