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

Modularise minimise()

parent bc8107f6
Branches
No related tags found
No related merge requests found
...@@ -134,25 +134,18 @@ template <int dim> class SampleFunctional { ...@@ -134,25 +134,18 @@ template <int dim> class SampleFunctional {
}; };
template <class Functional> template <class Functional>
void minimise(Functional const &J, typename Functional::SmallVector &x, void descentMinimisation(Functional const &J,
size_t steps, Bisection const &bisection) { typename Functional::SmallVector &x,
typename Functional::SmallVector const &descDir,
Bisection const &bisection) {
typedef typename Functional::SmallVector SmallVector; typedef typename Functional::SmallVector SmallVector;
for (size_t step = 0; step < steps; ++step) {
SmallVector descDir;
bool const linesearchp = J.descentDirection(x, descDir);
if (descDir == SmallVector(0.0))
return;
typedef typename Functional::NonlinearityType LocalNonlinearityType; typedef typename Functional::NonlinearityType LocalNonlinearityType;
if (linesearchp) {
// {{{ Construct a restriction of J to the line x + t * descDir // {{{ Construct a restriction of J to the line x + t * descDir
/* We have /* We have
1/2 <A(u+xv),u+xv>-<b,u+xv> = 1/2 <Av,v> x^2 - <b-Au,v> x + <1/2 1/2 <A(u+xv),u+xv>-<b,u+xv> = 1/2 <Av,v> x^2 - <b-Au,v> x + <1/2 Au-b,u>
Au-b,u>
since A is symmetric. since A is symmetric.
*/ */
...@@ -171,9 +164,9 @@ void minimise(Functional const &J, typename Functional::SmallVector &x, ...@@ -171,9 +164,9 @@ void minimise(Functional const &J, typename Functional::SmallVector &x,
Interval<double> D; Interval<double> D;
JRest.subDiff(0, D); JRest.subDiff(0, D);
dverb << "## Directional derivative (as per subdifferential of " dverb
"restriction): " << D[1] << " (coordinates of the restriction)" << "## Directional derivative (as per subdifferential of restriction): "
<< std::endl; << D[1] << " (coordinates of the restriction)" << std::endl;
/* /*
It is possible that this differs quite a lot from the It is possible that this differs quite a lot from the
directional derivative computed in the descentDirection() directional derivative computed in the descentDirection()
...@@ -196,25 +189,51 @@ void minimise(Functional const &J, typename Functional::SmallVector &x, ...@@ -196,25 +189,51 @@ void minimise(Functional const &J, typename Functional::SmallVector &x,
; ;
x.axpy(stepsize, descDir); x.axpy(stepsize, descDir);
} else { }
Bisection slowBisection(bisection);
slowBisection.setFastQuadratic(false); template <class Functional>
void tangentialMinimisation(Functional const &J,
typename Functional::SmallVector &x,
typename Functional::SmallVector const &descDir,
Bisection const &bisection) {
typedef typename Functional::NonlinearityType LocalNonlinearityType;
typedef typename Functional::SmallVector SmallVector;
CircularConvexFunction<LocalNonlinearityType> const JRest( CircularConvexFunction<LocalNonlinearityType> const JRest(J.A, J.b, *J.phi, x,
J.A, J.b, *J.phi, x, descDir); descDir);
int count; int count;
double const stepsize = slowBisection.minimize(JRest, 0.0, 1.0, count); double const stepsize = bisection.minimize(JRest, 0.0, 1.0, count);
dverb << "Number of iterations in the bisection method: " << count dverb << "Number of iterations in the bisection method: " << count
<< std::endl; << std::endl;
; ;
// Since x is used in the computation of the rhs, do not write to it // Since x is used in the computation of the rhs, do not write to it directly
// directly
SmallVector tmp; SmallVector tmp;
JRest.cartesian(stepsize, tmp); JRest.cartesian(stepsize, tmp);
x = tmp; x = tmp;
} }
template <class Functional>
void minimise(Functional const &J, typename Functional::SmallVector &x,
size_t steps, Bisection const &bisection) {
typedef typename Functional::SmallVector SmallVector;
for (size_t step = 0; step < steps; ++step) {
SmallVector descDir;
bool const linesearchp = J.descentDirection(x, descDir);
if (descDir == SmallVector(0.0))
return;
if (linesearchp) {
descentMinimisation(J, x, descDir, bisection);
} else {
Bisection slowBisection(bisection);
slowBisection.setFastQuadratic(false);
tangentialMinimisation(J, x, descDir, slowBisection);
}
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment