diff --git a/src/bisection-example-flexible.cc b/src/bisection-example-flexible.cc index 61398aee5d5c558b94cdcb446cffdec6c0a96630..a3d06cdf0ff5bdc0613ed96188d7622dd32d0fd2 100644 --- a/src/bisection-example-flexible.cc +++ b/src/bisection-example-flexible.cc @@ -34,18 +34,6 @@ class SampleFunctional { return y * v + func_(v.two_norm()); // <1/2 Av - b,v> + H(|v|) } - // |dir|-times the directional derivative wrt dir/|dir|. - double pseudoDirectionalDerivative(const SmallVector x, - const SmallVector dir) const { - if (x == SmallVector(0.0)) - return func_.rightDifferential(0) * dir.two_norm(); - - if (x * dir > 0) - return PlusGrad(x) * dir; - else - return MinusGrad(x) * dir; - } - double directionalDerivative(const SmallVector x, const SmallVector dir) const { double norm = dir.two_norm(); @@ -143,6 +131,18 @@ class SampleFunctional { return y; } + // |dir|-times the directional derivative wrt dir/|dir|. + double pseudoDirectionalDerivative(const SmallVector x, + const SmallVector dir) const { + if (x == SmallVector(0.0)) + return func_.rightDifferential(0) * dir.two_norm(); + + if (x * dir > 0) + return PlusGrad(x) * dir; + else + return MinusGrad(x) * dir; + } + SmallVector ModifiedGradient(const SmallVector x) const { if (x == SmallVector(0.0)) { SmallVector d = SmoothGrad(x); @@ -197,7 +197,7 @@ void testSampleFunction() { SampleFunctional J(A, b); std::cout << J.directionalDerivative(b, b) << std::endl; - assert(J.pseudoDirectionalDerivative(b, b) == 10 + 2 * sqrt(5)); + assert(J.directionalDerivative(b, b) == 2 * sqrt(5) + 2); SampleFunctional::SmallVector start = b; start *= 17; @@ -223,7 +223,7 @@ void testTrivialFunction() { SampleFunctional J(A, b); std::cout << J.directionalDerivative(b, b) << std::endl; - assert(J.pseudoDirectionalDerivative(b, b) == 10); + assert(J.directionalDerivative(b, b) == 2 * sqrt(5)); SampleFunctional::SmallVector start = b; start *= 17;