46 #include "AbstractLinAlgPack_MatrixSymDiagStd.hpp"
47 #include "AbstractLinAlgPack_MatrixSymOpNonsing.hpp"
48 #include "AbstractLinAlgPack_MatrixOpOut.hpp"
49 #include "AbstractLinAlgPack_MultiVectorMutable.hpp"
50 #include "AbstractLinAlgPack_VectorStdOps.hpp"
51 #include "AbstractLinAlgPack_VectorOut.hpp"
52 #include "AbstractLinAlgPack_VectorAuxiliaryOps.hpp"
53 #include "AbstractLinAlgPack_LinAlgOpPack.hpp"
54 #include "AbstractLinAlgPack_assert_print_nan_inf.hpp"
55 #include "ConstrainedOptPack_MatrixIdentConcat.hpp"
56 #include "IterationPack_print_algorithm_step.hpp"
57 #include "MoochoPack_IpState.hpp"
58 #include "MoochoPack_UpdateReducedSigma_Step.hpp"
59 #include "MoochoPack_moocho_algo_conversion.hpp"
61 #include "OptionsFromStreamPack_StringToIntMap.hpp"
63 #include "Teuchos_dyn_cast.hpp"
65 namespace MoochoPack {
68 const e_update_methods update_method
71 update_method_(update_method)
80 using IterationPack::print_algorithm_step;
85 EJournalOutputLevel olevel = algo.algo_cntr().journal_output_level();
89 if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) )
91 using IterationPack::print_algorithm_step;
92 print_algorithm_step( _algo, step_poss, type, assoc_step_poss, out );
95 switch (update_method_)
99 if( (
int)olevel >= (
int)PRINT_ALGORITHM_STEPS )
101 out <<
"\nupdate_method is always_explicit, forming Reduced Sigma Explicitly ...\n";
103 FormReducedSigmaExplicitly(algo,s,olevel,out);
107 case BFGS_DUAL_NO_CORRECTION:
108 case BFGS_DUAL_EXPLICIT_CORRECTION:
109 case BFGS_DUAL_SCALING_CORRECTION:
118 if( (
int)olevel >= (
int)PRINT_ITERATION_QUANTITIES )
120 out <<
"\nrHB_k =\n" << s.rHB().get_k(0);
127 void UpdateReducedSigma_Step::print_step(
128 const Algorithm& _algo, poss_type step_poss, IterationPack::EDoStepType type
129 ,poss_type assoc_step_poss, std::ostream& out,
const std::string& L
132 out << L <<
"*** Update Z'*Sigma*Z\n"
133 << L <<
"if (update_method == always_explicit) then\n"
134 << L <<
" Sigma_k = invXl*Vl-invXu*Vu\n"
135 << L <<
" Sigma_I = Sigma_k.sub_view(Z.I_rng)\n"
136 << L <<
" Sigma_D_sqrt = (Sigma_k.sub_view(Z.D_rng))^1/2\n"
137 << L <<
" J = Sigma_D_sqrt*Z\n"
138 << L <<
" rHB_k = J'*J + Sigma_I\n"
139 << L <<
"elsif ( update_method == BFGS_??? ) then\n"
140 << L <<
" NOT IMPLEMENTED YET!\n"
144 void UpdateReducedSigma_Step::FormReducedSigmaExplicitly(
145 NLPAlgo& algo, IpState& s, EJournalOutputLevel olevel, std::ostream& out
148 namespace mmp = MemMngPack;
153 using LinAlgOpPack::Mp_MtM;
154 using LinAlgOpPack::M_MtM;
156 using LinAlgOpPack::V_MtV;
164 const MatrixIdentConcat &Z =
dyn_cast<MatrixIdentConcat>(s.Z().get_k(0));
165 const MatrixSymDiagStd &invXl = s.invXl().get_k(0);
166 const MatrixSymDiagStd &invXu = s.invXu().get_k(0);
167 const MatrixSymDiagStd &Vl = s.Vl().get_k(0);
168 const MatrixSymDiagStd &Vu = s.Vu().get_k(0);
170 MatrixSymDiagStd &Sigma = s.Sigma().set_k(0);
172 MatrixSymOpNonsing& rHB =
dyn_cast<MatrixSymOpNonsing>(s.rHB().set_k(0));
173 if (rHB.cols() != Z.cols())
176 dyn_cast<MatrixSymInitDiag>(rHB).init_identity(Z.space_rows(), 0.0);
181 ele_wise_prod(1.0, invXl.diag(), Vl.diag(), &(Sigma.diag() = 0.0));
183 if( (
int)olevel >= (int)PRINT_ALGORITHM_STEPS )
184 out <<
"\n||Sigma_l||inf = " << Sigma.diag().norm_inf() << std::endl;
185 if( (
int)olevel >= (
int)PRINT_VECTORS )
186 out <<
"\nSigma_l =\n" << Sigma.diag();
190 if( (
int)olevel >= (int)PRINT_ALGORITHM_STEPS )
191 out <<
"\n||Sigma_k||inf = ||Sigma_l + Sigma_u||inf = " << Sigma.diag().norm_inf() << std::endl;
192 if( (
int)olevel >= (
int)PRINT_VECTORS )
193 out <<
"\nSigma_k = Sigma_l + Sigma_u =\n" << Sigma.diag();
196 VectorSpace::vec_mut_ptr_t temp = Z.space_cols().create_member(0.0);
197 ele_wise_prod(1.0, s.Ypy().get_k(0), Sigma.diag(), temp.get());
198 VectorMutable& w_sigma = s.w_sigma().set_k(0);
201 if( (
int)olevel >= (
int)PRINT_ALGORITHM_STEPS )
202 out <<
"\n||w_sigma_k||inf = " << w_sigma.norm_inf() << std::endl;
203 if( (
int)olevel >= (
int)PRINT_VECTORS )
204 out <<
"\nw_sigma_k = \n" << w_sigma;
210 Sigma_D_diag = Sigma.diag().sub_view(Z.D_rng()),
211 Sigma_I_diag = Sigma.diag().sub_view(Z.I_rng());
213 Sigma_D_nz = Sigma_D_diag->nz(),
214 Sigma_I_nz = Sigma_I_diag->nz();
216 if( (
int)olevel >= (
int)PRINT_ALGORITHM_STEPS )
218 out <<
"\nSigma_D.diag().nz() = " << Sigma_D_nz;
219 out <<
"\nSigma_I.diag().nz() = " << Sigma_I_nz << std::endl;
222 if( Sigma_D_nz || Sigma_I_nz )
224 if( (
int)olevel >= (
int)PRINT_ALGORITHM_STEPS )
226 out <<
"\nForming explicit, nonzero rHB_k = Z_k'*Sigma_k*Z_k ...\n";
231 MatrixSymDiagStd Sigma_D_sqrt(Sigma_D_diag->clone());
235 if( static_cast<int>(olevel) >=
static_cast<int>(PRINT_VECTORS) )
237 out <<
"\nSigma_D_sqrt =\n" << Sigma_D_sqrt;
241 J = Sigma_D_sqrt.space_cols().create_members(Z.cols());
243 static_cast<MatrixOp*>(J.
get())
248 if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ITERATION_QUANTITIES) )
250 out <<
"\nJ =\n" << *J;
251 out <<
"\nJ'*J =\n" << rHB;
259 const MatrixSymDiagStd Sigma_I(
260 Teuchos::rcp_const_cast<VectorMutable>(Sigma_I_diag)
276 if( (
int)olevel >= (
int)PRINT_ALGORITHM_STEPS )
278 out <<
"\nSigma_k is zero so setting rHB_k = 0.0 ...\n";
304 const int local_num_options = 1;
311 const char* local_SOptions[local_num_options] =
316 const int num_update_methods = 5;
318 const char* s_update_methods[num_update_methods] =
322 "BFGS_dual_no_correction",
323 "BFGS_dual_explicit_correction",
324 "BFGS_dual_scaling_correction"
330 UpdateReducedSigma_StepSetOptions::UpdateReducedSigma_StepSetOptions(
331 UpdateReducedSigma_Step* target
332 ,
const char opt_grp_name[] )
334 OptionsFromStreamPack::SetOptionsFromStreamNode(
335 opt_grp_name, local_num_options, local_SOptions ),
336 OptionsFromStreamPack::SetOptionsToTargetBase< UpdateReducedSigma_Step >( target )
340 void UpdateReducedSigma_StepSetOptions::setOption(
341 int option_num,
const std::string& option_value )
345 typedef UpdateReducedSigma_Step target_t;
346 switch( (local_EOptions)option_num )
350 StringToIntMap config_map( UpdateReducedSigma_opt_grp_name, num_update_methods, s_update_methods );
351 target().update_method( (UpdateReducedSigma_Step::e_update_methods) config_map( option_value.c_str() ) );
UpdateReducedSigma_Step(const e_update_methods update_method=ALWAYS_EXPLICIT)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
T_To & dyn_cast(T_From &from)
rSQP Algorithm control class.
void assign(MatrixOp *M_lhs, const MatrixOp &M_rhs, BLAS_Cpp::Transp trans_rhs)
virtual std::ostream & journal_out() const
void M_StM(MatrixOp *M_lhs, value_type alpha, const MatrixOp &M_rhs, BLAS_Cpp::Transp trans_rhs)
void syrk(const MatrixOp &mwo_rhs, BLAS_Cpp::Transp M_trans, value_type alpha, value_type beta, MatrixSymOp *sym_lhs)
void ele_wise_prod(const value_type &alpha, const Vector &v_rhs1, const Vector &v_rhs2, VectorMutable *v_lhs)
AlgorithmTracker & track()
void Mp_M(MatrixOp *M_lhs, const MatrixOp &M_rhs, BLAS_Cpp::Transp trans_rhs)
void ele_wise_sqrt(VectorMutable *z)
bool do_step(Algorithm &algo, poss_type step_poss, IterationPack::EDoStepType type, poss_type assoc_step_poss)
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)