NDOSolver / FiOracle
Interfaces and Solvers for NonDifferentiable Optimization
Loading...
Searching...
No Matches
FumeroTV.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*--------------------------- File FumeroTV.h ------------------------------*/
3/*--------------------------------------------------------------------------*/
23/*--------------------------------------------------------------------------*/
24/*-------------------- DEFINITIONS & IMPLEMENTATION ------------------------*/
25/*--------------------------------------------------------------------------*/
26
27#ifndef __FumeroTV
28 #define __FumeroTV /* self-identification: #endif at the end of the file */
29
30/*--------------------------------------------------------------------------*/
31/*------------------------------ INCLUDES ----------------------------------*/
32/*--------------------------------------------------------------------------*/
33
34#include "Stepsize.h"
35
36/*--------------------------------------------------------------------------*/
37/*------------------------------- MACROS ----------------------------------*/
38/*--------------------------------------------------------------------------*/
39
40#define LOG_STP 0
41
42/* If LOG_STP > 0, the FumeroTV class produces a log of its activities on the
43 ostream object and at the "level of verbosity" set with the method
44 SetSTPLog() [see below]. */
45
46#if( LOG_STP )
47 #define STPLOG( l , x ) if( STPLLvl > l ) *STPLog << x
48 #define STPLOG2( l , c , x ) if( ( STPLLvl > l ) && c ) *STPLog << x
49#else
50 #define STPLOG( l , x )
51 #define STPLOG2( l , c , x )
52#endif
53
54/*--------------------------------------------------------------------------*/
55/*----------------------------- NAMESPACE ----------------------------------*/
56/*--------------------------------------------------------------------------*/
57
58namespace NDO_di_unipi_it
59{
60
61/*--------------------------------------------------------------------------*/
62/*--------------------------- GENERAL NOTES --------------------------------*/
63/*--------------------------------------------------------------------------*/
71class FumeroTV : public Stepsize
72{
73
74/*--------------------------------------------------------------------------*/
75/*----------------------- PUBLIC PART OF THE CLASS -------------------------*/
76/*--------------------------------------------------------------------------*/
77
78 public:
79
80/*--------------------------------------------------------------------------*/
81/*--------------------- PUBLIC METHODS OF THE CLASS ------------------------*/
82/*--------------------------------------------------------------------------*/
83/*---------------------------- CONSTRUCTOR ---------------------------------*/
84/*--------------------------------------------------------------------------*/
101 FumeroTV( SubGrad *slvr , std::istream *iStrm = NULL )
102 : Stepsize( slvr , iStrm )
103 {
104 DfltdSfInpt( iStrm , sigmaMin , HpNum( 1e-4 ) );
105 DfltdSfInpt( iStrm , r1 , Index( 5 ) );
106 DfltdSfInpt( iStrm , BetaZero , HpNum( 1 ) );
107 DfltdSfInpt( iStrm , eta1 , Index( 5 ) );
108 DfltdSfInpt( iStrm , eta2 , Index( 5 ) );
109 }
110
111/*--------------------------------------------------------------------------*/
112/*-------------------------- OTHER INITIALIZATIONS -------------------------*/
113/*--------------------------------------------------------------------------*/
114
115 inline void SetSTPLog( ostream *outs = 0 , const char lvl = 0 );
116
117/*--------------------------------------------------------------------------*/
118
119 inline void Format( void );
120
121/*--------------------------------------------------------------------------*/
122/*-------------------- METHODS FOR STEPSIZE COMPUTATION --------------------*/
123/*--------------------------------------------------------------------------*/
124
125 inline void NewStep( void );
126
127/*--------------------------------------------------------------------------*/
128/*---------------------- PROTECTED PART OF THE CLASS -----------------------*/
129/*--------------------------------------------------------------------------*/
130
131 protected:
132
133 inline bool UpdateTargetLevel( void );
134
135/*--------------------------------------------------------------------------*/
136/*--------------------- PRIVATE PART OF THE CLASS --------------------------*/
137/*--------------------------------------------------------------------------*/
138
139 private:
140
141/*--------------------------------------------------------------------------*/
142/*-------------------------- PRIVATE METHODS -------------------------------*/
143/*--------------------------------------------------------------------------*/
144
145 inline HpNum ExpFun( Index ri );
146
147/*--------------------------------------------------------------------------*/
148/*----------------------- PRIVATE DATA STRUCTURES -------------------------*/
149/*--------------------------------------------------------------------------*/
150
152
155
158
159 HpNum BetaZero;
160
162 Index r1;
163 Index r2;
164
167 Index eta2;
168
169/*--------------------------------------------------------------------------*/
170
171 }; // end( class FumeroTV )
172
173/*--------------------------------------------------------------------------*/
174/*------------------- inline methods implementation ------------------------*/
175/*--------------------------------------------------------------------------*/
176
177inline void FumeroTV::Format( void )
178{
180 Beta = BetaZero;
181
183 // FiLambda and the reference value are not known
184 LwrBnd = -Inf< HpNum >(); // no lower bound or target level is known
185
186 etac = rc = 0;
187 r2 = ceil( pow( ( - log( sigmaMin ) / 0.6933 ) , ( 1.0 / 3.26 ) ) * r1 );
188
189 sigma = 1;
190
191 } // end ( FumeroTV::Format() )
192
193/*--------------------------------------------------------------------------*/
194
195inline void FumeroTV::NewStep( void )
196{
197 // get the function value - - - - - - - - - - - - - - - - - - - - - - - - -
198 //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
199
201
202 if( FiLambda == Inf< HpNum >() )
203 throw( NDOException( "FumeroTV::GetStepsize: this should not happen" ) );
204
205 // try to improve the target level - - - - - - - - - - - - - - - - - - - - -
206 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
207
208 bool TLchgd = UpdateTargetLevel();
209
210 // update target level- - - - - - - - - - - - - - - - - - - - - - - - - - - -
211 //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
212
213 if( TLchgd )
214 FiLev = sigma * LwrBnd + ( 1 - sigma ) * FiRef;
215
216 // fix beta - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
217 //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
218
219 if( Beta < 1e-6 )
220 Beta = 1e-6;
221
222 // print the level - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
223
224 STPLOG( 1 , endl << " " << " level = " << -FiLev << " ~ beta = "
225 << Beta << endl << " " );
226
227 } // end( FumeroTV::NewStep )
228
229/*--------------------------------------------------------------------------*/
230
231inline void FumeroTV::SetSTPLog( ostream *outs , const char lvl )
232{
233 Stepsize::SetSTPLog( outs , lvl );
234
235 #if( LOG_STP )
236 if( STPLLvl > 1 ) {
237 *STPLog << endl << "FumeroTV: ~ BetaZero = " << BetaZero
238 << " ~ (Eps0 , r1) = (" << sigma << " , " << r1 << ")"
239 << " ~ Eta = {" << eta1 << " , " << eta2 << "}" << endl;
240 }
241 #endif
242 } // end( FumeroTV::SetSTPLog )
243
244/*--------------------------------------------------------------------------*/
245
247{
248 bool TLchgd = false;
249
250 // the target level is updated if any changes of the lower bound occurs - - -
251 //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
252
253 cHpNum LwrBnd_ = GetOracle()->GetLowerBound();
254 if( LwrBnd_ > LwrBnd ) {
255 LwrBnd = LwrBnd_;
256 TLchgd = true;
257 }
258
259 // some exception - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
260 //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
261
262 if( LwrBnd == - Inf< HpNum >() )
263 throw( NDOException(
264 "FumeroTV::UpdateTargetLevel: no lower bound is given" ) );
265 HpNum FiRef_;
266 if( FiRef == Inf< HpNum >() ) // not initialized yet
267 FiRef_ = Inf< HpNum >();
268 else
269 FiRef_ = FiRef - ( 1e-6 * std::max( HpNum( 1.0 ) , std::abs( FiRef ) ) );
270
271 // beta updating- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
272 //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
273
274 if( FiLambda <= FiRef_ ) {
275 FiRef = FiLambda;
276 if( rc >= r2 )
277 Beta *= 2.0;
278 etac = 0;
279 TLchgd = true;
280 }
281 else // FiLambda > FiRef_
282 if( rc >= r2 ) {
283 if( ++etac >= eta2 ) {
284 Beta /= 2;
285 etac = 0;
286 }
287 }
288 else
289 if( ++etac >= eta1 ) {
290 Beta = Beta / ( 2.0 * Beta + 1.0 );
291 sigma = ExpFun( ++rc );
292 TLchgd = true;
293 etac = 0;
294 }
295
296 // failure of the target level updating - - - - - - - - - - - - - - - - - - -
297 //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
298
299 if( FiLev < LwrBnd ) { // change the level
300 FiLev = LwrBnd;
301 TLchgd = true;
302 }
303
304 return( TLchgd );
305
306 } // end( FumeroTV::UpdateTargetLevel )
307
308/*--------------------------------------------------------------------------*/
309
310inline HpNum FumeroTV::ExpFun( Index ri )
311{
312 return( exp( -0.6933 * pow( HpNum( ri ) / HpNum( r1 ) , 3.26 ) ) );
313
314 } // end( FumeroTV::ExpFun )
315
316/*--------------------------------------------------------------------------*/
317
318}; // end( namespace NDO_di_unipi_it )
319
320/*--------------------------------------------------------------------------*/
321/*--------------------------------------------------------------------------*/
322
323#endif /* FumeroTV.h included */
324
325/*--------------------------------------------------------------------------*/
326/*------------------------- End File FumeroTV.h ----------------------------*/
327/*--------------------------------------------------------------------------*/
virtual HpNum GetLowerBound(cIndex wFi=Inf< Index >())
Definition FiOracle.h:1601
Definition FumeroTV.h:72
Index etac
last improvement of FiLev
Definition FumeroTV.h:165
Index rc
current value of r
Definition FumeroTV.h:161
HpNum FiLambda
FiLambda.
Definition FumeroTV.h:151
FumeroTV(SubGrad *slvr, std::istream *iStrm=NULL)
Definition FumeroTV.h:101
HpNum FiRef
the best solution found so far
Definition FumeroTV.h:154
HpNum sigma
current value of
Definition FumeroTV.h:156
bool UpdateTargetLevel(void)
Definition FumeroTV.h:246
HpNum sigmaMin
minimum threshold of
Definition FumeroTV.h:157
Index eta1
thresholds for max number of failures
Definition FumeroTV.h:166
void Format(void)
Definition FumeroTV.h:177
HpNum LwrBnd
lower bound
Definition FumeroTV.h:153
void NewStep(void)
Definition FumeroTV.h:195
Definition FiOracle.h:66
Definition Stepsize.h:63
std::ostream * STPLog
the output stream object
Definition Stepsize.h:342
virtual void SetSTPLog(std::ostream *outs=0, const char lvl=0)
Definition Stepsize.h:126
HpNum Beta
beta factor
Definition Stepsize.h:346
char STPLLvl
the "level of verbosity"
Definition Stepsize.h:343
HpNum FiLev
the target level
Definition Stepsize.h:345
virtual void Format(void)
Definition Stepsize.h:137
FiOracle * GetOracle(void)
Definition SubGrad.h:148
const HpNum cHpNum
a read-only HpNum
Definition OPTtypes.h:102
double HpNum
"finer" floating point numbers
Definition OPTtypes.h:98
unsigned int Index
Index in a vector ( >= 0 )
Definition OPTtypes.h:60
static constexpr T Inf(void) noexcept
Inf< T >() = infinity value for T.
Definition OPTUtils.h:357
void DfltdSfInpt(istream *iStrm, T &Param, const T Dflt, const char cmntc='#')
Definition OPTUtils.h:392
Definition Bundle.h:68