|
GlobiPack Package Browser (Single Doxygen Collection) Version of the Day
|
00001 /* 00002 // @HEADER 00003 // *********************************************************************** 00004 // 00005 // GlobiPack: Collection of Scalar 1D globalizaton utilities 00006 // Copyright (2009) Sandia Corporation 00007 // 00008 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00009 // license for use of this work by or on behalf of the U.S. Government. 00010 // 00011 // This library is free software; you can redistribute it and/or modify 00012 // it under the terms of the GNU Lesser General Public License as 00013 // published by the Free Software Foundation; either version 2.1 of the 00014 // License, or (at your option) any later version. 00015 // 00016 // This library is distributed in the hope that it will be useful, but 00017 // WITHOUT ANY WARRANTY; without even the implied warranty of 00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 // Lesser General Public License for more details. 00020 // 00021 // You should have received a copy of the GNU Lesser General Public 00022 // License along with this library; if not, write to the Free Software 00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00024 // USA 00025 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 00026 // 00027 // *********************************************************************** 00028 // @HEADER 00029 */ 00030 00031 00032 #include "GlobiPack_GoldenQuadInterpBracket.hpp" 00033 #include "GlobiPack_TestLagrPolyMeritFunc1D.hpp" 00034 #include "Teuchos_Tuple.hpp" 00035 #include "Teuchos_UnitTestHarness.hpp" 00036 00037 00038 namespace { 00039 00040 00041 // 00042 // Helper code and declarations 00043 // 00044 00045 00046 using GlobiPack::TestLagrPolyMeritFunc1D; 00047 using GlobiPack::testLagrPolyMeritFunc1D; 00048 using GlobiPack::GoldenQuadInterpBracket; 00049 using GlobiPack::goldenQuadInterpBracket; 00050 using GlobiPack::PointEval1D; 00051 using GlobiPack::computePoint; 00052 using Teuchos::as; 00053 using Teuchos::inOutArg; 00054 using Teuchos::outArg; 00055 using Teuchos::null; 00056 using Teuchos::RCP; 00057 using Teuchos::rcpFromRef; 00058 using Teuchos::Array; 00059 using Teuchos::tuple; 00060 using Teuchos::ParameterList; 00061 using Teuchos::parameterList; 00062 00063 00064 template<class Scalar> 00065 inline Scalar sqr(const Scalar &x) { return x*x; } 00066 00067 00068 // Set up a quadratic merit function with minimizer at alpha=2.0, phi=3.0; 00069 template<class Scalar> 00070 const RCP<TestLagrPolyMeritFunc1D<Scalar> > quadPhi() 00071 { 00072 typedef Teuchos::ScalarTraits<Scalar> ST; 00073 typedef typename ST::magnitudeType ScalarMag; 00074 Array<Scalar> alphaPoints = tuple<Scalar>(0.0, 2.0, 4.0); 00075 Array<ScalarMag> phiPoints = tuple<ScalarMag>(6.0, 3.0, 6.0); 00076 return testLagrPolyMeritFunc1D<Scalar>(alphaPoints, phiPoints); 00077 } 00078 00079 00080 double g_tol = Teuchos::ScalarTraits<double>::eps()*100.0; 00081 00082 00083 TEUCHOS_STATIC_SETUP() 00084 { 00085 Teuchos::UnitTestRepository::getCLP().setOption( 00086 "tol", &g_tol, "Floating point tolerance" ); 00087 } 00088 00089 00090 // 00091 // Unit tests for GoldenQuadInterpBracket 00092 // 00093 00094 00095 // 00096 // Check that object can exactly interplate a quadratic merit function at the 00097 // very first iteration 00098 // 00099 00100 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( GoldenQuadInterpBracket, bracket, Scalar ) 00101 { 00102 00103 typedef Teuchos::ScalarTraits<Scalar> ST; 00104 using std::min; 00105 00106 const RCP<TestLagrPolyMeritFunc1D<Scalar> > phi = quadPhi<Scalar>(); 00107 00108 RCP<GoldenQuadInterpBracket<Scalar> > bracket = goldenQuadInterpBracket<Scalar>(); 00109 00110 bracket->setOStream(rcpFromRef(out)); 00111 00112 const Array<Scalar> alpha = 00113 tuple<Scalar>( 00114 1e-14, 1e-10, 1e-7, 1e-4, 0.1, 1.0, 1.1, 1.5, 00115 1.9, 2.0, 2.1, 4.0, 8.0, 30.0); 00116 00117 for (int i = 0; i < as<int>(alpha.size()); ++i ) { 00118 00119 PointEval1D<Scalar> p_l = computePoint(*phi, ST::zero()); 00120 PointEval1D<Scalar> p_m = computePoint(*phi, alpha[i]); 00121 PointEval1D<Scalar> p_u; 00122 int numIters = -1; 00123 00124 if (alpha[i] > ST::eps()) { 00125 00126 const bool bracketResult = bracket->bracketMinimum( 00127 *phi, inOutArg(p_l), inOutArg(p_m), outArg(p_u), outArg(numIters) ); 00128 00129 TEST_ASSERT(bracketResult); 00130 TEST_COMPARE(p_l.alpha, <, p_m.alpha); 00131 TEST_COMPARE(p_m.alpha, <, p_u.alpha); 00132 TEST_COMPARE(p_l.phi, >, p_m.phi); 00133 TEST_COMPARE(p_m.phi, <, p_u.phi); 00134 00135 } 00136 else { 00137 00138 // If alpha[i] < eps, then there will not be enough accuracy in the 00139 // merit function to allow for a successfull line search. 00140 00141 } 00142 00143 } 00144 00145 } 00146 00147 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT_REAL_SCALAR_TYPES( GoldenQuadInterpBracket, bracket ) 00148 00149 00150 } // namespace
1.7.4