MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MoochoPack_DampenCrossTermStd_Step.cpp
Go to the documentation of this file.
1 #if 0
2 
3 // @HEADER
4 // ***********************************************************************
5 //
6 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
7 // Copyright (2003) Sandia Corporation
8 //
9 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
10 // license for use of this work by or on behalf of the U.S. Government.
11 //
12 // Redistribution and use in source and binary forms, with or without
13 // modification, are permitted provided that the following conditions are
14 // met:
15 //
16 // 1. Redistributions of source code must retain the above copyright
17 // notice, this list of conditions and the following disclaimer.
18 //
19 // 2. Redistributions in binary form must reproduce the above copyright
20 // notice, this list of conditions and the following disclaimer in the
21 // documentation and/or other materials provided with the distribution.
22 //
23 // 3. Neither the name of the Corporation nor the names of the
24 // contributors may be used to endorse or promote products derived from
25 // this software without specific prior written permission.
26 //
27 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
28 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
31 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 //
39 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
40 //
41 // ***********************************************************************
42 // @HEADER
43 
44 #include <ostream>
45 #include <sstream>
46 #include <limits>
47 
51 #include "ConstrainedOptPack/src/VectorWithNorms.h"
52 #include "AbstractLinAlgPack/src/MatrixWithOpFactorized.hpp"
56 
58  : frac_descent_(frac_descent)
59 {}
60 
62  , poss_type step_poss, IterationPack::EDoStepType type, poss_type assoc_step_poss)
63 {
67 
68  NLPAlgo &algo = rsqp_algo(_algo);
69  NLPAlgoState &s = algo.rsqp_state();
70 
71  EJournalOutputLevel olevel = algo.algo_cntr().journal_output_level();
72  std::ostream& out = algo.track().journal_out();
73 
74  // print step header.
75  if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) {
77  print_algorithm_step( _algo, step_poss, type, assoc_step_poss, out );
78  }
79 
80  if( s.w().updated_k(0) ) {
81 
82  // inv(rHL_k) * rGf_k
83  const DVectorSlice rGf_k = s.rGf().get_k(0)();
84  DVector Inv_rHL_rGf;
85  V_InvMtV( &Inv_rHL_rGf, dynamic_cast<MatrixWithOpFactorized&>(s.rHL().get_k(0))
86  , BLAS_Cpp::no_trans, rGf_k );
87 
88  const value_type
89  small_num = 1e-20,
90  rGfT_Inv_rHL_rGf = dot( Inv_rHL_rGf(), rGf_k ), // rGf_k'*inv(rHL_k)*rGf_k
91  rGfT_Inv_rHL_w = dot( Inv_rHL_rGf(), s.w().get_k(0)() ), // rGf_k'*inv(rHL_k)*w_k
92  term = -(1.0-frac_descent()) * (rGfT_Inv_rHL_rGf + 2*small_num)
93  / (rGfT_Inv_rHL_w + small_num);
94 
95  if( rGfT_Inv_rHL_w >= 0.0 ) {
96  // We know that the descent property will be satisfied for all zeta_k > 0
97  // so set zeta_k = 1
98  s.zeta().set_k(0) = 1.0;
99  }
100  else {
101  // For some zeta_k > 0 the descent property will be violated so we may have to
102  // cut zeta_k back from 1.
103  s.zeta().set_k(0) = std::_MIN( term, 1.0 );
104  }
105 
106  if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) {
107  out << "\nterm1 = rGf_k'*inv(rHL_k)*rGf_k = " << rGfT_Inv_rHL_rGf;
108  out << "\nterm2 = rGf_k'*inv(rHL_k)*w_k = " << rGfT_Inv_rHL_w;
109  out << "\n(1-frac_descent)*(term1+2*small)/(term2+small) = " << term;
110  out << "\nzeta_k = " << s.zeta().get_k(0)
111  << std::endl;
112  }
113 
114  if( static_cast<int>(olevel) >= static_cast<int>(PRINT_VECTORS) ) {
115  out << "\ninv(rHL_k)*rGf_k = " << Inv_rHL_rGf();
116  }
117 
118  if( rGfT_Inv_rHL_rGf < 0.0 ) {
119  std::ostringstream omsg;
120  omsg
121  << "Error, rGf_k'*inv(rHL_k)*rGf_k = " << rGfT_Inv_rHL_rGf << " < 0.0 and therefore "
122  << "the reduced Hessian rHL_k can not be positive definite";
123  if( (int)(olevel) >= (int)(PRINT_ALGORITHM_STEPS) ) {
124  out << omsg.str();
125  }
126  throw std::runtime_error( std::string("DampenCrossTermStd_Step::do_step(...) : ")
127  + omsg.str() );
128  }
129  }
130 
131  return true;
132 }
133 
134 void MoochoPack::DampenCrossTermStd_Step::print_step( const Algorithm& algo
135  , poss_type step_poss, IterationPack::EDoStepType type, poss_type assoc_step_poss
136  , std::ostream& out, const std::string& L ) const
137 {
138  out
139  << L << "*** Compute the dampening parameter for the reduced QP cross term w_k\n"
140  << L << "default: frac_descent = " << frac_descent() << std::endl
141  << L << "if w_k is update then\n"
142  << L << " find zeta_k s.t.\n"
143  << L << " Gf_k'*Z_k*pz_k approx\n"
144  << L << " - zeta_k * rGf_k'*inv(rHL_k)*w_k - rGf_k'*inv(rHL_k)*rGf_k\n"
145  << L << " <= - frac_descent * rGf_k'*inv(rHL_k)*rGf_k\n"
146  << L << "end\n";
147 }
148 
149 #endif // 0
void print_step(const Algorithm &algo, poss_type step_poss, IterationPack::EDoStepType type, poss_type assoc_step_poss, std::ostream &out, const std::string &leading_str) const
Not transposed.
EJournalOutputLevel
enum for journal output.
std::ostream * out
void print_algorithm_step(const Algorithm &algo, Algorithm::poss_type step_poss, EDoStepType type, Algorithm::poss_type assoc_step_poss, std::ostream &out)
Prints to 'out' the algorithm step.
void V_InvMtV(VectorMutable *v_lhs, const MatrixNonsing &M_rhs1, BLAS_Cpp::Transp trans_rhs1, const Vector &v_rhs2)
v_lhs = inv(op(M_rhs1)) * v_rhs2
value_type dot(const Vector &v_rhs1, const Vector &v_rhs2)
result = v_rhs1' * v_rhs2
DenseLinAlgPack::VectorSliceTmpl< value_type > DVectorSlice
AbstractLinAlgPack::value_type value_type
DampenCrossTermStd_Step(const value_type &frac_descent=0.9)
bool do_step(Algorithm &algo, poss_type step_poss, IterationPack::EDoStepType type, poss_type assoc_step_poss)
value_type norm_inf(const DVectorSlice &vs_rhs)
result = ||vs_rhs||infinity (BLAS IxAMAX)
NLPAlgo & rsqp_algo(Algorithm &algo)
Convert from a Algorithm to a NLPAlgo.
value_type dot(const DVectorSlice &vs_rhs1, const DVectorSlice &vs_rhs2)
result = vs_rhs1' * vs_rhs2 (BLAS xDOT)