|
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_TestLagrPolyMeritFunc1D.hpp" 00033 #include "GlobiPack_BrentsLineSearch.hpp" 00034 #include "Teuchos_Tuple.hpp" 00035 00036 #include "meritFuncsHelpers.hpp" 00037 00038 #include "Teuchos_UnitTestHarness.hpp" 00039 00040 00041 namespace { 00042 00043 00044 // 00045 // Helper code and declarations 00046 // 00047 00048 00049 using GlobiPack::BrentsLineSearch; 00050 using GlobiPack::brentsLineSearch; 00051 using GlobiPack::computeValue; 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 double g_tol_scale = 100.0; 00065 00066 00067 TEUCHOS_STATIC_SETUP() 00068 { 00069 Teuchos::UnitTestRepository::getCLP().setOption( 00070 "tol", &g_tol_scale, "Floating point tolerance scaling of eps." ); 00071 } 00072 00073 00074 // 00075 // Unit tests for BrentsLineSearch 00076 // 00077 00078 00079 // 00080 // Check that object can exactly interplate a quadratic merit function. This 00081 // takes more than one iteration because of the golden search stuff. 00082 // 00083 00084 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( BrentsLineSearch, quadExact, Scalar ) 00085 { 00086 00087 typedef Teuchos::ScalarTraits<Scalar> ST; 00088 typedef typename ST::magnitudeType ScalarMag; 00089 00090 const RCP<TestLagrPolyMeritFunc1D<Scalar> > phi = quadPhi<Scalar>(); 00091 00092 RCP<BrentsLineSearch<Scalar> > linesearch = brentsLineSearch<Scalar>(); 00093 00094 linesearch->setOStream(rcpFromRef(out)); 00095 00096 const PointEval1D<Scalar> point_k = computePoint(*phi, ST::zero()); 00097 PointEval1D<Scalar> point_kp1 = computePoint(*phi, as<Scalar>(8.0)); 00098 00099 int numIters = -1; 00100 const bool linesearchResult = linesearch->doLineSearch( 00101 *phi, point_k, inOutArg(point_kp1), outArg(numIters) ); 00102 00103 TEST_ASSERT(linesearchResult); 00104 TEST_FLOATING_EQUALITY(point_kp1.alpha, as<Scalar>(2.0), 00105 as<Scalar>(g_tol_scale*ST::squareroot(ST::eps()))); 00106 TEST_FLOATING_EQUALITY(point_kp1.phi, as<ScalarMag>(3.0), 00107 as<Scalar>(g_tol_scale)*ST::eps()); 00108 00109 } 00110 00111 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT_REAL_SCALAR_TYPES( BrentsLineSearch, quadExact ) 00112 00113 00114 // 00115 // Check that object can approximately mimimize a cubic function. 00116 // 00117 00118 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( BrentsLineSearch, cubicApprox, Scalar ) 00119 { 00120 00121 typedef Teuchos::ScalarTraits<Scalar> ST; 00122 typedef typename ST::magnitudeType ScalarMag; 00123 00124 const RCP<TestLagrPolyMeritFunc1D<Scalar> > phi = quadPhi<Scalar>(); 00125 00126 RCP<BrentsLineSearch<Scalar> > linesearch = brentsLineSearch<Scalar>(); 00127 00128 const RCP<ParameterList> pl = parameterList(); 00129 pl->sublist("Minimize").set("Relative Tol", as<double>(g_tol_scale*ST::eps())); 00130 pl->sublist("Minimize").set("Bracket Tol", as<double>(ST::eps())); 00131 linesearch->setParameterList(pl); 00132 00133 linesearch->setOStream(rcpFromRef(out)); 00134 00135 const PointEval1D<Scalar> point_k = computePoint(*phi, ST::zero()); 00136 PointEval1D<Scalar> point_kp1 = computePoint(*phi, as<Scalar>(8.0)); 00137 00138 int numIters = -1; 00139 const bool linesearchResult = linesearch->doLineSearch( 00140 *phi, point_k, inOutArg(point_kp1), outArg(numIters) ); 00141 00142 TEST_ASSERT(linesearchResult); 00143 TEST_FLOATING_EQUALITY(point_kp1.alpha, as<Scalar>(2.0), 00144 as<Scalar>(g_tol_scale*ST::squareroot(ST::eps()))); 00145 TEST_FLOATING_EQUALITY(point_kp1.phi, as<ScalarMag>(3.0), 00146 as<Scalar>(g_tol_scale)*ST::eps()); 00147 00148 } 00149 00150 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT_REAL_SCALAR_TYPES( BrentsLineSearch, cubicApprox ) 00151 00152 00153 } // namespace
1.7.4