|
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 // Redistribution and use in source and binary forms, with or without 00012 // modification, are permitted provided that the following conditions are 00013 // met: 00014 // 00015 // 1. Redistributions of source code must retain the above copyright 00016 // notice, this list of conditions and the following disclaimer. 00017 // 00018 // 2. Redistributions in binary form must reproduce the above copyright 00019 // notice, this list of conditions and the following disclaimer in the 00020 // documentation and/or other materials provided with the distribution. 00021 // 00022 // 3. Neither the name of the Corporation nor the names of the 00023 // contributors may be used to endorse or promote products derived from 00024 // this software without specific prior written permission. 00025 // 00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00037 // 00038 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 00039 // 00040 // *********************************************************************** 00041 // @HEADER 00042 */ 00043 00044 #ifndef GLOBIPACK_BRENTS_LINE_SEARCH_DEF_HPP 00045 #define GLOBIPACK_BRENTS_LINE_SEARCH_DEF_HPP 00046 00047 00048 #include "GlobiPack_BrentsLineSearch_decl.hpp" 00049 #include "Teuchos_TabularOutputter.hpp" 00050 00051 00052 namespace GlobiPack { 00053 00054 00055 // Constructor/Initializers/Accessors 00056 00057 00058 template<typename Scalar> 00059 BrentsLineSearch<Scalar>::BrentsLineSearch() 00060 {} 00061 00062 00063 template<typename Scalar> 00064 const GoldenQuadInterpBracket<Scalar>& 00065 BrentsLineSearch<Scalar>::bracket() const 00066 { 00067 return bracket_; 00068 } 00069 00070 00071 template<typename Scalar> 00072 const Brents1DMinimization<Scalar>& 00073 BrentsLineSearch<Scalar>::brentsMin() const 00074 { 00075 return brentsMin_; 00076 } 00077 00078 00079 // Overridden from ParameterListAcceptor 00080 00081 00082 template<class Scalar> 00083 void BrentsLineSearch<Scalar>::setParameterList( 00084 RCP<ParameterList> const& paramList 00085 ) 00086 { 00087 typedef ScalarTraits<Scalar> ST; 00088 namespace BLSU = BrentsLineSearchUtils; 00089 using Teuchos::sublist; 00090 paramList->validateParametersAndSetDefaults(*this->getValidParameters()); 00091 bracket_.setParameterList(sublist(paramList, BLSU::bracket_name, true)); 00092 brentsMin_.setParameterList(sublist(paramList, BLSU::minimize_name, true)); 00093 setMyParamList(paramList); 00094 } 00095 00096 00097 template<class Scalar> 00098 RCP<const ParameterList> 00099 BrentsLineSearch<Scalar>::getValidParameters() const 00100 { 00101 namespace BLSU = BrentsLineSearchUtils; 00102 static RCP<const ParameterList> validPL; 00103 if (is_null(validPL)) { 00104 RCP<Teuchos::ParameterList> 00105 pl = Teuchos::rcp(new Teuchos::ParameterList()); 00106 pl->sublist(BLSU::bracket_name).setParameters( 00107 *bracket_.getValidParameters() 00108 ).disableRecursiveValidation(); 00109 pl->sublist(BLSU::minimize_name).setParameters( 00110 *brentsMin_.getValidParameters() 00111 ).disableRecursiveValidation(); 00112 validPL = pl; 00113 } 00114 return validPL; 00115 } 00116 00117 00118 // Overrridden from LineSearchBase 00119 00120 00121 template<typename Scalar> 00122 bool BrentsLineSearch<Scalar>::requiresBaseDeriv() const 00123 { 00124 return false; 00125 } 00126 00127 00128 template<typename Scalar> 00129 bool BrentsLineSearch<Scalar>::requiresDerivEvals() const 00130 { 00131 return false; 00132 } 00133 00134 00135 template<typename Scalar> 00136 bool BrentsLineSearch<Scalar>::doLineSearch( 00137 const MeritFunc1DBase<Scalar> &phi, 00138 const PointEval1D<Scalar> &point_k, 00139 const Ptr<PointEval1D<Scalar> > &point_kp1, 00140 const Ptr<int> &numIters 00141 ) const 00142 { 00143 00144 using Teuchos::as; 00145 using Teuchos::OSTab; 00146 using Teuchos::outArg; 00147 using Teuchos::inOutArg; 00148 typedef ScalarTraits<Scalar> ST; 00149 typedef PointEval1D<Scalar> PE1D; 00150 00151 #ifdef TEUCHOS_DEBUG 00152 TEUCHOS_ASSERT_EQUALITY(point_k.alpha, ST::zero()); 00153 TEUCHOS_ASSERT_INEQUALITY(point_k.phi, !=, PE1D::valNotGiven()); 00154 TEUCHOS_ASSERT_EQUALITY(point_k.Dphi, PE1D::valNotGiven()); 00155 TEUCHOS_ASSERT(!is_null(point_kp1)); 00156 TEUCHOS_ASSERT_INEQUALITY(point_kp1->alpha, >, ST::zero()); 00157 TEUCHOS_ASSERT_INEQUALITY(point_kp1->phi, !=, PE1D::valNotGiven()); 00158 TEUCHOS_ASSERT_EQUALITY(point_kp1->Dphi, PE1D::valNotGiven()); 00159 #endif 00160 00161 const RCP<Teuchos::FancyOStream> out = this->getOStream(); 00162 bracket_.setOStream(out); 00163 brentsMin_.setOStream(out); 00164 00165 *out << "\nStarting bracketing and brents 1D minimization linesearch ...\n"; 00166 00167 OSTab tab(out); 00168 00169 int totalNumIters = 0; 00170 00171 PointEval1D<Scalar> p_l = point_k; 00172 PointEval1D<Scalar> &p_m = *point_kp1; // Update in place! 00173 PointEval1D<Scalar> p_u; 00174 00175 bool success = true; 00176 00177 // A) Bracket the minimum 00178 00179 int numBracketIters = -1; 00180 00181 const bool bracketSuccess = bracket_.bracketMinimum( 00182 phi, inOutArg(p_l), inOutArg(p_m), outArg(p_u), outArg(numBracketIters) ); 00183 00184 if (!bracketSuccess) success = false; 00185 00186 totalNumIters += numBracketIters; 00187 00188 // B) Do approximate mimimization in the bracket 00189 00190 if (bracketSuccess) { 00191 00192 int numBrentsIters = -1; 00193 00194 const bool brentsSuccess = brentsMin_.approxMinimize( 00195 phi, p_l, inOutArg(p_m), p_u, outArg(numBrentsIters) ); 00196 00197 if (!brentsSuccess) success = false; 00198 00199 totalNumIters += numBrentsIters; 00200 00201 } 00202 00203 // C) Overall success? 00204 00205 if (!is_null(numIters)) 00206 *numIters = totalNumIters; 00207 00208 return success; 00209 00210 } 00211 00212 00213 } // namespace GlobiPack 00214 00215 00216 #endif // GLOBIPACK_BRENTS_LINE_SEARCH_DEF_HPP
1.7.6.1