NDOSolver / FiOracle
Interfaces and Solvers for NonDifferentiable Optimization
Loading...
Searching...
No Matches
Polyak.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*--------------------------- File Polyak.h ------------------------------*/
3/*--------------------------------------------------------------------------*/
23/*--------------------------------------------------------------------------*/
24/*-------------------- DEFINITIONS & IMPLEMENTATION ------------------------*/
25/*--------------------------------------------------------------------------*/
26
27#ifndef __Polyak
28 #define __Polyak /* 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 Polyak 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/*--------------------------------------------------------------------------*/
68class Polyak : public Stepsize
69{
70/*--------------------------------------------------------------------------*/
71/*----------------------- PUBLIC PART OF THE CLASS -------------------------*/
72/*--------------------------------------------------------------------------*/
73
74 public:
75
76/*--------------------------------------------------------------------------*/
77/*--------------------- PUBLIC METHODS OF THE CLASS ------------------------*/
78/*--------------------------------------------------------------------------*/
79/*---------------------------- CONSTRUCTOR ---------------------------------*/
80/*--------------------------------------------------------------------------*/
88 Polyak( SubGrad *slvr , std::istream *iStrm ) : Stepsize( slvr , iStrm )
89 {
90 DfltdSfInpt( iStrm , Beta , HpNum( 1e-2 ) );
91 }
92
93/*--------------------------------------------------------------------------*/
94/*-------------------------- OTHER INITIALIZATIONS -------------------------*/
95/*--------------------------------------------------------------------------*/
96
97 inline void SetSTPLog( ostream *outs = 0 , const char lvl = 0 );
98
99/*--------------------------------------------------------------------------*/
100
101 void Format( void ) {
103 FiLev = -Inf< HpNum >();
104 }
105
106/*--------------------------------------------------------------------------*/
107/*-------------------- METHODS FOR STEPSIZE COMPUTATION --------------------*/
108/*--------------------------------------------------------------------------*/
109
110 inline void NewStep( void );
111
112/*--------------------------------------------------------------------------*/
113/*---------------------- PROTECTED PART OF THE CLASS -----------------------*/
114/*--------------------------------------------------------------------------*/
115
116 protected:
117
118 inline bool UpdateTargetLevel( void );
119
120/*--------------------------------------------------------------------------*/
121/*--------------------- PRIVATE PART OF THE CLASS --------------------------*/
122/*--------------------------------------------------------------------------*/
123
124 private:
125
126/*--------------------------------------------------------------------------*/
127/*----------------------- PRIVATE DATA STRUCTURES -------------------------*/
128/*--------------------------------------------------------------------------*/
129
130/*--------------------------------------------------------------------------*/
131
132 }; // end( class Polyak )
133
134/*--------------------------------------------------------------------------*/
135/*------------------- inline methods implementation ------------------------*/
136/*--------------------------------------------------------------------------*/
137
138inline void Polyak::SetSTPLog( ostream *outs , const char lvl )
139{
140 Stepsize::SetSTPLog( outs , lvl );
141
142 #if( LOG_STP )
143 if( STPLLvl > 1 ) {
144 *STPLog << endl << "Polyak: Beta = "<< Beta << " ~ Chi = " << LpsFct
145 << endl;
146 }
147 #endif
148 }
149
150/*--------------------------------------------------------------------------*/
151
152inline void Polyak::NewStep( void )
153{
154 // update the target value - - - - - - - - - - - - - - - - - - - - - - - - -
155 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
156
158
159 // some exception - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
160 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
161
162 if( FiLev == -Inf< HpNum >() )
163 throw( NDOException( "Polyak::GetStepsize: no lower bound is given" ) );
164
165 } // end ( Polyak::NewStep )
166
167/*--------------------------------------------------------------------------*/
168
169inline bool Polyak::UpdateTargetLevel( void )
170{
171 cHpNum LwrBnd = GetOracle()->GetLowerBound();
172 if( LwrBnd > FiLev ) {
173 FiLev = LwrBnd;
174 return( true );
175 }
176
177 return( false );
178 }
179
180/*--------------------------------------------------------------------------*/
181
182}; // end( namespace NDO_di_unipi_it )
183
184/*--------------------------------------------------------------------------*/
185/*--------------------------------------------------------------------------*/
186
187#endif /* Polyak.h included */
188
189/*--------------------------------------------------------------------------*/
190/*------------------------- End File Polyak.h ------------------------------*/
191/*--------------------------------------------------------------------------*/
virtual HpNum GetLowerBound(cIndex wFi=Inf< Index >())
Definition FiOracle.h:1601
Definition FiOracle.h:66
Definition Polyak.h:69
bool UpdateTargetLevel(void)
Definition Polyak.h:169
void Format(void)
Definition Polyak.h:101
Polyak(SubGrad *slvr, std::istream *iStrm)
Definition Polyak.h:88
void NewStep(void)
Definition Polyak.h:152
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 LpsFct
scaling factor
Definition Stepsize.h:349
HpNum MaxBeta
maximum value for beta factor
Definition Stepsize.h:347
HpNum FiLev
the target level
Definition Stepsize.h:345
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
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