From 14b2fced8dc99b9f4daa07cc142d3f0c8d1d2cc5 Mon Sep 17 00:00:00 2001 From: Elias Pipping <elias.pipping@fu-berlin.de> Date: Mon, 6 Aug 2012 16:25:49 +0200 Subject: [PATCH] Compare minimise() and minimise2() --- src/test-gradient-method-helper.hh | 18 ++++++++++++++++++ src/test-gradient-sample-steep.cc | 11 ++++++++++- src/test-gradient-sample-steep2.cc | 9 +++++++++ src/test-gradient-sample-verysteep.cc | 9 +++++++++ src/test-gradient-sample.cc | 11 ++++++++++- 5 files changed, 56 insertions(+), 2 deletions(-) diff --git a/src/test-gradient-method-helper.hh b/src/test-gradient-method-helper.hh index 2bb22ad9..310e60d8 100644 --- a/src/test-gradient-method-helper.hh +++ b/src/test-gradient-method-helper.hh @@ -28,6 +28,24 @@ double functionTester(Dune::EllipticEnergy<dim> J, return final; } +template <int dim> +double functionTester2(Dune::EllipticEnergy<dim> J, + typename Dune::EllipticEnergy<dim>::SmallVector &start, + size_t runs) { + Bisection const bisection( + 0.0, // acceptError: Stop if the search interval has + // become smaller than this number + 1.0, // acceptFactor: ? + 1e-12, // requiredResidual: ? + true, // fastQuadratic + 0); // safety: acceptance factor for inexact minimization + Dune::minimise2(J, start, runs, bisection); + double const final = J(start); + std::cout << boost::format(" -> %e (%e)") % final % start + << std::endl; + return final; +} + template <int dim> double two_distance(typename Dune::EllipticEnergy<dim>::SmallVector const &x, typename Dune::EllipticEnergy<dim>::SmallVector const &y) { diff --git a/src/test-gradient-sample-steep.cc b/src/test-gradient-sample-steep.cc index 9e7350bd..3f082c4a 100644 --- a/src/test-gradient-sample-steep.cc +++ b/src/test-gradient-sample-steep.cc @@ -29,7 +29,10 @@ int main() { double ret1; { SmallVector start = { 0, 1 }; - ret1 = functionTester(J, start, 3); + ret1 = functionTester(J, start, 2); + SmallVector minimum; + functionTester2(J, minimum, 2); + assert(two_distance<dim>(start, minimum) < 1e-5); } double ret2; @@ -37,6 +40,9 @@ int main() { // Something random SmallVector start = { 279, -96 }; ret2 = functionTester(J, start, 3); + SmallVector minimum; + functionTester2(J, minimum, 3); + assert(two_distance<dim>(start, minimum) < 1e-5); } assert(std::abs(ret1 - ret2) < 1e-5); @@ -44,6 +50,9 @@ int main() { { SmallVector start = { 0, 0 }; ret3 = functionTester(J, start, 1); + SmallVector minimum; + functionTester2(J, minimum, 1); + assert(two_distance<dim>(start, minimum) < 1e-5); } assert(std::abs(ret1 - ret3) < 1e-5); } diff --git a/src/test-gradient-sample-steep2.cc b/src/test-gradient-sample-steep2.cc index 30a8507e..3f082c4a 100644 --- a/src/test-gradient-sample-steep2.cc +++ b/src/test-gradient-sample-steep2.cc @@ -30,6 +30,9 @@ int main() { { SmallVector start = { 0, 1 }; ret1 = functionTester(J, start, 2); + SmallVector minimum; + functionTester2(J, minimum, 2); + assert(two_distance<dim>(start, minimum) < 1e-5); } double ret2; @@ -37,6 +40,9 @@ int main() { // Something random SmallVector start = { 279, -96 }; ret2 = functionTester(J, start, 3); + SmallVector minimum; + functionTester2(J, minimum, 3); + assert(two_distance<dim>(start, minimum) < 1e-5); } assert(std::abs(ret1 - ret2) < 1e-5); @@ -44,6 +50,9 @@ int main() { { SmallVector start = { 0, 0 }; ret3 = functionTester(J, start, 1); + SmallVector minimum; + functionTester2(J, minimum, 1); + assert(two_distance<dim>(start, minimum) < 1e-5); } assert(std::abs(ret1 - ret3) < 1e-5); } diff --git a/src/test-gradient-sample-verysteep.cc b/src/test-gradient-sample-verysteep.cc index 86b3f2c8..4d5f09ad 100644 --- a/src/test-gradient-sample-verysteep.cc +++ b/src/test-gradient-sample-verysteep.cc @@ -30,6 +30,9 @@ int main() { { SmallVector start = { 0, 1 }; ret1 = functionTester(J, start, 2); + SmallVector minimum; + functionTester2(J, minimum, 2); + assert(two_distance<dim>(start, minimum) < 1e-5); } double ret2; @@ -37,6 +40,9 @@ int main() { // Something random SmallVector start = { 279, -96 }; ret2 = functionTester(J, start, 4); + SmallVector minimum; + functionTester2(J, minimum, 4); + assert(two_distance<dim>(start, minimum) < 1e-5); } assert(std::abs(ret1 - ret2) < 1e-8); @@ -44,6 +50,9 @@ int main() { { SmallVector start = { 0, 0 }; ret3 = functionTester(J, start, 1); + SmallVector minimum; + functionTester2(J, minimum, 1); + assert(two_distance<dim>(start, minimum) < 1e-5); } assert(std::abs(ret1 - ret3) < 1e-5); } diff --git a/src/test-gradient-sample.cc b/src/test-gradient-sample.cc index 742bbf09..245249b7 100644 --- a/src/test-gradient-sample.cc +++ b/src/test-gradient-sample.cc @@ -43,7 +43,10 @@ int main() { double ret1; { SmallVector start = { 17, 34 }; - ret1 = functionTester(J, start, 6); + ret1 = functionTester(J, start, 8); + SmallVector minimum; + functionTester2(J, minimum, 8); + assert(two_distance<dim>(start, minimum) < 1e-5); } double ret2; @@ -51,6 +54,9 @@ int main() { // Something random SmallVector start = { 279, -96 }; ret2 = functionTester(J, start, 10); + SmallVector minimum; + functionTester2(J, minimum, 10); + assert(two_distance<dim>(start, minimum) < 1e-5); } assert(std::abs(ret1 - ret2) < 1e-5); @@ -58,6 +64,9 @@ int main() { { SmallVector start = { 0, 0 }; ret3 = functionTester(J, start, 3); + SmallVector minimum; + functionTester2(J, minimum, 3); + assert(two_distance<dim>(start, minimum) < 1e-5); } assert(std::abs(ret1 - ret3) < 1e-5); } -- GitLab