MoochoPack_DampenCrossTermStd_Step.cpp

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

Generated on Wed May 12 21:32:12 2010 for MoochoPack : Framework for Large-Scale Optimization Algorithms by  doxygen 1.4.7