MoochoPack_DampenCrossTermStd_Step.cpp

Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
00005 //                  Copyright (2003) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #include <ostream>
00030 #include <sstream>
00031 #include <limits>
00032 
00033 #include "../std/MoochoPack_DampenCrossTermStd_Step.hpp"
00034 #include "../MoochoPack_moocho_algo_conversion.hpp"
00035 #include "IterationPack_print_algorithm_step.hpp"
00036 #include "ConstrainedOptPack/src/VectorWithNorms.h"
00037 #include "AbstractLinAlgPack/src/MatrixWithOpFactorized.hpp"
00038 #include "DenseLinAlgPack_LinAlgOpPack.hpp"
00039 #include "DenseLinAlgPack_DVectorClass.hpp"
00040 #include "DenseLinAlgPack_DVectorOut.hpp"
00041 
00042 MoochoPack::DampenCrossTermStd_Step::DampenCrossTermStd_Step(const value_type& frac_descent)
00043   : frac_descent_(frac_descent)
00044 {}
00045 
00046 bool MoochoPack::DampenCrossTermStd_Step::do_step(Algorithm& _algo
00047   , poss_type step_poss, IterationPack::EDoStepType type, poss_type assoc_step_poss)
00048 {
00049   using AbstractLinAlgPack::V_InvMtV;
00050   using DenseLinAlgPack::norm_inf;
00051   using DenseLinAlgPack::dot;
00052 
00053   NLPAlgo &algo = rsqp_algo(_algo);
00054   NLPAlgoState  &s    = algo.rsqp_state();
00055 
00056   EJournalOutputLevel olevel = algo.algo_cntr().journal_output_level();
00057   std::ostream& out = algo.track().journal_out();
00058 
00059   // print step header.
00060   if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) {
00061     using IterationPack::print_algorithm_step;
00062     print_algorithm_step( _algo, step_poss, type, assoc_step_poss, out );
00063   }
00064 
00065   if( s.w().updated_k(0) ) {
00066 
00067     // inv(rHL_k) * rGf_k
00068     const DVectorSlice rGf_k = s.rGf().get_k(0)();
00069     DVector Inv_rHL_rGf;
00070     V_InvMtV( &Inv_rHL_rGf, dynamic_cast<MatrixWithOpFactorized&>(s.rHL().get_k(0))
00071       , BLAS_Cpp::no_trans, rGf_k );
00072     
00073     const value_type
00074       small_num     = 1e-20,
00075       rGfT_Inv_rHL_rGf  = dot( Inv_rHL_rGf(), rGf_k ),          // rGf_k'*inv(rHL_k)*rGf_k
00076       rGfT_Inv_rHL_w    = dot( Inv_rHL_rGf(), s.w().get_k(0)() ),   // rGf_k'*inv(rHL_k)*w_k
00077       term        = -(1.0-frac_descent()) * (rGfT_Inv_rHL_rGf + 2*small_num)
00078                   / (rGfT_Inv_rHL_w + small_num);
00079 
00080     if( rGfT_Inv_rHL_w >= 0.0 ) {
00081       // We know that the descent property will be satisfied for all zeta_k > 0
00082       // so set zeta_k = 1
00083       s.zeta().set_k(0) = 1.0;
00084     }
00085     else {
00086       // For some zeta_k > 0 the descent property will be violated so we may have to
00087       // cut zeta_k back from 1.
00088       s.zeta().set_k(0) = std::_MIN( term, 1.0 );
00089     }
00090 
00091     if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) {
00092       out << "\nterm1 = rGf_k'*inv(rHL_k)*rGf_k                = "  <<  rGfT_Inv_rHL_rGf;
00093       out << "\nterm2 = rGf_k'*inv(rHL_k)*w_k                  = "  <<  rGfT_Inv_rHL_w;
00094       out << "\n(1-frac_descent)*(term1+2*small)/(term2+small) = "  <<  term;
00095       out << "\nzeta_k                                         = "  <<  s.zeta().get_k(0)
00096         << std::endl;
00097     }
00098 
00099     if( static_cast<int>(olevel) >= static_cast<int>(PRINT_VECTORS) ) {
00100       out << "\ninv(rHL_k)*rGf_k = "  <<  Inv_rHL_rGf();
00101     }
00102 
00103     if( rGfT_Inv_rHL_rGf < 0.0 ) {
00104       std::ostringstream omsg;
00105       omsg
00106         << "Error, rGf_k'*inv(rHL_k)*rGf_k = " << rGfT_Inv_rHL_rGf << " < 0.0 and therefore "
00107         << "the reduced Hessian rHL_k can not be positive definite";
00108       if( (int)(olevel) >= (int)(PRINT_ALGORITHM_STEPS) ) {
00109         out << omsg.str();
00110       }
00111       throw std::runtime_error( std::string("DampenCrossTermStd_Step::do_step(...) : ")
00112                     + omsg.str() );
00113     }
00114   }
00115 
00116   return true;
00117 }
00118 
00119 void MoochoPack::DampenCrossTermStd_Step::print_step( const Algorithm& algo
00120   , poss_type step_poss, IterationPack::EDoStepType type, poss_type assoc_step_poss
00121   , std::ostream& out, const std::string& L ) const
00122 {
00123   out
00124     << L << "*** Compute the dampening parameter for the reduced QP cross term w_k\n"
00125     << L << "default: frac_descent = " << frac_descent() << std::endl
00126     << L << "if w_k is update then\n"
00127     << L << "    find zeta_k s.t.\n"
00128     << L << "        Gf_k'*Z_k*pz_k ~\n"
00129     << L << "           - zeta_k * rGf_k'*inv(rHL_k)*w_k - rGf_k'*inv(rHL_k)*rGf_k\n"
00130     << L << "             <= - frac_descent * rGf_k'*inv(rHL_k)*rGf_k\n"
00131     << L << "end\n";
00132 }

Generated on Thu Sep 18 12:35:17 2008 for MOOCHO (Single Doxygen Collection) by doxygen 1.3.9.1