45 #include "GlobiPack_Brents1DMinimization.hpp"
46 #include "GlobiPack_TestLagrPolyMeritFunc1D.hpp"
62 using GlobiPack::brents1DMinimization;
64 using GlobiPack::computePoint;
66 using Teuchos::inOutArg;
67 using Teuchos::outArg;
70 using Teuchos::rcpFromRef;
75 using Teuchos::parameterList;
79 template<
class Scalar>
80 inline Scalar sqr(
const Scalar &x) {
return x*x; }
83 template<
class Scalar>
84 inline Scalar cube(
const Scalar &x) {
return x*x*x; }
88 template<
class Scalar>
89 const RCP<TestLagrPolyMeritFunc1D<Scalar> > quadPhi()
92 typedef typename ST::magnitudeType ScalarMag;
93 Array<Scalar> alphaPoints = tuple<Scalar>(0.0, 2.0, 4.0);
94 Array<ScalarMag> phiPoints = tuple<ScalarMag>(6.0, 3.0, 6.0);
95 return testLagrPolyMeritFunc1D<Scalar>(alphaPoints, phiPoints);
115 const double cubicMut = 1e-3;
117 template<
class Scalar>
118 inline Scalar cubicPhiVal(
const Scalar &alpha)
119 {
return sqr(alpha - 2.0) + cubicMut * cube(alpha - 2.0) + 3.0; }
122 template<
class Scalar>
123 const RCP<TestLagrPolyMeritFunc1D<Scalar> > cubicPhi()
126 typedef typename ST::magnitudeType ScalarMag;
127 Array<Scalar> alphaPoints =
128 tuple<Scalar>(0.0, 1.0, 3.0, 4.0);
129 Array<ScalarMag> phiPoints =
131 cubicPhiVal(alphaPoints[0]),
132 cubicPhiVal(alphaPoints[1]),
133 cubicPhiVal(alphaPoints[2]),
134 cubicPhiVal(alphaPoints[3])
136 return testLagrPolyMeritFunc1D<Scalar>(alphaPoints, phiPoints);
140 double g_tol_scale = 100.0;
146 "tol", &g_tol_scale,
"Floating point tolerance scaling of eps." );
166 const RCP<TestLagrPolyMeritFunc1D<Scalar> > phi = quadPhi<Scalar>();
168 RCP<Brents1DMinimization<Scalar> > brentsMin = brents1DMinimization<Scalar>();
172 const RCP<ParameterList> pl = parameterList();
176 brentsMin->setParameterList(pl);
178 brentsMin->setOStream(rcpFromRef(out));
180 const Array<Array<double> > brackets =
181 tuple<Array<double> >(
182 tuple(0.0, 2.0, 4.0),
183 tuple(0.5, 2.5, 4.5),
184 tuple(0.0, 1.0, 3.0),
185 tuple(1.0, 3.0, 4.0),
186 tuple(1.9, 2.0, 4.0),
187 tuple(1.9, 3.9, 4.0),
188 tuple(0.0, 2.0, 2.1),
192 for (
int i = 0; i < as<int>(brackets.size()); ++i ) {
194 const ArrayView<const double> bracket = brackets[i]();
196 out <<
"\ni = "<<i<<
": bracket = "<<bracket()<<
"\n";
200 PointEval1D<Scalar> p_l = computePoint<Scalar>(*phi, bracket[0]);
201 PointEval1D<Scalar> p_m = computePoint<Scalar>(*phi, bracket[1]);
202 PointEval1D<Scalar> p_u = computePoint<Scalar>(*phi, bracket[2]);
205 const bool mimimized = brentsMin->approxMinimize(
206 *phi, p_l, inOutArg(p_m), p_u, outArg(numIters) );
211 as<Scalar>(g_tol_scale*ST::squareroot(ST::eps())));
213 as<Scalar>(g_tol_scale)*ST::eps());
230 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( Brents1DMinimization, cubicApprox, Scalar )
235 const RCP<TestLagrPolyMeritFunc1D<Scalar> > phi = cubicPhi<Scalar>();
237 RCP<Brents1DMinimization<Scalar> > brentsMin = brents1DMinimization<Scalar>();
241 const RCP<ParameterList> pl = parameterList();
242 pl->set(
"Relative Tol", as<double>(g_tol_scale*ST::eps()));
243 pl->set(
"Bracket Tol", as<double>(ST::eps()));
244 brentsMin->setParameterList(pl);
246 brentsMin->setOStream(rcpFromRef(out));
248 const Array<Array<double> > brackets =
249 tuple<Array<double> >(
250 tuple(0.0, 2.0, 4.0),
251 tuple(0.5, 2.5, 4.5),
252 tuple(0.0, 1.0, 3.0),
253 tuple(1.0, 3.0, 4.0),
254 tuple(1.9, 2.0, 4.0),
255 tuple(1.9, 3.9, 4.0),
256 tuple(0.0, 2.0, 2.1),
260 for (
int i = 0; i < as<int>(brackets.size()); ++i ) {
262 const ArrayView<const double> bracket = brackets[i]();
264 out <<
"\ni = "<<i<<
": bracket = "<<bracket()<<
"\n";
268 PointEval1D<Scalar> p_l = computePoint<Scalar>(*phi, bracket[0]);
269 PointEval1D<Scalar> p_m = computePoint<Scalar>(*phi, bracket[1]);
270 PointEval1D<Scalar> p_u = computePoint<Scalar>(*phi, bracket[2]);
273 const bool mimimized = brentsMin->approxMinimize(
274 *phi, p_l, inOutArg(p_m), p_u, outArg(numIters) );
279 as<Scalar>(g_tol_scale*ST::squareroot(ST::eps())));
281 as<Scalar>(g_tol_scale*ST::eps()));
TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL(Teuchos_Conditions, NumberConditionSerialization, T)
const RCP< TestLagrPolyMeritFunc1D< Scalar > > testLagrPolyMeritFunc1D(const ArrayView< const Scalar > &alpha, const ArrayView< const Scalar > &phi)
Simple concrete class that implements a 1D algorithm to mimimize a 1D function.
static CommandLineProcessor & getCLP()
basic_OSTab< char > OSTab
Represents the evaluation point of the merit function phi(alpha) and/or is derivative Dphi(alpha)...
void setOption(const char option_true[], const char option_false[], bool *option_val, const char documentation[]=NULL)
TypeTo as(const TypeFrom &t)
#define TEST_FLOATING_EQUALITY(v1, v2, tol)
#define TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT_REAL_SCALAR_TYPES(TEST_GROUP, TEST_NAME)
Lagrange Polynomial Merit Function used in testing.
#define TEST_COMPARE(v1, comp, v2)