|
MoochoPack : Framework for Large-Scale Optimization Algorithms
Version of the Day
|
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 // Redistribution and use in source and binary forms, with or without 00011 // modification, are permitted provided that the following conditions are 00012 // met: 00013 // 00014 // 1. Redistributions of source code must retain the above copyright 00015 // notice, this list of conditions and the following disclaimer. 00016 // 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // 3. Neither the name of the Corporation nor the names of the 00022 // contributors may be used to endorse or promote products derived from 00023 // this software without specific prior written permission. 00024 // 00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 // 00037 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 00038 // 00039 // *********************************************************************** 00040 // @HEADER 00041 00042 #include <typeinfo> 00043 #include <limits> 00044 00045 #include "MoochoPack_CheckDecompositionFromPy_Step.hpp" 00046 #include "MoochoPack_moocho_algo_conversion.hpp" 00047 #include "IterationPack_print_algorithm_step.hpp" 00048 #include "AbstractLinAlgPack_Vector.hpp" 00049 #include "AbstractLinAlgPack_LinAlgOpPack.hpp" 00050 00051 namespace MoochoPack { 00052 00053 CheckDecompositionFromPy_Step::CheckDecompositionFromPy_Step( 00054 const new_decomp_strategy_ptr_t &new_decomp_strategy 00055 ,value_type max_decomposition_cond_change_frac 00056 ) 00057 :new_decomp_strategy_(new_decomp_strategy) 00058 ,max_decomposition_cond_change_frac_( max_decomposition_cond_change_frac ) 00059 ,max_cond_( 0.01 / std::numeric_limits<value_type>::epsilon() ) 00060 { 00061 reset(); 00062 } 00063 00064 void CheckDecompositionFromPy_Step::reset() { 00065 beta_min_ = std::numeric_limits<value_type>::max(); 00066 } 00067 00068 // Overridden 00069 00070 bool CheckDecompositionFromPy_Step::do_step( 00071 Algorithm& _algo, poss_type step_poss, IterationPack::EDoStepType type, poss_type assoc_step_poss 00072 ) 00073 { 00074 NLPAlgo &algo = rsqp_algo(_algo); 00075 NLPAlgoState &s = algo.rsqp_state(); 00076 const Range1D equ_decomp = s.equ_decomp(); 00077 EJournalOutputLevel olevel = algo.algo_cntr().journal_output_level(); 00078 std::ostream &out = algo.track().journal_out(); 00079 00080 // print step header. 00081 if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) { 00082 using IterationPack::print_algorithm_step; 00083 print_algorithm_step( algo, step_poss, type, assoc_step_poss, out ); 00084 } 00085 00086 bool select_new_decomposition = false; 00087 00088 const value_type 00089 small_num = std::numeric_limits<value_type>::min(), 00090 beta = s.py().get_k(0).norm_inf() / (s.c().get_k(0).sub_view(equ_decomp)->norm_inf()+small_num); 00091 00092 if( (int)olevel >= (int)PRINT_ALGORITHM_STEPS ) { 00093 out << "\nbeta = ||py||/||c|| = " << beta << std::endl; 00094 } 00095 00096 // Check to see if a new basis was selected or not 00097 IterQuantityAccess<index_type> 00098 &num_basis_iq = s.num_basis(); 00099 if( num_basis_iq.updated_k(0) ) { 00100 if( (int)olevel >= (int)PRINT_ALGORITHM_STEPS ) 00101 out << "\nnum_basis_k was updated so the basis changed so we will skip this check\n" 00102 << " reset min ||py||/||c|| to current value + 1\n"; 00103 beta_min_ = beta + 1.0; 00104 return true; 00105 } 00106 00107 if( beta + 1.0 < beta_min_ ) { 00108 beta_min_ = beta + 1.0; 00109 } 00110 else { 00111 if( (beta + 1.0)/ beta_min_ > max_decomposition_cond_change_frac() ) { 00112 if( (int)olevel >= (int)PRINT_BASIC_ALGORITHM_INFO ) { 00113 out << "Select a new decomposition" 00114 << " (k = " << algo.state().k() << ")\n" 00115 << "beta_change = ( ||py||/||c|| = " << beta 00116 << " ) / ( min ||py||/||c|| = " << beta_min_ << " )\n" 00117 << "beta_change = " << (beta/beta_min_) << " > max_decomposition_cond_change_frac = " 00118 << max_decomposition_cond_change_frac() << std::endl; 00119 } 00120 select_new_decomposition = true; 00121 } 00122 } 00123 if( !select_new_decomposition && beta > max_cond() ) { 00124 if( (int)olevel >= (int)PRINT_BASIC_ALGORITHM_INFO ) { 00125 out << "\nConditioning of decomposition matrix is > " << beta 00126 << " > max_cond = " << max_cond() << std::endl 00127 << "Selecting a new decomposition ... " 00128 << " (k = " << algo.state().k() << ")\n"; 00129 } 00130 select_new_decomposition = true; 00131 } 00132 00133 if(select_new_decomposition) { 00134 reset(); 00135 return new_decomp_strategy().new_decomposition(algo,step_poss,type,assoc_step_poss); 00136 } 00137 00138 return true; 00139 } 00140 00141 void CheckDecompositionFromPy_Step::print_step( 00142 const Algorithm& algo, poss_type step_poss 00143 ,IterationPack::EDoStepType type, poss_type assoc_step_poss 00144 ,std::ostream& out, const std::string& L ) const 00145 { 00146 out 00147 << L << "default: beta_min = inf\n" 00148 << L << " max_decomposition_cond_change_frac = " << max_decomposition_cond_change_frac() << std::endl 00149 << L << " max_cond = 0.01 * mach_eps\n" 00150 << L << "beta = norm_inf(py_k) / (norm_inf(c_k(equ_decomp))+small_number)\n" 00151 << L << "select_new_decomposition = false\n" 00152 << L << "if num_basis_k is updated then\n" 00153 << L << " beta_min = beta + 1\n" 00154 << L << "end\n" 00155 << L << "if beta + 1 < beta_min then\n" 00156 << L << " beta_min = beta + 1\n" 00157 << L << "else\n" 00158 << L << " if (beta + 1) / beta_min > max_decomposition_cond_change_frac then\n" 00159 << L << " select_new_decomposition = true\n" 00160 << L << " end\n" 00161 << L << "end\n" 00162 << L << "if beta > max_cond then\n" 00163 << L << " select_new_decomposition = true\n" 00164 << L << "end\n" 00165 << L << "if select_new_decomposition == true then\n" 00166 << L << " new decomposition selection : " << typeName(new_decomp_strategy()) << std::endl 00167 ; 00168 new_decomp_strategy().print_new_decomposition( 00169 rsqp_algo(algo),step_poss,type,assoc_step_poss,out, L + " " ); 00170 out 00171 << L << " end new decomposition selection\n" 00172 << L << "end\n" 00173 ; 00174 } 00175 00176 } // end namespace MoochoPack
1.7.6.1