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

Do not use fastquadratic because of problems

Reaching the minimum with one step leaves us with a
zero-subdifferential. fastquadratic and that subdifferential do not
get along.
parent b8a5e16f
No related branches found
No related tags found
No related merge requests found
...@@ -157,6 +157,7 @@ void minimise(const Functional J, const typename Functional::SmallVector x, ...@@ -157,6 +157,7 @@ void minimise(const Functional J, const typename Functional::SmallVector x,
{ // Debug { // Debug
Interval<double> D; Interval<double> D;
JRest.subDiff(0, D); JRest.subDiff(0, D);
dverb dverb
<< "## Directional derivative (as per subdifferential of restriction): " << "## Directional derivative (as per subdifferential of restriction): "
<< D[1] << " (coordinates of the restriction)" << std::endl; << D[1] << " (coordinates of the restriction)" << std::endl;
...@@ -164,8 +165,16 @@ void minimise(const Functional J, const typename Functional::SmallVector x, ...@@ -164,8 +165,16 @@ void minimise(const Functional J, const typename Functional::SmallVector x,
0); // We should not be minimising in this direction otherwise 0); // We should not be minimising in this direction otherwise
} }
// FIXME: default values are used // WARNING:
Bisection bisection; // Using fastquadratic appears to be a very bad idea if D[1] is exactly zero.
// Huge steps that lead us back to where we came from are the result.
Bisection bisection(
0.0, // acceptError: Stop if the search interval has
// become smaller than this number
1.0, // acceptFactor: ?
1e-12, // requiredResidual: ?
false, // fastQuadratic
1e-14); // safety: acceptance factor for inexact minimization
int count; int count;
// FIXME: The value of x_old should not matter if the factor is 1.0, correct? // FIXME: The value of x_old should not matter if the factor is 1.0, correct?
double const stepsize = bisection.minimize(JRest, 0.0, 1.0, count); double const stepsize = bisection.minimize(JRest, 0.0, 1.0, count);
......
...@@ -294,6 +294,41 @@ void testSampleFunction3D() { ...@@ -294,6 +294,41 @@ void testSampleFunction3D() {
assert(std::abs(ret1 - ret3) < 1e-5); assert(std::abs(ret1 - ret3) < 1e-5);
} }
// Checks if reaching the minimum in one step leads to problems
void testSampleFunction2() {
int const dim = 2;
typedef Dune::SampleFunctional<dim> Functional;
Functional::SmallMatrix A;
A[0][0] = 1;
A[0][1] = 0;
A[1][0] = 0;
A[1][1] = 1;
Functional::SmallVector b;
b[0] = 1;
b[1] = 1;
Dune::SampleFunction f;
Functional J(A, b, Dune::MyNonlinearity<dim>(f));
Functional::SmallVector start = b;
double const ret1 = functionTester(J, start, 2);
// Something random
start[0] = 279;
start[1] = -96;
double const ret2 = functionTester(J, start, 9);
assert(std::abs(ret1 - ret2) < 1e-5);
start[0] = 0;
start[1] = 0;
double const ret3 = functionTester(J, start, 2);
assert(std::abs(ret1 - ret3) < 1e-5);
}
int main() { int main() {
try { try {
testSampleFunction(); testSampleFunction();
...@@ -306,6 +341,8 @@ int main() { ...@@ -306,6 +341,8 @@ int main() {
std::cout << std::endl << std::endl << std::endl; std::cout << std::endl << std::endl << std::endl;
testHorribleFunctionLogarithmic(); testHorribleFunctionLogarithmic();
std::cout << std::endl << std::endl << std::endl; std::cout << std::endl << std::endl << std::endl;
testSampleFunction2();
std::cout << std::endl << std::endl << std::endl;
testSampleFunction3D(); testSampleFunction3D();
return 0; return 0;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment