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

Clean up testing code

parent 6588b185
No related branches found
No related tags found
No related merge requests found
...@@ -152,6 +152,20 @@ class SampleFunctional { ...@@ -152,6 +152,20 @@ class SampleFunctional {
} }
}; };
template <int dim, class Function>
void functionTester(
SampleFunctional<dim, Function> J,
typename SampleFunctional<dim, Function>::SmallVector &start, size_t runs) {
typename SampleFunctional<dim, Function>::SmallVector correction;
for (size_t i = 1; i <= runs; ++i) {
correction = J.minimise(start);
start += correction;
if (i != runs)
std::cout << "New value: J(...) = " << J(start) << std::endl;
}
std::cout << "Arrived at J(...) = " << J(start) << std::endl;
}
void testSampleFunction() { void testSampleFunction() {
int const dim = 2; int const dim = 2;
typedef SampleFunctional<dim, SampleFunction> SampleFunctional; typedef SampleFunctional<dim, SampleFunction> SampleFunctional;
...@@ -167,21 +181,10 @@ void testSampleFunction() { ...@@ -167,21 +181,10 @@ void testSampleFunction() {
SampleFunctional J(A, b); SampleFunctional J(A, b);
SampleFunctional::SmallVector c = b;
c /= c.two_norm();
// assert(J.directionalDerivative(b,c) == 2*sqrt(5) + 2);
SampleFunctional::SmallVector start = b; SampleFunctional::SmallVector start = b;
start *= 17; start *= 17;
SampleFunctional::SmallVector correction;
for (int i = 1; i <= 6; ++i) { functionTester(J, start, 6);
correction = J.minimise(start);
start += correction;
std::cout << "New value: J(...) = " << J(start) << std::endl;
}
std::cout << "Arrived at J(...) = " << J(start) << std::endl;
} }
void testTrivialFunction() { void testTrivialFunction() {
...@@ -199,26 +202,16 @@ void testTrivialFunction() { ...@@ -199,26 +202,16 @@ void testTrivialFunction() {
SampleFunctional J(A, b); SampleFunctional J(A, b);
SampleFunctional::SmallVector c = b;
c /= c.two_norm();
// assert(J.directionalDerivative(b,c) == 2*sqrt(5));
SampleFunctional::SmallVector start = b; SampleFunctional::SmallVector start = b;
start *= 17; start *= 17;
SampleFunctional::SmallVector correction;
for (int i = 1; i <= 5; ++i) { functionTester(J, start, 5);
correction = J.minimise(start);
start += correction;
std::cout << "New value: J(...) = " << J(start) << std::endl;
}
std::cout << "Arrived at J(...) = " << J(start) << std::endl;
} }
int main() { int main() {
try { try {
testSampleFunction(); testSampleFunction();
std::cout << std::endl;
testTrivialFunction(); testTrivialFunction();
return 0; return 0;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment