diff --git a/src/bisection-example-new.cc b/src/bisection-example-new.cc index 8269baf79931707b437c765301ea28102fa37b36..30366162337d00d771ec31516c46f8726c546bbd 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;