NDOSolver / FiOracle
Interfaces and Solvers for NonDifferentiable Optimization
Loading...
Searching...
No Matches
PrimalDual.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*----------------------- File PrimalDual.h --------------------------------*/
3/*--------------------------------------------------------------------------*/
27/*--------------------------------------------------------------------------*/
28/*-------------------- DEFINITIONS & IMPLEMENTATION ------------------------*/
29/*--------------------------------------------------------------------------*/
30
31#ifndef __PrimalDual
32 #define __PrimalDual /* self-identification: #endif at the end of the file */
33
34/*--------------------------------------------------------------------------*/
35/*------------------------------- MACROS ----------------------------------*/
36/*--------------------------------------------------------------------------*/
37
38#define LOG_VOL 0
39
40/* If LOG_VOL > 0, the PrimalDual class produces a log of its activities on
41 the ostream object and at the "level of verbosity" set with the method
42 SetVOLLog() [see below]. */
43
44#if( LOG_VOL )
45 #define VOLLOG( l , x ) if( VOLLLvl > l ) *VOLLog << x
46 #define VOLLOG2( l , c , x ) if( ( VOLLLvl > l ) && c ) *VOLLog << x
47#else
48 #define VOLLOG( l , x )
49 #define VOLLOG2( l , c , x )
50#endif
51
52/*--------------------------------------------------------------------------*/
53/*------------------------------ INCLUDES ----------------------------------*/
54/*--------------------------------------------------------------------------*/
55
56#include "Deflection.h"
57#include "Stepsize.h"
58
59#include <cmath>
60
61/*--------------------------------------------------------------------------*/
62/*----------------------------- NAMESPACE ----------------------------------*/
63/*--------------------------------------------------------------------------*/
64
65namespace NDO_di_unipi_it
66{
67
68/*--------------------------------------------------------------------------*/
69/*--------------------------- GENERAL NOTES --------------------------------*/
70/*--------------------------------------------------------------------------*/
89class PrimalDual : public Deflection , public Stepsize
90{
91/*--------------------------------------------------------------------------*/
92/*----------------------- PUBLIC PART OF THE CLASS -------------------------*/
93/*--------------------------------------------------------------------------*/
94
95 public:
96
97/*--------------------------------------------------------------------------*/
98/*--------------------- PUBLIC METHODS OF THE CLASS ------------------------*/
99/*--------------------------------------------------------------------------*/
100/*---------------------------- CONSTRUCTOR ---------------------------------*/
101/*--------------------------------------------------------------------------*/
102
115 PrimalDual( SubGrad *slvr , istream *iStrm = 0 )
116 : Deflection( slvr ) , Stepsize( slvr , iStrm )
117 {
118 DfltdSfInpt( iStrm , average , bool( true ) );
119 }
120
121/*--------------------------------------------------------------------------*/
122/*-------------------------- OTHER INITIALIZATIONS -------------------------*/
123/*--------------------------------------------------------------------------*/
124
125 inline void SetVOLLog( ostream *outs = 0 , const char lvl = 0 );
126
127 inline void Format( void );
128
129/*--------------------------------------------------------------------------*/
130/*----------------------- METHODS FOR DR and SR COMPUTATION --------------*/
131/*--------------------------------------------------------------------------*/
135 inline void NewDEF( void );
136
137 inline void NewStep( void );
138
139/*--------------------------------------------------------------------------*/
140
141 inline HpNum GetDFLCoeff( void );
142
143 inline HpNum GetStepsize( bool StepIsIncr = false );
144
145/*--------------------------------------------------------------------------*/
146
147 HpNum GetLev( void )
148 {
149 throw( NDOException( "PrimalDual::GetLev: not allowed" ) );
150 }
151
152/*--------------------------------------------------------------------------*/
153
155 {
156 throw( NDOException( "PrimalDual::GetBeta: not allowed" ) );
157 }
158
159/*--------------------------------------------------------------------------*/
160
161 void SetMaxBeta( const HpNum alpha )
162 {
163 throw( NDOException( "PrimalDual::SetMaxBeta: not allowed" ) );
164 }
165
166/*--------------------------------------------------------------------------*/
167/*--------------------- PRIVATE PART OF THE CLASS --------------------------*/
168/*--------------------------------------------------------------------------*/
169
170 private:
171
172/*--------------------------------------------------------------------------*/
173/*--------------------------- PRIVATE METHODS ------------------------------*/
174/*--------------------------------------------------------------------------*/
175
176 inline void UpdateGamma( void );
177
178/*--------------------------------------------------------------------------*/
179/*----------------------- PRIVATE DATA STRUCTURES -------------------------*/
180/*--------------------------------------------------------------------------*/
181
182 HpNum delta;
183 HpNum Tmpdelta;
184 HpNum vk;
185
186 HpNum StepSize;
187 HpNum gamma;
188
189 HpNum beta1;
190 bool average;
191
192 HpNum LipCnst; // Lipschitz constant
193
194/*--------------------------------------------------------------------------*/
195/*--------------------------------------------------------------------------*/
196
197 }; // end( class PrimalDual )
198
199/*--------------------------------------------------------------------------*/
200/*------------------- inline methods implementation ------------------------*/
201/*--------------------------------------------------------------------------*/
202
203inline void PrimalDual::SetVOLLog( ostream *outs , const char lvl )
204{
205 Deflection::SetVOLLog( outs , lvl );
206
207 #if( LOG_VOL )
208 if( VOLLLvl > 1 )
209 if( average )
210 *VOLLog << endl << "PrimalDual: Simple averages ";
211 else
212 *VOLLog << endl << "PrimalDual: Weighted averages ";
213
214 *VOLLog << "~ GammaFact = " << LpsFct << endl;
215 #endif
216
217} // end( PrimalDual::SetVOLLog )
218
219/*--------------------------------------------------------------------------*/
220
221inline void PrimalDual::Format( void )
222{
224
226 if( LipTmp != LipCnst )
227 LipCnst = LipTmp;
228
229 beta1 = 1;
230 delta = 0;
231
232 } // end( PrimalDual::Format )
233
234/*--------------------------------------------------------------------------*/
235
236inline void PrimalDual::NewStep( void )
237{
238 // update the Lipschitz constant - - - - - - - - - - - - - - - - - - - - - -
239 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
240
242 if( LipTmp != LipCnst )
243 LipCnst = LipTmp;
244
245 UpdateGamma();
246
247 // SR computation - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
248 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
249
250 StepSize = Tmpdelta / ( gamma * beta1 );
251
252 VOLLOG( 1, endl << " Delta = " << Tmpdelta << " ~ Beta = "
253 << beta1 << " ~ gamma = " << gamma );
254
255 delta = Tmpdelta;
256 beta1 = ( beta1 + 1/beta1 );
257
258 } // end( PrimalDual::NewStep )
259
260/*--------------------------------------------------------------------------*/
261
262inline HpNum PrimalDual::GetStepsize( bool StepIsIncr )
263{
264 if( StepIsIncr )
265 throw( NDOException( "PrimalDual::GetStepsize: this is not allowed" ) );
266
267 return( StepSize );
268
269 } // end( PrimalDual::GetStepsize )
270
271/*--------------------------------------------------------------------------*/
272
273inline void PrimalDual::NewDEF( void )
274{
275 if( average )
276 vk = 1;
277 else
278 vk = 1 / std::sqrt( Deflection::GetGiNorm() );
279
280 Tmpdelta = delta + vk;
281
282 } // end( PrimalDual::NewDEF )
283
284/*--------------------------------------------------------------------------*/
285
287{
288 return( vk / Tmpdelta );
289 }
290
291/*--------------------------------------------------------------------------*/
292
293inline void PrimalDual::UpdateGamma( void )
294{
295 HpNum tStar;
296 Deflection::Solver->GetPar( NDOSolver::ktStar , tStar );
297
298 if( average )
299 gamma = LpsFct * ( std::sqrt( LipCnst / 2.0 ) / tStar );
300 else
301 gamma = LpsFct / ( std::sqrt( 2.0 * LipCnst ) * tStar );
302
303 } // end( PrimalDual::UpdateGamma )
304
305/*--------------------------------------------------------------------------*/
306
307}; // end( namespace NDO_di_unipi_it )
308
309/*--------------------------------------------------------------------------*/
310/*--------------------------------------------------------------------------*/
311
312#endif /* PrimalDual.h included */
313
314/*--------------------------------------------------------------------------*/
315/*-------------------- End File PrimalDual.h -------------------------------*/
316/*--------------------------------------------------------------------------*/
Definition Deflection.h:63
char VOLLLvl
the "level of verbosity"
Definition Deflection.h:237
std::ostream * VOLLog
the output stream object
Definition Deflection.h:235
virtual void SetVOLLog(std::ostream *outs=0, const char lvl=0)
Definition Deflection.h:106
SubGrad * Solver
(pointer to) the SubGrad solver
Definition Deflection.h:233
virtual void Format(void)
Definition Deflection.h:117
FiOracle * GetOracle(void)
virtual HpNum GetGlobalLipschitz(cIndex wFi=Inf< Index >())
Definition FiOracle.h:778
Definition FiOracle.h:66
Definition PrimalDual.h:90
HpNum GetLev(void)
Definition PrimalDual.h:147
HpNum GetBeta(void)
Definition PrimalDual.h:154
HpNum GetDFLCoeff(void)
Definition PrimalDual.h:286
void NewDEF(void)
Definition PrimalDual.h:273
void SetMaxBeta(const HpNum alpha)
Definition PrimalDual.h:161
void Format(void)
Definition PrimalDual.h:221
PrimalDual(SubGrad *slvr, istream *iStrm=0)
Definition PrimalDual.h:115
void NewStep(void)
Definition PrimalDual.h:236
Definition Stepsize.h:63
HpNum LpsFct
scaling factor
Definition Stepsize.h:349
Definition SubGrad.h:148
void GetPar(const int wp, int &value)
Definition SubGrad.h:825
double HpNum
"finer" floating point numbers
Definition OPTtypes.h:98
void DfltdSfInpt(istream *iStrm, T &Param, const T Dflt, const char cmntc='#')
Definition OPTUtils.h:392
Definition Bundle.h:68