alglibinternal.h   alglibinternal.h 
skipping to change at line 32 skipping to change at line 32
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// THIS SECTION CONTAINS COMPUTATIONAL CORE DECLARATIONS (DATATYPES) // THIS SECTION CONTAINS COMPUTATIONAL CORE DECLARATIONS (DATATYPES)
// //
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
namespace alglib_impl namespace alglib_impl
{ {
typedef struct typedef struct
{ {
ae_vector ia0;
ae_vector ia1; ae_vector ia1;
ae_vector ia2; ae_vector ia2;
ae_vector ia3;
ae_vector ra0;
ae_vector ra1; ae_vector ra1;
ae_vector ra2; ae_vector ra2;
ae_vector ra3;
} apbuffers; } apbuffers;
typedef struct typedef struct
{ {
ae_bool brackt; ae_bool brackt;
ae_bool stage1; ae_bool stage1;
ae_int_t infoc; ae_int_t infoc;
double dg; double dg;
double dgm; double dgm;
double dginit; double dginit;
double dgtest; double dgtest;
skipping to change at line 108 skipping to change at line 112
} }
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// THIS SECTION CONTAINS COMPUTATIONAL CORE DECLARATIONS (FUNCTIONS) // THIS SECTION CONTAINS COMPUTATIONAL CORE DECLARATIONS (FUNCTIONS)
// //
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
namespace alglib_impl namespace alglib_impl
{ {
void tagsort(/* Real */ ae_vector* a,
ae_int_t n,
/* Integer */ ae_vector* p1,
/* Integer */ ae_vector* p2,
ae_state *_state);
void tagsortfasti(/* Real */ ae_vector* a,
/* Integer */ ae_vector* b,
/* Real */ ae_vector* bufa,
/* Integer */ ae_vector* bufb,
ae_int_t n,
ae_state *_state);
void tagsortfastr(/* Real */ ae_vector* a,
/* Real */ ae_vector* b,
/* Real */ ae_vector* bufa,
/* Real */ ae_vector* bufb,
ae_int_t n,
ae_state *_state);
void tagsortfast(/* Real */ ae_vector* a,
/* Real */ ae_vector* bufa,
ae_int_t n,
ae_state *_state);
void tagheappushi(/* Real */ ae_vector* a,
/* Integer */ ae_vector* b,
ae_int_t* n,
double va,
ae_int_t vb,
ae_state *_state);
void tagheapreplacetopi(/* Real */ ae_vector* a,
/* Integer */ ae_vector* b,
ae_int_t n,
double va,
ae_int_t vb,
ae_state *_state);
void tagheappopi(/* Real */ ae_vector* a,
/* Integer */ ae_vector* b,
ae_int_t* n,
ae_state *_state);
void taskgenint1d(double a, void taskgenint1d(double a,
double b, double b,
ae_int_t n, ae_int_t n,
/* Real */ ae_vector* x, /* Real */ ae_vector* x,
/* Real */ ae_vector* y, /* Real */ ae_vector* y,
ae_state *_state); ae_state *_state);
void taskgenint1dequidist(double a, void taskgenint1dequidist(double a,
double b, double b,
ae_int_t n, ae_int_t n,
/* Real */ ae_vector* x, /* Real */ ae_vector* x,
skipping to change at line 175 skipping to change at line 142
ae_int_t n, ae_int_t n,
/* Real */ ae_vector* x, /* Real */ ae_vector* x,
/* Real */ ae_vector* y, /* Real */ ae_vector* y,
ae_state *_state); ae_state *_state);
ae_bool aredistinct(/* Real */ ae_vector* x, ae_bool aredistinct(/* Real */ ae_vector* x,
ae_int_t n, ae_int_t n,
ae_state *_state); ae_state *_state);
void bvectorsetlengthatleast(/* Boolean */ ae_vector* x, void bvectorsetlengthatleast(/* Boolean */ ae_vector* x,
ae_int_t n, ae_int_t n,
ae_state *_state); ae_state *_state);
void ivectorsetlengthatleast(/* Integer */ ae_vector* x,
ae_int_t n,
ae_state *_state);
void rvectorsetlengthatleast(/* Real */ ae_vector* x, void rvectorsetlengthatleast(/* Real */ ae_vector* x,
ae_int_t n, ae_int_t n,
ae_state *_state); ae_state *_state);
void rmatrixsetlengthatleast(/* Real */ ae_matrix* x, void rmatrixsetlengthatleast(/* Real */ ae_matrix* x,
ae_int_t m, ae_int_t m,
ae_int_t n, ae_int_t n,
ae_state *_state); ae_state *_state);
ae_bool isfinitevector(/* Real */ ae_vector* x, ae_bool isfinitevector(/* Real */ ae_vector* x,
ae_int_t n, ae_int_t n,
ae_state *_state); ae_state *_state);
skipping to change at line 221 skipping to change at line 191
double safeminposrv(double x, double y, double v, ae_state *_state); double safeminposrv(double x, double y, double v, ae_state *_state);
void apperiodicmap(double* x, void apperiodicmap(double* x,
double a, double a,
double b, double b,
double* k, double* k,
ae_state *_state); ae_state *_state);
double boundval(double x, double b1, double b2, ae_state *_state); double boundval(double x, double b1, double b2, ae_state *_state);
ae_bool _apbuffers_init(apbuffers* p, ae_state *_state, ae_bool make_automa tic); ae_bool _apbuffers_init(apbuffers* p, ae_state *_state, ae_bool make_automa tic);
ae_bool _apbuffers_init_copy(apbuffers* dst, apbuffers* src, ae_state *_sta te, ae_bool make_automatic); ae_bool _apbuffers_init_copy(apbuffers* dst, apbuffers* src, ae_state *_sta te, ae_bool make_automatic);
void _apbuffers_clear(apbuffers* p); void _apbuffers_clear(apbuffers* p);
void tagsort(/* Real */ ae_vector* a,
ae_int_t n,
/* Integer */ ae_vector* p1,
/* Integer */ ae_vector* p2,
ae_state *_state);
void tagsortbuf(/* Real */ ae_vector* a,
ae_int_t n,
/* Integer */ ae_vector* p1,
/* Integer */ ae_vector* p2,
apbuffers* buf,
ae_state *_state);
void tagsortfasti(/* Real */ ae_vector* a,
/* Integer */ ae_vector* b,
/* Real */ ae_vector* bufa,
/* Integer */ ae_vector* bufb,
ae_int_t n,
ae_state *_state);
void tagsortfastr(/* Real */ ae_vector* a,
/* Real */ ae_vector* b,
/* Real */ ae_vector* bufa,
/* Real */ ae_vector* bufb,
ae_int_t n,
ae_state *_state);
void tagsortfast(/* Real */ ae_vector* a,
/* Real */ ae_vector* bufa,
ae_int_t n,
ae_state *_state);
void tagheappushi(/* Real */ ae_vector* a,
/* Integer */ ae_vector* b,
ae_int_t* n,
double va,
ae_int_t vb,
ae_state *_state);
void tagheapreplacetopi(/* Real */ ae_vector* a,
/* Integer */ ae_vector* b,
ae_int_t n,
double va,
ae_int_t vb,
ae_state *_state);
void tagheappopi(/* Real */ ae_vector* a,
/* Integer */ ae_vector* b,
ae_int_t* n,
ae_state *_state);
void rankx(/* Real */ ae_vector* x, void rankx(/* Real */ ae_vector* x,
ae_int_t n, ae_int_t n,
apbuffers* buf, apbuffers* buf,
ae_state *_state); ae_state *_state);
ae_bool cmatrixrank1f(ae_int_t m, ae_bool cmatrixrank1f(ae_int_t m,
ae_int_t n, ae_int_t n,
/* Complex */ ae_matrix* a, /* Complex */ ae_matrix* a,
ae_int_t ia, ae_int_t ia,
ae_int_t ja, ae_int_t ja,
/* Complex */ ae_vector* u, /* Complex */ ae_vector* u,
 End of changes. 6 change blocks. 
37 lines changed or deleted 50 lines changed or added


 dataanalysis.h   dataanalysis.h 
skipping to change at line 897 skipping to change at line 897
void lrbuildz(const real_2d_array &xy, const ae_int_t npoints, const ae_int _t nvars, ae_int_t &info, linearmodel &lm, lrreport &ar); void lrbuildz(const real_2d_array &xy, const ae_int_t npoints, const ae_int _t nvars, ae_int_t &info, linearmodel &lm, lrreport &ar);
/************************************************************************* /*************************************************************************
Unpacks coefficients of linear model. Unpacks coefficients of linear model.
INPUT PARAMETERS: INPUT PARAMETERS:
LM - linear model in ALGLIB format LM - linear model in ALGLIB format
OUTPUT PARAMETERS: OUTPUT PARAMETERS:
V - coefficients, array[0..NVars] V - coefficients, array[0..NVars]
constant term (intercept) is stored in the V[NVars].
NVars - number of independent variables (one less than number NVars - number of independent variables (one less than number
of coefficients) of coefficients)
-- ALGLIB -- -- ALGLIB --
Copyright 30.08.2008 by Bochkanov Sergey Copyright 30.08.2008 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void lrunpack(const linearmodel &lm, real_1d_array &v, ae_int_t &nvars); void lrunpack(const linearmodel &lm, real_1d_array &v, ae_int_t &nvars);
/************************************************************************* /*************************************************************************
"Packs" coefficients and creates linear model in ALGLIB format (LRUnpack "Packs" coefficients and creates linear model in ALGLIB format (LRUnpack
 End of changes. 1 change blocks. 
0 lines changed or deleted 1 lines changed or added


 interpolation.h   interpolation.h 
skipping to change at line 99 skipping to change at line 99
{ {
double taskrcond; double taskrcond;
double rmserror; double rmserror;
double avgerror; double avgerror;
double avgrelerror; double avgrelerror;
double maxerror; double maxerror;
} spline1dfitreport; } spline1dfitreport;
typedef struct typedef struct
{ {
double taskrcond; double taskrcond;
ae_int_t iterationscount;
double rmserror; double rmserror;
double avgerror; double avgerror;
double avgrelerror; double avgrelerror;
double maxerror; double maxerror;
double wrmserror;
} lsfitreport; } lsfitreport;
typedef struct typedef struct
{ {
ae_int_t n; ae_int_t optalgo;
ae_int_t m; ae_int_t m;
ae_int_t k; ae_int_t k;
double epsf; double epsf;
double epsx; double epsx;
ae_int_t maxits; ae_int_t maxits;
double stpmax; double stpmax;
ae_bool xrep; ae_bool xrep;
ae_vector s;
ae_vector bndl;
ae_vector bndu;
ae_matrix taskx; ae_matrix taskx;
ae_vector tasky; ae_vector tasky;
ae_int_t npoints;
ae_vector w; ae_vector w;
ae_int_t nweights;
ae_int_t wkind;
ae_int_t wits;
ae_bool xupdated; ae_bool xupdated;
ae_bool needf; ae_bool needf;
ae_bool needfg; ae_bool needfg;
ae_bool needfgh; ae_bool needfgh;
ae_int_t pointindex; ae_int_t pointindex;
ae_vector x; ae_vector x;
ae_vector c; ae_vector c;
double f; double f;
ae_vector g; ae_vector g;
ae_matrix h; ae_matrix h;
ae_int_t repiterationscount;
ae_int_t repterminationtype; ae_int_t repterminationtype;
double reprmserror; double reprmserror;
double repavgerror; double repavgerror;
double repavgrelerror; double repavgrelerror;
double repmaxerror; double repmaxerror;
double repwrmserror;
minlmstate optstate; minlmstate optstate;
minlmreport optrep; minlmreport optrep;
ae_int_t prevnpt;
ae_int_t prevalgo;
rcommstate rstate; rcommstate rstate;
} lsfitstate; } lsfitstate;
typedef struct typedef struct
{ {
ae_int_t n; ae_int_t n;
ae_bool periodic; ae_bool periodic;
ae_vector p; ae_vector p;
spline1dinterpolant x; spline1dinterpolant x;
spline1dinterpolant y; spline1dinterpolant y;
} pspline2interpolant; } pspline2interpolant;
skipping to change at line 356 skipping to change at line 369
double &rmserror; double &rmserror;
double &avgerror; double &avgerror;
double &avgrelerror; double &avgrelerror;
double &maxerror; double &maxerror;
}; };
/************************************************************************* /*************************************************************************
Least squares fitting report: Least squares fitting report:
TaskRCond reciprocal of task's condition number TaskRCond reciprocal of task's condition number
IterationsCount number of internal iterations
RMSError RMS error RMSError RMS error
AvgError average error AvgError average error
AvgRelError average relative error (for non-zero Y[I]) AvgRelError average relative error (for non-zero Y[I])
MaxError maximum error MaxError maximum error
WRMSError weighted RMS error
*************************************************************************/ *************************************************************************/
class _lsfitreport_owner class _lsfitreport_owner
{ {
public: public:
_lsfitreport_owner(); _lsfitreport_owner();
_lsfitreport_owner(const _lsfitreport_owner &rhs); _lsfitreport_owner(const _lsfitreport_owner &rhs);
_lsfitreport_owner& operator=(const _lsfitreport_owner &rhs); _lsfitreport_owner& operator=(const _lsfitreport_owner &rhs);
virtual ~_lsfitreport_owner(); virtual ~_lsfitreport_owner();
alglib_impl::lsfitreport* c_ptr(); alglib_impl::lsfitreport* c_ptr();
alglib_impl::lsfitreport* c_ptr() const; alglib_impl::lsfitreport* c_ptr() const;
skipping to change at line 381 skipping to change at line 398
alglib_impl::lsfitreport *p_struct; alglib_impl::lsfitreport *p_struct;
}; };
class lsfitreport : public _lsfitreport_owner class lsfitreport : public _lsfitreport_owner
{ {
public: public:
lsfitreport(); lsfitreport();
lsfitreport(const lsfitreport &rhs); lsfitreport(const lsfitreport &rhs);
lsfitreport& operator=(const lsfitreport &rhs); lsfitreport& operator=(const lsfitreport &rhs);
virtual ~lsfitreport(); virtual ~lsfitreport();
double &taskrcond; double &taskrcond;
ae_int_t &iterationscount;
double &rmserror; double &rmserror;
double &avgerror; double &avgerror;
double &avgrelerror; double &avgrelerror;
double &maxerror; double &maxerror;
double &wrmserror;
}; };
/************************************************************************* /*************************************************************************
Nonlinear fitter. Nonlinear fitter.
You should use ALGLIB functions to work with fitter. You should use ALGLIB functions to work with fitter.
Never try to access its fields directly! Never try to access its fields directly!
*************************************************************************/ *************************************************************************/
class _lsfitstate_owner class _lsfitstate_owner
skipping to change at line 2749 skipping to change at line 2768
void lsfitcreatefgh(const real_2d_array &x, const real_1d_array &y, const r eal_1d_array &c, const ae_int_t n, const ae_int_t m, const ae_int_t k, lsfi tstate &state); void lsfitcreatefgh(const real_2d_array &x, const real_1d_array &y, const r eal_1d_array &c, const ae_int_t n, const ae_int_t m, const ae_int_t k, lsfi tstate &state);
void lsfitcreatefgh(const real_2d_array &x, const real_1d_array &y, const r eal_1d_array &c, lsfitstate &state); void lsfitcreatefgh(const real_2d_array &x, const real_1d_array &y, const r eal_1d_array &c, lsfitstate &state);
/************************************************************************* /*************************************************************************
Stopping conditions for nonlinear least squares fitting. Stopping conditions for nonlinear least squares fitting.
INPUT PARAMETERS: INPUT PARAMETERS:
State - structure which stores algorithm state State - structure which stores algorithm state
EpsF - stopping criterion. Algorithm stops if EpsF - stopping criterion. Algorithm stops if
|F(k+1)-F(k)| <= EpsF*max{|F(k)|, |F(k+1)|, 1} |F(k+1)-F(k)| <= EpsF*max{|F(k)|, |F(k+1)|, 1}
EpsX - stopping criterion. Algorithm stops if EpsX - >=0
|X(k+1)-X(k)| <= EpsX*(1+|X(k)|) The subroutine finishes its work if on k+1-th iteration
MaxIts - stopping criterion. Algorithm stops after MaxIts iterations the condition |v|<=EpsX is fulfilled, where:
. * |.| means Euclidian norm
MaxIts=0 means no stopping criterion. * v - scaled step vector, v[i]=dx[i]/s[i]
* dx - ste pvector, dx=X(k+1)-X(k)
* s - scaling coefficients set by LSFitSetScale()
MaxIts - maximum number of iterations. If MaxIts=0, the number of
iterations is unlimited. Only Levenberg-Marquardt
iterations are counted (L-BFGS/CG iterations are NOT
counted because their cost is very low compared to that of
LM).
NOTE NOTE
Passing EpsF=0, EpsX=0 and MaxIts=0 (simultaneously) will lead to automatic Passing EpsF=0, EpsX=0 and MaxIts=0 (simultaneously) will lead to automatic
stopping criterion selection (according to the scheme used by MINLM unit). stopping criterion selection (according to the scheme used by MINLM unit).
-- ALGLIB -- -- ALGLIB --
Copyright 17.08.2009 by Bochkanov Sergey Copyright 17.08.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void lsfitsetcond(const lsfitstate &state, const double epsf, const double epsx, const ae_int_t maxits); void lsfitsetcond(const lsfitstate &state, const double epsf, const double epsx, const ae_int_t maxits);
skipping to change at line 2803 skipping to change at line 2830
When reports are needed, State.C (current parameters) and State.F (current When reports are needed, State.C (current parameters) and State.F (current
value of fitting function) are reported. value of fitting function) are reported.
-- ALGLIB -- -- ALGLIB --
Copyright 15.08.2010 by Bochkanov Sergey Copyright 15.08.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void lsfitsetxrep(const lsfitstate &state, const bool needxrep); void lsfitsetxrep(const lsfitstate &state, const bool needxrep);
/************************************************************************* /*************************************************************************
This function sets scaling coefficients for underlying optimizer.
ALGLIB optimizers use scaling matrices to test stopping conditions (step
size and gradient are scaled before comparison with tolerances). Scale of
the I-th variable is a translation invariant measure of:
a) "how large" the variable is
b) how large the step should be to make significant changes in the function
Generally, scale is NOT considered to be a form of preconditioner. But LM
optimizer is unique in that it uses scaling matrix both in the stopping
condition tests and as Marquardt damping factor.
Proper scaling is very important for the algorithm performance. It is less
important for the quality of results, but still has some influence (it is
easier to converge when variables are properly scaled, so premature
stopping is possible when very badly scalled variables are combined with
relaxed stopping conditions).
INPUT PARAMETERS:
State - structure stores algorithm state
S - array[N], non-zero scaling coefficients
S[i] may be negative, sign doesn't matter.
-- ALGLIB --
Copyright 14.01.2011 by Bochkanov Sergey
*************************************************************************/
void lsfitsetscale(const lsfitstate &state, const real_1d_array &s);
/*************************************************************************
This function sets boundary constraints for underlying optimizer
Boundary constraints are inactive by default (after initial creation).
They are preserved until explicitly turned off with another SetBC() call.
INPUT PARAMETERS:
State - structure stores algorithm state
BndL - lower bounds, array[K].
If some (all) variables are unbounded, you may specify
very small number or -INF (latter is recommended because
it will allow solver to use better algorithm).
BndU - upper bounds, array[K].
If some (all) variables are unbounded, you may specify
very large number or +INF (latter is recommended because
it will allow solver to use better algorithm).
NOTE 1: it is possible to specify BndL[i]=BndU[i]. In this case I-th
variable will be "frozen" at X[i]=BndL[i]=BndU[i].
NOTE 2: unlike other constrained optimization algorithms, this solver has
following useful properties:
* bound constraints are always satisfied exactly
* function is evaluated only INSIDE area specified by bound constraints
-- ALGLIB --
Copyright 14.01.2011 by Bochkanov Sergey
*************************************************************************/
void lsfitsetbc(const lsfitstate &state, const real_1d_array &bndl, const r
eal_1d_array &bndu);
/*************************************************************************
This function provides reverse communication interface This function provides reverse communication interface
Reverse communication interface is not documented or recommended to use. Reverse communication interface is not documented or recommended to use.
See below for functions which provide better documented API See below for functions which provide better documented API
*************************************************************************/ *************************************************************************/
bool lsfititeration(const lsfitstate &state); bool lsfititeration(const lsfitstate &state);
/************************************************************************* /*************************************************************************
This family of functions is used to launcn iterations of nonlinear fitter This family of functions is used to launcn iterations of nonlinear fitter
These functions accept following parameters: These functions accept following parameters:
skipping to change at line 2904 skipping to change at line 2990
* 7 stopping conditions are too stringent, * 7 stopping conditions are too stringent,
further improvement is impossible further improvement is impossible
C - array[0..K-1], solution C - array[0..K-1], solution
Rep - optimization report. Following fields are set: Rep - optimization report. Following fields are set:
* Rep.TerminationType completetion code: * Rep.TerminationType completetion code:
* RMSError rms error on the (X,Y). * RMSError rms error on the (X,Y).
* AvgError average error on the (X,Y). * AvgError average error on the (X,Y).
* AvgRelError average relative error on the non-zero Y * AvgRelError average relative error on the non-zero Y
* MaxError maximum error * MaxError maximum error
NON-WEIGHTED ERRORS ARE CALCULATED NON-WEIGHTED ERRORS ARE CALCULATED
* WRMSError weighted rms error on the (X,Y).
-- ALGLIB -- -- ALGLIB --
Copyright 17.08.2009 by Bochkanov Sergey Copyright 17.08.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void lsfitresults(const lsfitstate &state, ae_int_t &info, real_1d_array &c , lsfitreport &rep); void lsfitresults(const lsfitstate &state, ae_int_t &info, real_1d_array &c , lsfitreport &rep);
/************************************************************************* /*************************************************************************
This function builds non-periodic 2-dimensional parametric spline which This function builds non-periodic 2-dimensional parametric spline which
starts at (X[0],Y[0]) and ends at (X[N-1],Y[N-1]). starts at (X[0],Y[0]) and ends at (X[N-1],Y[N-1]).
skipping to change at line 3927 skipping to change at line 4014
ae_int_t k, ae_int_t k,
lsfitstate* state, lsfitstate* state,
ae_state *_state); ae_state *_state);
void lsfitsetcond(lsfitstate* state, void lsfitsetcond(lsfitstate* state,
double epsf, double epsf,
double epsx, double epsx,
ae_int_t maxits, ae_int_t maxits,
ae_state *_state); ae_state *_state);
void lsfitsetstpmax(lsfitstate* state, double stpmax, ae_state *_state); void lsfitsetstpmax(lsfitstate* state, double stpmax, ae_state *_state);
void lsfitsetxrep(lsfitstate* state, ae_bool needxrep, ae_state *_state); void lsfitsetxrep(lsfitstate* state, ae_bool needxrep, ae_state *_state);
void lsfitsetscale(lsfitstate* state,
/* Real */ ae_vector* s,
ae_state *_state);
void lsfitsetbc(lsfitstate* state,
/* Real */ ae_vector* bndl,
/* Real */ ae_vector* bndu,
ae_state *_state);
ae_bool lsfititeration(lsfitstate* state, ae_state *_state); ae_bool lsfititeration(lsfitstate* state, ae_state *_state);
void lsfitresults(lsfitstate* state, void lsfitresults(lsfitstate* state,
ae_int_t* info, ae_int_t* info,
/* Real */ ae_vector* c, /* Real */ ae_vector* c,
lsfitreport* rep, lsfitreport* rep,
ae_state *_state); ae_state *_state);
void lsfitscalexy(/* Real */ ae_vector* x, void lsfitscalexy(/* Real */ ae_vector* x,
/* Real */ ae_vector* y, /* Real */ ae_vector* y,
/* Real */ ae_vector* w, /* Real */ ae_vector* w,
ae_int_t n, ae_int_t n,
 End of changes. 17 change blocks. 
6 lines changed or deleted 100 lines changed or added


 optimization.h   optimization.h 
skipping to change at line 25 skipping to change at line 25
A copy of the GNU General Public License is available at A copy of the GNU General Public License is available at
http://www.fsf.org/licensing/licenses http://www.fsf.org/licensing/licenses
>>> END OF LICENSE >>> >>> END OF LICENSE >>>
*************************************************************************/ *************************************************************************/
#ifndef _optimization_pkg_h #ifndef _optimization_pkg_h
#define _optimization_pkg_h #define _optimization_pkg_h
#include "ap.h" #include "ap.h"
#include "alglibinternal.h" #include "alglibinternal.h"
#include "linalg.h" #include "linalg.h"
#include "alglibmisc.h" #include "alglibmisc.h"
#include "solvers.h"
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// THIS SECTION CONTAINS COMPUTATIONAL CORE DECLARATIONS (DATATYPES) // THIS SECTION CONTAINS COMPUTATIONAL CORE DECLARATIONS (DATATYPES)
// //
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
namespace alglib_impl namespace alglib_impl
{ {
typedef struct typedef struct
{ {
ae_int_t n; ae_int_t n;
ae_int_t m; ae_int_t m;
double epsg; double epsg;
double epsf; double epsf;
double epsx; double epsx;
ae_int_t maxits; ae_int_t maxits;
ae_int_t flags;
ae_bool xrep; ae_bool xrep;
double stpmax; double stpmax;
ae_vector s;
ae_int_t nfev; ae_int_t nfev;
ae_int_t mcstage; ae_int_t mcstage;
ae_int_t k; ae_int_t k;
ae_int_t q; ae_int_t q;
ae_int_t p; ae_int_t p;
ae_vector rho; ae_vector rho;
ae_matrix y; ae_matrix yk;
ae_matrix s; ae_matrix sk;
ae_vector theta; ae_vector theta;
ae_vector d; ae_vector d;
double stp; double stp;
ae_vector work; ae_vector work;
double fold; double fold;
ae_int_t prectype; ae_int_t prectype;
double gammak; double gammak;
ae_matrix denseh; ae_matrix denseh;
ae_vector diagh;
ae_vector autobuf; ae_vector autobuf;
ae_vector x; ae_vector x;
double f; double f;
ae_vector g; ae_vector g;
ae_bool needfg; ae_bool needfg;
ae_bool xupdated; ae_bool xupdated;
rcommstate rstate; rcommstate rstate;
ae_int_t repiterationscount; ae_int_t repiterationscount;
ae_int_t repnfev; ae_int_t repnfev;
ae_int_t repterminationtype; ae_int_t repterminationtype;
skipping to change at line 81 skipping to change at line 83
} minlbfgsstate; } minlbfgsstate;
typedef struct typedef struct
{ {
ae_int_t iterationscount; ae_int_t iterationscount;
ae_int_t nfev; ae_int_t nfev;
ae_int_t terminationtype; ae_int_t terminationtype;
} minlbfgsreport; } minlbfgsreport;
typedef struct typedef struct
{ {
ae_int_t n; ae_int_t n;
ae_int_t algokind;
ae_int_t akind;
ae_matrix densea;
ae_vector diaga;
ae_vector b;
ae_vector bndl;
ae_vector bndu;
ae_vector havebndl;
ae_vector havebndu;
ae_vector xorigin;
ae_vector startx;
ae_bool havex;
ae_vector xc;
ae_vector gc;
ae_vector activeconstraints;
ae_vector prevactiveconstraints;
double constterm;
ae_vector workbndl;
ae_vector workbndu;
ae_int_t repinneriterationscount;
ae_int_t repouteriterationscount;
ae_int_t repncholesky;
ae_int_t repnmv;
ae_int_t repterminationtype;
ae_vector tmp0;
ae_vector tmp1;
ae_vector itmp0;
ae_vector p2;
ae_matrix bufa;
ae_vector bufb;
ae_vector bufx;
apbuffers buf;
} minqpstate;
typedef struct
{
ae_int_t inneriterationscount;
ae_int_t outeriterationscount;
ae_int_t nmv;
ae_int_t ncholesky;
ae_int_t terminationtype;
} minqpreport;
typedef struct
{
ae_int_t n;
ae_int_t m; ae_int_t m;
double diffstep; double diffstep;
double epsg; double epsg;
double epsf; double epsf;
double epsx; double epsx;
ae_int_t maxits; ae_int_t maxits;
ae_bool xrep; ae_bool xrep;
double stpmax; double stpmax;
ae_int_t maxmodelage; ae_int_t maxmodelage;
ae_bool makeadditers; ae_bool makeadditers;
skipping to change at line 112 skipping to change at line 158
ae_bool xupdated; ae_bool xupdated;
ae_int_t algomode; ae_int_t algomode;
ae_bool hasf; ae_bool hasf;
ae_bool hasfi; ae_bool hasfi;
ae_bool hasg; ae_bool hasg;
ae_vector xbase; ae_vector xbase;
double fbase; double fbase;
ae_vector fibase; ae_vector fibase;
ae_vector gbase; ae_vector gbase;
ae_matrix quadraticmodel; ae_matrix quadraticmodel;
ae_vector bndl;
ae_vector bndu;
ae_vector havebndl;
ae_vector havebndu;
ae_vector s;
double lambdav; double lambdav;
double nu; double nu;
ae_matrix dampedmodel;
ae_int_t modelage; ae_int_t modelage;
ae_vector xdir; ae_vector xdir;
ae_vector deltax; ae_vector deltax;
ae_vector deltaf; ae_vector deltaf;
ae_bool deltaxready; ae_bool deltaxready;
ae_bool deltafready; ae_bool deltafready;
ae_int_t repiterationscount; ae_int_t repiterationscount;
ae_int_t repterminationtype; ae_int_t repterminationtype;
ae_int_t repnfunc; ae_int_t repnfunc;
ae_int_t repnjac; ae_int_t repnjac;
ae_int_t repngrad; ae_int_t repngrad;
ae_int_t repnhess; ae_int_t repnhess;
ae_int_t repncholesky; ae_int_t repncholesky;
rcommstate rstate; rcommstate rstate;
ae_vector choleskybuf; ae_vector choleskybuf;
ae_vector tmp0;
double actualdecrease; double actualdecrease;
double predicteddecrease; double predicteddecrease;
ae_vector fm2; double xm1;
double xp1;
ae_vector fm1; ae_vector fm1;
ae_vector fp2;
ae_vector fp1; ae_vector fp1;
minlbfgsstate internalstate; minlbfgsstate internalstate;
minlbfgsreport internalrep; minlbfgsreport internalrep;
minqpstate qpstate;
minqpreport qprep;
} minlmstate; } minlmstate;
typedef struct typedef struct
{ {
ae_int_t iterationscount; ae_int_t iterationscount;
ae_int_t terminationtype; ae_int_t terminationtype;
ae_int_t nfunc; ae_int_t nfunc;
ae_int_t njac; ae_int_t njac;
ae_int_t ngrad; ae_int_t ngrad;
ae_int_t nhess; ae_int_t nhess;
ae_int_t ncholesky; ae_int_t ncholesky;
skipping to change at line 215 skipping to change at line 268
ae_int_t n; ae_int_t n;
double epsg; double epsg;
double epsf; double epsf;
double epsx; double epsx;
ae_int_t maxits; ae_int_t maxits;
double stpmax; double stpmax;
double suggestedstep; double suggestedstep;
ae_bool xrep; ae_bool xrep;
ae_bool drep; ae_bool drep;
ae_int_t cgtype; ae_int_t cgtype;
ae_int_t prectype;
ae_vector diagh;
ae_vector diaghl2;
ae_matrix vcorr;
ae_int_t vcnt;
ae_vector s;
ae_int_t nfev; ae_int_t nfev;
ae_int_t mcstage; ae_int_t mcstage;
ae_int_t k; ae_int_t k;
ae_vector xk; ae_vector xk;
ae_vector dk; ae_vector dk;
ae_vector xn; ae_vector xn;
ae_vector dn; ae_vector dn;
ae_vector d; ae_vector d;
double fold; double fold;
double stp; double stp;
double curstpmax; double curstpmax;
ae_vector work;
ae_vector yk; ae_vector yk;
double laststep; double laststep;
double lastscaledstep;
ae_int_t mcinfo;
ae_bool innerresetneeded;
ae_bool terminationneeded;
ae_int_t rstimer; ae_int_t rstimer;
ae_vector x; ae_vector x;
double f; double f;
ae_vector g; ae_vector g;
ae_bool needfg; ae_bool needfg;
ae_bool xupdated; ae_bool xupdated;
ae_bool algpowerup;
ae_bool lsstart; ae_bool lsstart;
ae_bool lsend; ae_bool lsend;
rcommstate rstate; rcommstate rstate;
ae_int_t repiterationscount; ae_int_t repiterationscount;
ae_int_t repnfev; ae_int_t repnfev;
ae_int_t repterminationtype; ae_int_t repterminationtype;
ae_int_t debugrestartscount; ae_int_t debugrestartscount;
linminstate lstate; linminstate lstate;
double betahs; double betahs;
double betady; double betady;
ae_vector work0;
ae_vector work1;
} mincgstate; } mincgstate;
typedef struct typedef struct
{ {
ae_int_t iterationscount; ae_int_t iterationscount;
ae_int_t nfev; ae_int_t nfev;
ae_int_t terminationtype; ae_int_t terminationtype;
} mincgreport; } mincgreport;
typedef struct typedef struct
{ {
ae_int_t n; ae_int_t nmain;
ae_int_t nslack;
double innerepsg; double innerepsg;
double innerepsf; double innerepsf;
double innerepsx; double innerepsx;
double outerepsx; double outerepsx;
double outerepsi; double outerepsi;
ae_int_t maxits; ae_int_t maxits;
ae_bool xrep; ae_bool xrep;
double stpmax; double stpmax;
ae_int_t cgtype; ae_int_t prectype;
double mustart; ae_vector diaghoriginal;
double mudecay; ae_vector diagh;
ae_vector x; ae_vector x;
double f; double f;
ae_vector g; ae_vector g;
ae_bool needfg; ae_bool needfg;
ae_bool xupdated; ae_bool xupdated;
rcommstate rstate; rcommstate rstate;
ae_int_t repinneriterationscount; ae_int_t repinneriterationscount;
ae_int_t repouteriterationscount; ae_int_t repouteriterationscount;
ae_int_t repnfev; ae_int_t repnfev;
ae_int_t repterminationtype; ae_int_t repterminationtype;
double repdebugeqerr; double repdebugeqerr;
double repdebugfs; double repdebugfs;
double repdebugff; double repdebugff;
double repdebugdx; double repdebugdx;
ae_vector xcur; ae_vector xcur;
ae_vector xprev; ae_vector xprev;
ae_vector xstart; ae_vector xstart;
ae_int_t itsleft; ae_int_t itsleft;
ae_int_t mucounter; ae_vector xend;
ae_matrix ce; ae_vector lastg;
ae_matrix ci; ae_matrix ceoriginal;
ae_matrix cebasis; ae_matrix ceeffective;
ae_matrix cesvl; ae_matrix cecurrent;
ae_vector xe; ae_vector ct;
ae_int_t cecnt; ae_int_t cecnt;
ae_int_t cicnt;
ae_int_t cedim; ae_int_t cedim;
ae_vector bndl; ae_vector xe;
ae_vector hasbndl; ae_vector hasbndl;
ae_vector bndu;
ae_vector hasbndu; ae_vector hasbndu;
ae_vector lm; ae_vector bndloriginal;
ae_int_t lmcnt; ae_vector bnduoriginal;
double mu; ae_vector bndleffective;
ae_vector bndueffective;
ae_vector activeconstraints;
ae_vector constrainedvalues;
ae_vector transforms;
ae_vector seffective;
ae_vector soriginal;
ae_vector w; ae_vector w;
ae_vector tmp0; ae_vector tmp0;
ae_vector tmp1; ae_vector tmp1;
ae_vector tmp2;
ae_vector r; ae_vector r;
ae_matrix lmmatrix;
double v0; double v0;
double v1; double v1;
double v2; double v2;
double t; double t;
double errfeas; double errfeas;
double errslack;
double gnorm; double gnorm;
double mpgnorm; double mpgnorm;
double lmdif;
double lmnorm;
double lmgrowth;
double mba; double mba;
double boundary; ae_int_t variabletofreeze;
ae_bool closetobarrier; double valuetofreeze;
double bndmax;
linminstate lstate;
mincgstate cgstate; mincgstate cgstate;
mincgreport cgrep; mincgreport cgrep;
ae_int_t optdim;
} minbleicstate; } minbleicstate;
typedef struct typedef struct
{ {
ae_int_t inneriterationscount; ae_int_t inneriterationscount;
ae_int_t outeriterationscount; ae_int_t outeriterationscount;
ae_int_t nfev; ae_int_t nfev;
ae_int_t terminationtype; ae_int_t terminationtype;
double debugeqerr; double debugeqerr;
double debugfs; double debugfs;
double debugff; double debugff;
skipping to change at line 404 skipping to change at line 471
minlbfgsreport(const minlbfgsreport &rhs); minlbfgsreport(const minlbfgsreport &rhs);
minlbfgsreport& operator=(const minlbfgsreport &rhs); minlbfgsreport& operator=(const minlbfgsreport &rhs);
virtual ~minlbfgsreport(); virtual ~minlbfgsreport();
ae_int_t &iterationscount; ae_int_t &iterationscount;
ae_int_t &nfev; ae_int_t &nfev;
ae_int_t &terminationtype; ae_int_t &terminationtype;
}; };
/************************************************************************* /*************************************************************************
This object stores nonlinear optimizer state.
You should use functions provided by MinQP subpackage to work with this
object
*************************************************************************/
class _minqpstate_owner
{
public:
_minqpstate_owner();
_minqpstate_owner(const _minqpstate_owner &rhs);
_minqpstate_owner& operator=(const _minqpstate_owner &rhs);
virtual ~_minqpstate_owner();
alglib_impl::minqpstate* c_ptr();
alglib_impl::minqpstate* c_ptr() const;
protected:
alglib_impl::minqpstate *p_struct;
};
class minqpstate : public _minqpstate_owner
{
public:
minqpstate();
minqpstate(const minqpstate &rhs);
minqpstate& operator=(const minqpstate &rhs);
virtual ~minqpstate();
};
/*************************************************************************
This structure stores optimization report:
* InnerIterationsCount number of inner iterations
* OuterIterationsCount number of outer iterations
* NCholesky number of Cholesky decomposition
* NMV number of matrix-vector products
(only products calculated as part of iterative
process are counted)
* TerminationType completion code (see below)
Completion codes:
* -5 inappropriate solver was used:
* Cholesky solver for semidefinite or indefinite problems
* Cholesky solver for problems with non-boundary constraints
* -3 inconsistent constraints (or, maybe, feasible point is
too hard to find). If you are sure that constraints are feasible,
try to restart optimizer with better initial approximation.
* 4 successful completion
* 5 MaxIts steps was taken
* 7 stopping conditions are too stringent,
further improvement is impossible,
X contains best point found so far.
*************************************************************************/
class _minqpreport_owner
{
public:
_minqpreport_owner();
_minqpreport_owner(const _minqpreport_owner &rhs);
_minqpreport_owner& operator=(const _minqpreport_owner &rhs);
virtual ~_minqpreport_owner();
alglib_impl::minqpreport* c_ptr();
alglib_impl::minqpreport* c_ptr() const;
protected:
alglib_impl::minqpreport *p_struct;
};
class minqpreport : public _minqpreport_owner
{
public:
minqpreport();
minqpreport(const minqpreport &rhs);
minqpreport& operator=(const minqpreport &rhs);
virtual ~minqpreport();
ae_int_t &inneriterationscount;
ae_int_t &outeriterationscount;
ae_int_t &nmv;
ae_int_t &ncholesky;
ae_int_t &terminationtype;
};
/*************************************************************************
Levenberg-Marquardt optimizer. Levenberg-Marquardt optimizer.
This structure should be created using one of the MinLMCreate???() This structure should be created using one of the MinLMCreate???()
functions. You should not access its fields directly; use ALGLIB functions functions. You should not access its fields directly; use ALGLIB functions
to work with it. to work with it.
*************************************************************************/ *************************************************************************/
class _minlmstate_owner class _minlmstate_owner
{ {
public: public:
_minlmstate_owner(); _minlmstate_owner();
skipping to change at line 651 skipping to change at line 795
real_1d_array g; real_1d_array g;
real_1d_array x; real_1d_array x;
}; };
/************************************************************************* /*************************************************************************
This structure stores optimization report: This structure stores optimization report:
* InnerIterationsCount number of inner iterations * InnerIterationsCount number of inner iterations
* OuterIterationsCount number of outer iterations * OuterIterationsCount number of outer iterations
* NFEV number of gradient evaluations * NFEV number of gradient evaluations
* TerminationType termination type (see below)
TERMINATION CODES
TerminationType field contains completion code, which can be:
-10 unsupported combination of algorithm settings:
1) StpMax is set to non-zero value,
AND 2) non-default preconditioner is used.
You can't use both features at the same moment,
so you have to choose one of them (and to turn
off another one).
-3 inconsistent constraints. Feasible point is
either nonexistent or too hard to find. Try to
restart optimizer with better initial
approximation
4 conditions on constraints are fulfilled
with error less than or equal to EpsC
5 MaxIts steps was taken
7 stopping conditions are too stringent,
further improvement is impossible,
X contains best point found so far.
ADDITIONAL FIELDS
There are additional fields which can be used for debugging: There are additional fields which can be used for debugging:
* DebugEqErr error in the equality constraints (2-norm) * DebugEqErr error in the equality constraints (2-norm)
* DebugFS f, calculated at projection of initial point * DebugFS f, calculated at projection of initial point
to the feasible set to the feasible set
* DebugFF f, calculated at the final point * DebugFF f, calculated at the final point
* DebugDX |X_start-X_final| * DebugDX |X_start-X_final|
*************************************************************************/ *************************************************************************/
class _minbleicreport_owner class _minbleicreport_owner
{ {
skipping to change at line 803 skipping to change at line 970
large steps which leads to overflow. This function allows us to reject large steps which leads to overflow. This function allows us to reject
steps that are too large (and therefore expose us to the possible steps that are too large (and therefore expose us to the possible
overflow) without actually calculating function value at the x+stp*d. overflow) without actually calculating function value at the x+stp*d.
-- ALGLIB -- -- ALGLIB --
Copyright 02.04.2010 by Bochkanov Sergey Copyright 02.04.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void minlbfgssetstpmax(const minlbfgsstate &state, const double stpmax); void minlbfgssetstpmax(const minlbfgsstate &state, const double stpmax);
/************************************************************************* /*************************************************************************
Modification of the preconditioner: This function sets scaling coefficients for LBFGS optimizer.
default preconditioner (simple scaling) is used.
ALGLIB optimizers use scaling matrices to test stopping conditions (step
size and gradient are scaled before comparison with tolerances). Scale of
the I-th variable is a translation invariant measure of:
a) "how large" the variable is
b) how large the step should be to make significant changes in the function
In most optimizers (and in the LBFGS too) scaling is NOT a form of
preconditioning. It just affects stopping conditions. You should set
preconditioner by separate call to one of the MinLBFGSSetPrec...()
functions.
There is special preconditioning mode, however, which uses scaling
coefficients to form diagonal preconditioning matrix. You can turn this
mode on, if you want. But you should understand that scaling is not the
same thing as preconditioning - these are two different, although related
forms of tuning solver.
INPUT PARAMETERS: INPUT PARAMETERS:
State - structure which stores algorithm state State - structure stores algorithm state
S - array[N], non-zero scaling coefficients
S[i] may be negative, sign doesn't matter.
-- ALGLIB --
Copyright 14.01.2011 by Bochkanov Sergey
*************************************************************************/
void minlbfgssetscale(const minlbfgsstate &state, const real_1d_array &s);
/*************************************************************************
Modification of the preconditioner: default preconditioner (simple
scaling, same for all elements of X) is used.
After call to this function preconditioner is changed to the default one. INPUT PARAMETERS:
State - structure which stores algorithm state
NOTE: you can change preconditioner "on the fly", during algorithm NOTE: you can change preconditioner "on the fly", during algorithm
iterations. iterations.
-- ALGLIB -- -- ALGLIB --
Copyright 13.10.2010 by Bochkanov Sergey Copyright 13.10.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void minlbfgssetdefaultpreconditioner(const minlbfgsstate &state); void minlbfgssetprecdefault(const minlbfgsstate &state);
/************************************************************************* /*************************************************************************
Modification of the preconditioner: Modification of the preconditioner: Cholesky factorization of approximate
Cholesky factorization of approximate Hessian is used. Hessian is used.
INPUT PARAMETERS: INPUT PARAMETERS:
State - structure which stores algorithm state State - structure which stores algorithm state
P - triangular preconditioner, Cholesky factorization of P - triangular preconditioner, Cholesky factorization of
the approximate Hessian. array[0..N-1,0..N-1], the approximate Hessian. array[0..N-1,0..N-1],
(if larger, only leading N elements are used). (if larger, only leading N elements are used).
IsUpper - whether upper or lower triangle of P is given IsUpper - whether upper or lower triangle of P is given
(other triangle is not referenced) (other triangle is not referenced)
After call to this function preconditioner is changed to P (P is copied After call to this function preconditioner is changed to P (P is copied
into the internal buffer). into the internal buffer).
NOTE: you can change preconditioner "on the fly", during algorithm NOTE: you can change preconditioner "on the fly", during algorithm
iterations. iterations.
NOTE 2: P should be nonsingular. Exception will be thrown otherwise. It NOTE 2: P should be nonsingular. Exception will be thrown otherwise.
also should be well conditioned, although only strict non-singularity is
tested.
-- ALGLIB -- -- ALGLIB --
Copyright 13.10.2010 by Bochkanov Sergey Copyright 13.10.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void minlbfgssetcholeskypreconditioner(const minlbfgsstate &state, const re void minlbfgssetpreccholesky(const minlbfgsstate &state, const real_2d_arra
al_2d_array &p, const bool isupper); y &p, const bool isupper);
/*************************************************************************
Modification of the preconditioner: diagonal of approximate Hessian is
used.
INPUT PARAMETERS:
State - structure which stores algorithm state
D - diagonal of the approximate Hessian, array[0..N-1],
(if larger, only leading N elements are used).
NOTE: you can change preconditioner "on the fly", during algorithm
iterations.
NOTE 2: D[i] should be positive. Exception will be thrown otherwise.
NOTE 3: you should pass diagonal of approximate Hessian - NOT ITS INVERSE.
-- ALGLIB --
Copyright 13.10.2010 by Bochkanov Sergey
*************************************************************************/
void minlbfgssetprecdiag(const minlbfgsstate &state, const real_1d_array &d
);
/*************************************************************************
Modification of the preconditioner: scale-based diagonal preconditioning.
This preconditioning mode can be useful when you don't have approximate
diagonal of Hessian, but you know that your variables are badly scaled
(for example, one variable is in [1,10], and another in [1000,100000]),
and most part of the ill-conditioning comes from different scales of vars.
In this case simple scale-based preconditioner, with H[i] = 1/(s[i]^2),
can greatly improve convergence.
IMPRTANT: you should set scale of your variables with MinLBFGSSetScale()
call (before or after MinLBFGSSetPrecScale() call). Without knowledge of
the scale of your variables scale-based preconditioner will be just unit
matrix.
INPUT PARAMETERS:
State - structure which stores algorithm state
-- ALGLIB --
Copyright 13.10.2010 by Bochkanov Sergey
*************************************************************************/
void minlbfgssetprecscale(const minlbfgsstate &state);
/************************************************************************* /*************************************************************************
This function provides reverse communication interface This function provides reverse communication interface
Reverse communication interface is not documented or recommended to use. Reverse communication interface is not documented or recommended to use.
See below for functions which provide better documented API See below for functions which provide better documented API
*************************************************************************/ *************************************************************************/
bool minlbfgsiteration(const minlbfgsstate &state); bool minlbfgsiteration(const minlbfgsstate &state);
/************************************************************************* /*************************************************************************
This family of functions is used to launcn iterations of nonlinear optimize r This family of functions is used to launcn iterations of nonlinear optimize r
skipping to change at line 932 skipping to change at line 1170
INPUT PARAMETERS: INPUT PARAMETERS:
State - structure used to store algorithm state State - structure used to store algorithm state
X - new starting point. X - new starting point.
-- ALGLIB -- -- ALGLIB --
Copyright 30.07.2010 by Bochkanov Sergey Copyright 30.07.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void minlbfgsrestartfrom(const minlbfgsstate &state, const real_1d_array &x ); void minlbfgsrestartfrom(const minlbfgsstate &state, const real_1d_array &x );
/************************************************************************* /*************************************************************************
CONSTRAINED QUADRATIC PROGRAMMING
The subroutine creates QP optimizer. After initial creation, it contains
default optimization problem with zero quadratic and linear terms and no
constraints. You should set quadratic/linear terms with calls to functions
provided by MinQP subpackage.
INPUT PARAMETERS:
N - problem size
OUTPUT PARAMETERS:
State - optimizer with zero quadratic/linear terms
and no constraints
-- ALGLIB --
Copyright 11.01.2011 by Bochkanov Sergey
*************************************************************************/
void minqpcreate(const ae_int_t n, minqpstate &state);
/*************************************************************************
This function sets linear term for QP solver.
By default, linear term is zero.
INPUT PARAMETERS:
State - structure which stores algorithm state
B - linear term, array[N].
-- ALGLIB --
Copyright 11.01.2011 by Bochkanov Sergey
*************************************************************************/
void minqpsetlinearterm(const minqpstate &state, const real_1d_array &b);
/*************************************************************************
This function sets quadratic term for QP solver.
By default quadratic term is zero.
IMPORTANT: this solver minimizes following function:
f(x) = 0.5*x'*A*x + b'*x.
Note that quadratic term has 0.5 before it. So if you want to minimize
f(x) = x^2 + x
you should rewrite your problem as follows:
f(x) = 0.5*(2*x^2) + x
and your matrix A will be equal to [[2.0]], not to [[1.0]]
INPUT PARAMETERS:
State - structure which stores algorithm state
A - matrix, array[N,N]
IsUpper - (optional) storage type:
* if True, symmetric matrix A is given by its upper
triangle, and the lower triangle isn
* if False, symmetric matrix A is given by its lower
triangle, and the upper triangle isn
* if not given, both lower and upper triangles must be
filled.
-- ALGLIB --
Copyright 11.01.2011 by Bochkanov Sergey
*************************************************************************/
void minqpsetquadraticterm(const minqpstate &state, const real_2d_array &a,
const bool isupper);
void minqpsetquadraticterm(const minqpstate &state, const real_2d_array &a)
;
/*************************************************************************
This function sets starting point for QP solver. It is useful to have
good initial approximation to the solution, because it will increase
speed of convergence and identification of active constraints.
INPUT PARAMETERS:
State - structure which stores algorithm state
X - starting point, array[N].
-- ALGLIB --
Copyright 11.01.2011 by Bochkanov Sergey
*************************************************************************/
void minqpsetstartingpoint(const minqpstate &state, const real_1d_array &x)
;
/*************************************************************************
This function sets origin for QP solver. By default, following QP program
is solved:
min(0.5*x'*A*x+b'*x)
This function allows to solve different problem:
min(0.5*(x-x_origin)'*A*(x-x_origin)+b'*(x-x_origin))
INPUT PARAMETERS:
State - structure which stores algorithm state
XOrigin - origin, array[N].
-- ALGLIB --
Copyright 11.01.2011 by Bochkanov Sergey
*************************************************************************/
void minqpsetorigin(const minqpstate &state, const real_1d_array &xorigin);
/*************************************************************************
This function tells solver to use Cholesky-based algorithm.
Cholesky-based algorithm can be used when:
* problem is convex
* there is no constraints or only boundary constraints are present
This algorithm has O(N^3) complexity for unconstrained problem and is up
to several times slower on bound constrained problems (these additional
iterations are needed to identify active constraints).
INPUT PARAMETERS:
State - structure which stores algorithm state
-- ALGLIB --
Copyright 11.01.2011 by Bochkanov Sergey
*************************************************************************/
void minqpsetalgocholesky(const minqpstate &state);
/*************************************************************************
This function sets boundary constraints for QP solver
Boundary constraints are inactive by default (after initial creation).
After being set, they are preserved until explicitly turned off with
another SetBC() call.
INPUT PARAMETERS:
State - structure stores algorithm state
BndL - lower bounds, array[N].
If some (all) variables are unbounded, you may specify
very small number or -INF (latter is recommended because
it will allow solver to use better algorithm).
BndU - upper bounds, array[N].
If some (all) variables are unbounded, you may specify
very large number or +INF (latter is recommended because
it will allow solver to use better algorithm).
NOTE: it is possible to specify BndL[i]=BndU[i]. In this case I-th
variable will be "frozen" at X[i]=BndL[i]=BndU[i].
-- ALGLIB --
Copyright 11.01.2011 by Bochkanov Sergey
*************************************************************************/
void minqpsetbc(const minqpstate &state, const real_1d_array &bndl, const r
eal_1d_array &bndu);
/*************************************************************************
This function solves quadratic programming problem.
You should call it after setting solver options with MinQPSet...() calls.
INPUT PARAMETERS:
State - algorithm state
You should use MinQPResults() function to access results after calls
to this function.
-- ALGLIB --
Copyright 11.01.2011 by Bochkanov Sergey
*************************************************************************/
void minqpoptimize(const minqpstate &state);
/*************************************************************************
QP solver results
INPUT PARAMETERS:
State - algorithm state
OUTPUT PARAMETERS:
X - array[0..N-1], solution
Rep - optimization report. You should check Rep.TerminationType,
which contains completion code, and you may check another
fields which contain another information about algorithm
functioning.
-- ALGLIB --
Copyright 11.01.2011 by Bochkanov Sergey
*************************************************************************/
void minqpresults(const minqpstate &state, real_1d_array &x, minqpreport &r
ep);
/*************************************************************************
QP results
Buffered implementation of MinQPResults() which uses pre-allocated buffer
to store X[]. If buffer size is too small, it resizes buffer. It is
intended to be used in the inner cycles of performance critical algorithms
where array reallocation penalty is too large to be ignored.
-- ALGLIB --
Copyright 11.01.2011 by Bochkanov Sergey
*************************************************************************/
void minqpresultsbuf(const minqpstate &state, real_1d_array &x, minqpreport
&rep);
/*************************************************************************
IMPROVED LEVENBERG-MARQUARDT METHOD FOR IMPROVED LEVENBERG-MARQUARDT METHOD FOR
NON-LINEAR LEAST SQUARES OPTIMIZATION NON-LINEAR LEAST SQUARES OPTIMIZATION
DESCRIPTION: DESCRIPTION:
This function is used to find minimum of function which is represented as This function is used to find minimum of function which is represented as
sum of squares: sum of squares:
F(x) = f[0]^2(x[0],...,x[n-1]) + ... + f[m-1]^2(x[0],...,x[n-1]) F(x) = f[0]^2(x[0],...,x[n-1]) + ... + f[m-1]^2(x[0],...,x[n-1])
using value of function vector f[] and Jacobian of f[]. using value of function vector f[] and Jacobian of f[].
REQUIREMENTS: REQUIREMENTS:
skipping to change at line 1112 skipping to change at line 1538
NOTES: NOTES:
1. you may tune stopping conditions with MinLMSetCond() function 1. you may tune stopping conditions with MinLMSetCond() function
2. if target function contains exp() or other fast growing functions, and 2. if target function contains exp() or other fast growing functions, and
optimization algorithm makes too large steps which leads to overflow, optimization algorithm makes too large steps which leads to overflow,
use MinLMSetStpMax() function to bound algorithm's steps. use MinLMSetStpMax() function to bound algorithm's steps.
-- ALGLIB -- -- ALGLIB --
Copyright 30.03.2009 by Bochkanov Sergey Copyright 30.03.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void minlmcreatefgh(const ae_int_t n, const real_1d_array &x, minlmstate &s void minlmcreatefgh(const ae_int_t n, const real_1d_array &x, minlmstate &s
tate); tate);
void minlmcreatefgh(const real_1d_array &x, minlmstate &state); void minlmcreatefgh(const real_1d_array &x, minlmstate &state);
/*************************************************************************
IMPROVED LEVENBERG-MARQUARDT METHOD FOR
NON-LINEAR LEAST SQUARES OPTIMIZATION
DESCRIPTION:
This function is used to find minimum of function which is represented as
sum of squares:
F(x) = f[0]^2(x[0],...,x[n-1]) + ... + f[m-1]^2(x[0],...,x[n-1])
using:
* value of function vector f[]
* value of Jacobian of f[]
* gradient of merit function F(x)
This function creates optimizer which uses acceleration strategy 2. Cheap
gradient of merit function (which is twice the product of function vector
and Jacobian) is used for accelerated iterations (see User Guide for more
info on this subject).
REQUIREMENTS:
This algorithm will request following information during its operation:
* function vector f[] at given point X
* function vector f[] and Jacobian of f[] (simultaneously) at given point
* gradient of
There are several overloaded versions of MinLMOptimize() function which
correspond to different LM-like optimization algorithms provided by this
unit. You should choose version which accepts fvec(), jac() and grad()
callbacks. First one is used to calculate f[] at given point, second one
calculates f[] and Jacobian df[i]/dx[j], last one calculates gradient of
merit function F(x).
You can try to initialize MinLMState structure with VJ function and then
use incorrect version of MinLMOptimize() (for example, version which
works with general form function and does not provide Jacobian), but it
will lead to exception being thrown after first attempt to calculate
Jacobian.
USAGE:
1. User initializes algorithm state with MinLMCreateVGJ() call
2. User tunes solver parameters with MinLMSetCond(), MinLMSetStpMax() and
other functions
3. User calls MinLMOptimize() function which takes algorithm state and
callback functions.
4. User calls MinLMResults() to get solution
5. Optionally, user may call MinLMRestartFrom() to solve another problem
with same N/M but another starting point and/or another function.
MinLMRestartFrom() allows to reuse already initialized structure.
INPUT PARAMETERS:
N - dimension, N>1
* if given, only leading N elements of X are used
* if not given, automatically determined from size of X
M - number of functions f[i]
X - initial solution, array[0..N-1]
OUTPUT PARAMETERS:
State - structure which stores algorithm state
NOTES:
1. you may tune stopping conditions with MinLMSetCond() function
2. if target function contains exp() or other fast growing functions, and
optimization algorithm makes too large steps which leads to overflow,
use MinLMSetStpMax() function to bound algorithm's steps.
-- ALGLIB --
Copyright 30.03.2009 by Bochkanov Sergey
*************************************************************************/
void minlmcreatevgj(const ae_int_t n, const ae_int_t m, const real_1d_array
&x, minlmstate &state);
void minlmcreatevgj(const ae_int_t m, const real_1d_array &x, minlmstate &s
tate);
/*************************************************************************
LEVENBERG-MARQUARDT-LIKE METHOD FOR
NON-LINEAR LEAST SQUARES OPTIMIZATION
DESCRIPTION:
This function is used to find minimum of function which is represented as
sum of squares:
F(x) = f[0]^2(x[0],...,x[n-1]) + ... + f[m-1]^2(x[0],...,x[n-1])
using value of F(), gradient of F(), function vector f[] and Jacobian of
f[].
This function is considered obsolete since ALGLIB 3.1.0 and is present for
backward compatibility only. We recommend to use MinLMCreateVGJ, which
provides similar, but more consistent interface.
-- ALGLIB --
Copyright 30.03.2009 by Bochkanov Sergey
*************************************************************************/
void minlmcreatefgj(const ae_int_t n, const ae_int_t m, const real_1d_array
&x, minlmstate &state);
void minlmcreatefgj(const ae_int_t m, const real_1d_array &x, minlmstate &s
tate);
/*************************************************************************
CLASSIC LEVENBERG-MARQUARDT METHOD FOR NON-LINEAR OPTIMIZATION
DESCRIPTION:
This function is used to find minimum of function which is represented as
sum of squares:
F(x) = f[0]^2(x[0],...,x[n-1]) + ... + f[m-1]^2(x[0],...,x[n-1])
using value of F(), function vector f[] and Jacobian of f[]. Classic
Levenberg-Marquardt method is used.
This function is considered obsolete since ALGLIB 3.1.0 and is present for
backward compatibility only. We recommend to use MinLMCreateVJ, which
provides similar, but more consistent and feature-rich interface.
-- ALGLIB --
Copyright 30.03.2009 by Bochkanov Sergey
*************************************************************************/
void minlmcreatefj(const ae_int_t n, const ae_int_t m, const real_1d_array
&x, minlmstate &state);
void minlmcreatefj(const ae_int_t m, const real_1d_array &x, minlmstate &st
ate);
/************************************************************************* /*************************************************************************
This function sets stopping conditions for Levenberg-Marquardt optimization This function sets stopping conditions for Levenberg-Marquardt optimization
algorithm. algorithm.
INPUT PARAMETERS: INPUT PARAMETERS:
State - structure which stores algorithm state State - structure which stores algorithm state
EpsG - >=0 EpsG - >=0
The subroutine finishes its work if the condition The subroutine finishes its work if the condition
||G||<EpsG is satisfied, where ||.|| means Euclidian norm, |v|<EpsG is satisfied, where:
G - gradient. * |.| means Euclidian norm
* v - scaled gradient vector, v[i]=g[i]*s[i]
* g - gradient
* s - scaling coefficients set by MinLMSetScale()
EpsF - >=0 EpsF - >=0
The subroutine finishes its work if on k+1-th iteration The subroutine finishes its work if on k+1-th iteration
the condition |F(k+1)-F(k)|<=EpsF*max{|F(k)|,|F(k+1)|,1} the condition |F(k+1)-F(k)|<=EpsF*max{|F(k)|,|F(k+1)|,1}
is satisfied. is satisfied.
EpsX - >=0 EpsX - >=0
The subroutine finishes its work if on k+1-th iteration The subroutine finishes its work if on k+1-th iteration
the condition |X(k+1)-X(k)| <= EpsX is fulfilled. the condition |v|<=EpsX is fulfilled, where:
* |.| means Euclidian norm
* v - scaled step vector, v[i]=dx[i]/s[i]
* dx - ste pvector, dx=X(k+1)-X(k)
* s - scaling coefficients set by MinLMSetScale()
MaxIts - maximum number of iterations. If MaxIts=0, the number of MaxIts - maximum number of iterations. If MaxIts=0, the number of
iterations is unlimited. Only Levenberg-Marquardt iterations is unlimited. Only Levenberg-Marquardt
iterations are counted (L-BFGS/CG iterations are NOT iterations are counted (L-BFGS/CG iterations are NOT
counted because their cost is very low compared to that of counted because their cost is very low compared to that of
LM). LM).
Passing EpsG=0, EpsF=0, EpsX=0 and MaxIts=0 (simultaneously) will lead to Passing EpsG=0, EpsF=0, EpsX=0 and MaxIts=0 (simultaneously) will lead to
automatic stopping criterion selection (small EpsX). automatic stopping criterion selection (small EpsX).
-- ALGLIB -- -- ALGLIB --
skipping to change at line 1299 skipping to change at line 1619
NOTE: non-zero StpMax leads to moderate performance degradation because NOTE: non-zero StpMax leads to moderate performance degradation because
intermediate step of preconditioned L-BFGS optimization is incompatible intermediate step of preconditioned L-BFGS optimization is incompatible
with limits on step size. with limits on step size.
-- ALGLIB -- -- ALGLIB --
Copyright 02.04.2010 by Bochkanov Sergey Copyright 02.04.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void minlmsetstpmax(const minlmstate &state, const double stpmax); void minlmsetstpmax(const minlmstate &state, const double stpmax);
/************************************************************************* /*************************************************************************
This function sets scaling coefficients for LM optimizer.
ALGLIB optimizers use scaling matrices to test stopping conditions (step
size and gradient are scaled before comparison with tolerances). Scale of
the I-th variable is a translation invariant measure of:
a) "how large" the variable is
b) how large the step should be to make significant changes in the function
Generally, scale is NOT considered to be a form of preconditioner. But LM
optimizer is unique in that it uses scaling matrix both in the stopping
condition tests and as Marquardt damping factor.
Proper scaling is very important for the algorithm performance. It is less
important for the quality of results, but still has some influence (it is
easier to converge when variables are properly scaled, so premature
stopping is possible when very badly scalled variables are combined with
relaxed stopping conditions).
INPUT PARAMETERS:
State - structure stores algorithm state
S - array[N], non-zero scaling coefficients
S[i] may be negative, sign doesn't matter.
-- ALGLIB --
Copyright 14.01.2011 by Bochkanov Sergey
*************************************************************************/
void minlmsetscale(const minlmstate &state, const real_1d_array &s);
/*************************************************************************
This function sets boundary constraints for LM optimizer
Boundary constraints are inactive by default (after initial creation).
They are preserved until explicitly turned off with another SetBC() call.
INPUT PARAMETERS:
State - structure stores algorithm state
BndL - lower bounds, array[N].
If some (all) variables are unbounded, you may specify
very small number or -INF (latter is recommended because
it will allow solver to use better algorithm).
BndU - upper bounds, array[N].
If some (all) variables are unbounded, you may specify
very large number or +INF (latter is recommended because
it will allow solver to use better algorithm).
NOTE 1: it is possible to specify BndL[i]=BndU[i]. In this case I-th
variable will be "frozen" at X[i]=BndL[i]=BndU[i].
NOTE 2: this solver has following useful properties:
* bound constraints are always satisfied exactly
* function is evaluated only INSIDE area specified by bound constraints
-- ALGLIB --
Copyright 14.01.2011 by Bochkanov Sergey
*************************************************************************/
void minlmsetbc(const minlmstate &state, const real_1d_array &bndl, const r
eal_1d_array &bndu);
/*************************************************************************
This function is used to change acceleration settings This function is used to change acceleration settings
You can choose between three acceleration strategies: You can choose between three acceleration strategies:
* AccType=0, no acceleration. * AccType=0, no acceleration.
* AccType=1, secant updates are used to update quadratic model after each * AccType=1, secant updates are used to update quadratic model after each
iteration. After fixed number of iterations (or after model breakdown) iteration. After fixed number of iterations (or after model breakdown)
we recalculate quadratic model using analytic Jacobian or finite we recalculate quadratic model using analytic Jacobian or finite
differences. Number of secant-based iterations depends on optimization differences. Number of secant-based iterations depends on optimization
settings: about 3 iterations - when we have analytic Jacobian, up to 2*N settings: about 3 iterations - when we have analytic Jacobian, up to 2*N
iterations - when we use finite differences to calculate Jacobian. iterations - when we use finite differences to calculate Jacobian.
* AccType=2, after quadratic model is built and LM step is made, we use it
as preconditioner for several (5-10) iterations of L-BFGS algorithm.
AccType=1 is recommended when Jacobian calculation cost is prohibitive AccType=1 is recommended when Jacobian calculation cost is prohibitive
high (several Mx1 function vector calculations followed by several NxN high (several Mx1 function vector calculations followed by several NxN
Cholesky factorizations are faster than calculation of one M*N Jacobian). Cholesky factorizations are faster than calculation of one M*N Jacobian).
It should also be used when we have no Jacobian, because finite difference It should also be used when we have no Jacobian, because finite difference
approximation takes too much time to compute. approximation takes too much time to compute.
AccType=2 is recommended when Jacobian is cheap - much more cheaper than
one Cholesky factorization. We can reduce number of Cholesky
factorizations at the cost of increased number of Jacobian calculations.
Sometimes it helps.
Table below list optimization protocols (XYZ protocol corresponds to Table below list optimization protocols (XYZ protocol corresponds to
MinLMCreateXYZ) and acceleration types they support (and use by default). MinLMCreateXYZ) and acceleration types they support (and use by default).
ACCELERATION TYPES SUPPORTED BY OPTIMIZATION PROTOCOLS: ACCELERATION TYPES SUPPORTED BY OPTIMIZATION PROTOCOLS:
protocol 0 1 2 comment protocol 0 1 comment
V + + V + +
VJ + + + VJ + +
FGH + + FGH +
VGJ + + + special protocol, not for widespread use
FJ + + obsolete protocol, not recommended
FGJ + + obsolete protocol, not recommended
DAFAULT VALUES: DAFAULT VALUES:
protocol 0 1 2 comment protocol 0 1 comment
V x without acceleration it is so slooooooooow V x without acceleration it is so slooooooooow
VJ x VJ x
FGH x FGH x
VGJ x we've implicitly turned (2) by passing gradient
FJ x obsolete protocol, not recommended
FGJ x obsolete protocol, not recommended
NOTE: this function should be called before optimization. Attempt to call NOTE: this function should be called before optimization. Attempt to call
it during algorithm iterations may result in unexpected behavior. it during algorithm iterations may result in unexpected behavior.
NOTE: attempt to call this function with unsupported protocol/acceleration NOTE: attempt to call this function with unsupported protocol/acceleration
combination will result in exception being thrown. combination will result in exception being thrown.
-- ALGLIB -- -- ALGLIB --
Copyright 14.10.2010 by Bochkanov Sergey Copyright 14.10.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
skipping to change at line 1477 skipping to change at line 1842
State - structure used for reverse communication previously State - structure used for reverse communication previously
allocated with MinLMCreateXXX call. allocated with MinLMCreateXXX call.
X - new starting point. X - new starting point.
-- ALGLIB -- -- ALGLIB --
Copyright 30.07.2010 by Bochkanov Sergey Copyright 30.07.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void minlmrestartfrom(const minlmstate &state, const real_1d_array &x); void minlmrestartfrom(const minlmstate &state, const real_1d_array &x);
/************************************************************************* /*************************************************************************
This is obsolete function.
Since ALGLIB 3.3 it is equivalent to MinLMCreateVJ().
-- ALGLIB --
Copyright 30.03.2009 by Bochkanov Sergey
*************************************************************************/
void minlmcreatevgj(const ae_int_t n, const ae_int_t m, const real_1d_array
&x, minlmstate &state);
void minlmcreatevgj(const ae_int_t m, const real_1d_array &x, minlmstate &s
tate);
/*************************************************************************
This is obsolete function.
Since ALGLIB 3.3 it is equivalent to MinLMCreateFJ().
-- ALGLIB --
Copyright 30.03.2009 by Bochkanov Sergey
*************************************************************************/
void minlmcreatefgj(const ae_int_t n, const ae_int_t m, const real_1d_array
&x, minlmstate &state);
void minlmcreatefgj(const ae_int_t m, const real_1d_array &x, minlmstate &s
tate);
/*************************************************************************
This function is considered obsolete since ALGLIB 3.1.0 and is present for
backward compatibility only. We recommend to use MinLMCreateVJ, which
provides similar, but more consistent and feature-rich interface.
-- ALGLIB --
Copyright 30.03.2009 by Bochkanov Sergey
*************************************************************************/
void minlmcreatefj(const ae_int_t n, const ae_int_t m, const real_1d_array
&x, minlmstate &state);
void minlmcreatefj(const ae_int_t m, const real_1d_array &x, minlmstate &st
ate);
/*************************************************************************
Obsolete function, use MinLBFGSSetPrecDefault() instead.
-- ALGLIB --
Copyright 13.10.2010 by Bochkanov Sergey
*************************************************************************/
void minlbfgssetdefaultpreconditioner(const minlbfgsstate &state);
/*************************************************************************
Obsolete function, use MinLBFGSSetCholeskyPreconditioner() instead.
-- ALGLIB --
Copyright 13.10.2010 by Bochkanov Sergey
*************************************************************************/
void minlbfgssetcholeskypreconditioner(const minlbfgsstate &state, const re
al_2d_array &p, const bool isupper);
/*************************************************************************
NONLINEAR BOUND CONSTRAINED OPTIMIZATION USING NONLINEAR BOUND CONSTRAINED OPTIMIZATION USING
MODIFIED ACTIVE SET ALGORITHM MODIFIED ACTIVE SET ALGORITHM
WILLIAM W. HAGER AND HONGCHAO ZHANG WILLIAM W. HAGER AND HONGCHAO ZHANG
DESCRIPTION: DESCRIPTION:
The subroutine minimizes function F(x) of N arguments with bound The subroutine minimizes function F(x) of N arguments with bound
constraints: BndL[i] <= x[i] <= BndU[i] constraints: BndL[i] <= x[i] <= BndU[i]
This method is globally convergent as long as grad(f) is Lipschitz This method is globally convergent as long as grad(f) is Lipschitz
continuous on a level set: L = { x : f(x)<=f(x0) }. continuous on a level set: L = { x : f(x)<=f(x0) }.
skipping to change at line 1749 skipping to change at line 2163
void mincgcreate(const ae_int_t n, const real_1d_array &x, mincgstate &stat e); void mincgcreate(const ae_int_t n, const real_1d_array &x, mincgstate &stat e);
void mincgcreate(const real_1d_array &x, mincgstate &state); void mincgcreate(const real_1d_array &x, mincgstate &state);
/************************************************************************* /*************************************************************************
This function sets stopping conditions for CG optimization algorithm. This function sets stopping conditions for CG optimization algorithm.
INPUT PARAMETERS: INPUT PARAMETERS:
State - structure which stores algorithm state State - structure which stores algorithm state
EpsG - >=0 EpsG - >=0
The subroutine finishes its work if the condition The subroutine finishes its work if the condition
||G||<EpsG is satisfied, where ||.|| means Euclidian norm, |v|<EpsG is satisfied, where:
G - gradient. * |.| means Euclidian norm
* v - scaled gradient vector, v[i]=g[i]*s[i]
* g - gradient
* s - scaling coefficients set by MinCGSetScale()
EpsF - >=0 EpsF - >=0
The subroutine finishes its work if on k+1-th iteration The subroutine finishes its work if on k+1-th iteration
the condition |F(k+1)-F(k)|<=EpsF*max{|F(k)|,|F(k+1)|,1} the condition |F(k+1)-F(k)|<=EpsF*max{|F(k)|,|F(k+1)|,1}
is satisfied. is satisfied.
EpsX - >=0 EpsX - >=0
The subroutine finishes its work if on k+1-th iteration The subroutine finishes its work if on k+1-th iteration
the condition |X(k+1)-X(k)| <= EpsX is fulfilled. the condition |v|<=EpsX is fulfilled, where:
* |.| means Euclidian norm
* v - scaled step vector, v[i]=dx[i]/s[i]
* dx - ste pvector, dx=X(k+1)-X(k)
* s - scaling coefficients set by MinCGSetScale()
MaxIts - maximum number of iterations. If MaxIts=0, the number of MaxIts - maximum number of iterations. If MaxIts=0, the number of
iterations is unlimited. iterations is unlimited.
Passing EpsG=0, EpsF=0, EpsX=0 and MaxIts=0 (simultaneously) will lead to Passing EpsG=0, EpsF=0, EpsX=0 and MaxIts=0 (simultaneously) will lead to
automatic stopping criterion selection (small EpsX). automatic stopping criterion selection (small EpsX).
-- ALGLIB -- -- ALGLIB --
Copyright 02.04.2010 by Bochkanov Sergey Copyright 02.04.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void mincgsetcond(const mincgstate &state, const double epsg, const double epsf, const double epsx, const ae_int_t maxits); void mincgsetcond(const mincgstate &state, const double epsg, const double epsf, const double epsx, const ae_int_t maxits);
/************************************************************************* /*************************************************************************
This function sets scaling coefficients for CG optimizer.
ALGLIB optimizers use scaling matrices to test stopping conditions (step
size and gradient are scaled before comparison with tolerances). Scale of
the I-th variable is a translation invariant measure of:
a) "how large" the variable is
b) how large the step should be to make significant changes in the function
In most optimizers (and in the CG too) scaling is NOT a form of
preconditioning. It just affects stopping conditions. You should set
preconditioner by separate call to one of the MinCGSetPrec...() functions.
There is special preconditioning mode, however, which uses scaling
coefficients to form diagonal preconditioning matrix. You can turn this
mode on, if you want. But you should understand that scaling is not the
same thing as preconditioning - these are two different, although related
forms of tuning solver.
INPUT PARAMETERS:
State - structure stores algorithm state
S - array[N], non-zero scaling coefficients
S[i] may be negative, sign doesn't matter.
-- ALGLIB --
Copyright 14.01.2011 by Bochkanov Sergey
*************************************************************************/
void mincgsetscale(const mincgstate &state, const real_1d_array &s);
/*************************************************************************
This function turns on/off reporting. This function turns on/off reporting.
INPUT PARAMETERS: INPUT PARAMETERS:
State - structure which stores algorithm state State - structure which stores algorithm state
NeedXRep- whether iteration reports are needed or not NeedXRep- whether iteration reports are needed or not
If NeedXRep is True, algorithm will call rep() callback function if it is If NeedXRep is True, algorithm will call rep() callback function if it is
provided to MinCGOptimize(). provided to MinCGOptimize().
-- ALGLIB -- -- ALGLIB --
skipping to change at line 1836 skipping to change at line 2286
Line search may fail on such problems without good estimate of initial Line search may fail on such problems without good estimate of initial
step length. Imagine, for example, problem with ||grad||=10^50 and desired step length. Imagine, for example, problem with ||grad||=10^50 and desired
step equal to 0.1 Line search function will use 10^50 as initial step, step equal to 0.1 Line search function will use 10^50 as initial step,
then it will decrease step length by 2 (up to 20 attempts) and will get then it will decrease step length by 2 (up to 20 attempts) and will get
10^44, which is still too large. 10^44, which is still too large.
This function allows us to tell than line search should be started from This function allows us to tell than line search should be started from
some moderate step length, like 1.0, so algorithm will be able to detect some moderate step length, like 1.0, so algorithm will be able to detect
desired step length in a several searches. desired step length in a several searches.
Default behavior (when no step is suggested) is to use preconditioner, if
it is available, to generate initial estimate of step length.
This function influences only first iteration of algorithm. It should be This function influences only first iteration of algorithm. It should be
called between MinCGCreate/MinCGRestartFrom() call and MinCGOptimize call. called between MinCGCreate/MinCGRestartFrom() call and MinCGOptimize call.
Suggested step is ignored if you have preconditioner.
INPUT PARAMETERS: INPUT PARAMETERS:
State - structure used to store algorithm state. State - structure used to store algorithm state.
Stp - initial estimate of the step length. Stp - initial estimate of the step length.
Can be zero (no estimate). Can be zero (no estimate).
-- ALGLIB -- -- ALGLIB --
Copyright 30.07.2010 by Bochkanov Sergey Copyright 30.07.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void mincgsuggeststep(const mincgstate &state, const double stp); void mincgsuggeststep(const mincgstate &state, const double stp);
/************************************************************************* /*************************************************************************
Modification of the preconditioner: preconditioning is turned off.
INPUT PARAMETERS:
State - structure which stores algorithm state
NOTE: you can change preconditioner "on the fly", during algorithm
iterations.
-- ALGLIB --
Copyright 13.10.2010 by Bochkanov Sergey
*************************************************************************/
void mincgsetprecdefault(const mincgstate &state);
/*************************************************************************
Modification of the preconditioner: diagonal of approximate Hessian is
used.
INPUT PARAMETERS:
State - structure which stores algorithm state
D - diagonal of the approximate Hessian, array[0..N-1],
(if larger, only leading N elements are used).
NOTE: you can change preconditioner "on the fly", during algorithm
iterations.
NOTE 2: D[i] should be positive. Exception will be thrown otherwise.
NOTE 3: you should pass diagonal of approximate Hessian - NOT ITS INVERSE.
-- ALGLIB --
Copyright 13.10.2010 by Bochkanov Sergey
*************************************************************************/
void mincgsetprecdiag(const mincgstate &state, const real_1d_array &d);
/*************************************************************************
Modification of the preconditioner: scale-based diagonal preconditioning.
This preconditioning mode can be useful when you don't have approximate
diagonal of Hessian, but you know that your variables are badly scaled
(for example, one variable is in [1,10], and another in [1000,100000]),
and most part of the ill-conditioning comes from different scales of vars.
In this case simple scale-based preconditioner, with H[i] = 1/(s[i]^2),
can greatly improve convergence.
IMPRTANT: you should set scale of your variables with MinCGSetScale() call
(before or after MinCGSetPrecScale() call). Without knowledge of the scale
of your variables scale-based preconditioner will be just unit matrix.
INPUT PARAMETERS:
State - structure which stores algorithm state
NOTE: you can change preconditioner "on the fly", during algorithm
iterations.
-- ALGLIB --
Copyright 13.10.2010 by Bochkanov Sergey
*************************************************************************/
void mincgsetprecscale(const mincgstate &state);
/*************************************************************************
This function provides reverse communication interface This function provides reverse communication interface
Reverse communication interface is not documented or recommended to use. Reverse communication interface is not documented or recommended to use.
See below for functions which provide better documented API See below for functions which provide better documented API
*************************************************************************/ *************************************************************************/
bool mincgiteration(const mincgstate &state); bool mincgiteration(const mincgstate &state);
/************************************************************************* /*************************************************************************
This family of functions is used to launcn iterations of nonlinear optimize r This family of functions is used to launcn iterations of nonlinear optimize r
These functions accept following parameters: These functions accept following parameters:
skipping to change at line 1895 skipping to change at line 2410
Rep - optimization report: Rep - optimization report:
* Rep.TerminationType completetion code: * Rep.TerminationType completetion code:
* 1 relative function improvement is no more than * 1 relative function improvement is no more than
EpsF. EpsF.
* 2 relative step is no more than EpsX. * 2 relative step is no more than EpsX.
* 4 gradient norm is no more than EpsG * 4 gradient norm is no more than EpsG
* 5 MaxIts steps was taken * 5 MaxIts steps was taken
* 7 stopping conditions are too stringent, * 7 stopping conditions are too stringent,
further improvement is impossible, further improvement is impossible,
we return best X found so far we return best X found so far
* 8 terminated by user
* Rep.IterationsCount contains iterations count * Rep.IterationsCount contains iterations count
* NFEV countains number of function calculations * NFEV countains number of function calculations
-- ALGLIB -- -- ALGLIB --
Copyright 20.04.2009 by Bochkanov Sergey Copyright 20.04.2009 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void mincgresults(const mincgstate &state, real_1d_array &x, mincgreport &r ep); void mincgresults(const mincgstate &state, real_1d_array &x, mincgreport &r ep);
/************************************************************************* /*************************************************************************
Conjugate gradient results Conjugate gradient results
skipping to change at line 1944 skipping to change at line 2460
WITH ADDITIONAL LINEAR EQUALITY AND INEQUALITY CONSTRAINTS WITH ADDITIONAL LINEAR EQUALITY AND INEQUALITY CONSTRAINTS
DESCRIPTION: DESCRIPTION:
The subroutine minimizes function F(x) of N arguments subject to any The subroutine minimizes function F(x) of N arguments subject to any
combination of: combination of:
* bound constraints * bound constraints
* linear inequality constraints * linear inequality constraints
* linear equality constraints * linear equality constraints
REQUIREMENTS: REQUIREMENTS:
* function value and gradient * user must provide function value and gradient
* grad(f) must be Lipschitz continuous on a level set: L = { x : f(x)<=f(x0 * starting point X0 must be feasible or
) } not too far away from the feasible set
* function must be defined even in the infeasible points (algorithm make ta * grad(f) must be Lipschitz continuous on a level set:
ke L = { x : f(x)<=f(x0) }
steps in the infeasible area before converging to the feasible point) * function must be defined everywhere on the feasible set F
* starting point X0 must be feasible or not too far away from the feasible
set
* problem must satisfy strict complementary conditions
USAGE: USAGE:
Constrained optimization if far more complex than the unconstrained one. Constrained optimization if far more complex than the unconstrained one.
Here we give very brief outline of the BLEIC optimizer. We strongly recomme nd Here we give very brief outline of the BLEIC optimizer. We strongly recomme nd
you to read examples in the ALGLIB Reference Manual and to read ALGLIB User Guide you to read examples in the ALGLIB Reference Manual and to read ALGLIB User Guide
on optimization, which is available at http://www.alglib.net/optimization/ on optimization, which is available at http://www.alglib.net/optimization/
1. User initializes algorithm state with MinBLEICCreate() call 1. User initializes algorithm state with MinBLEICCreate() call
skipping to change at line 1971 skipping to change at line 2487
MinBLEICSetBC() and MinBLEICSetLC() functions. MinBLEICSetBC() and MinBLEICSetLC() functions.
3. User sets stopping conditions for underlying unconstrained solver 3. User sets stopping conditions for underlying unconstrained solver
with MinBLEICSetInnerCond() call. with MinBLEICSetInnerCond() call.
This function controls accuracy of underlying optimization algorithm. This function controls accuracy of underlying optimization algorithm.
4. User sets stopping conditions for outer iteration by calling 4. User sets stopping conditions for outer iteration by calling
MinBLEICSetOuterCond() function. MinBLEICSetOuterCond() function.
This function controls handling of boundary and inequality constraints. This function controls handling of boundary and inequality constraints.
5. User tunes barrier parameters: 5. Additionally, user may set limit on number of internal iterations
* barrier width with MinBLEICSetBarrierWidth() call
* (optionally) dynamics of the barrier width with MinBLEICSetBarrierDeca
y() call
These functions control handling of boundary and inequality constraints.
6. Additionally, user may set limit on number of internal iterations
by MinBLEICSetMaxIts() call. by MinBLEICSetMaxIts() call.
This function allows to prevent algorithm from looping forever. This function allows to prevent algorithm from looping forever.
7. User calls MinBLEICOptimize() function which takes algorithm state and 6. User calls MinBLEICOptimize() function which takes algorithm state and
pointer (delegate, etc.) to callback function which calculates F/G. pointer (delegate, etc.) to callback function which calculates F/G.
8. User calls MinBLEICResults() to get solution 7. User calls MinBLEICResults() to get solution
9. Optionally user may call MinBLEICRestartFrom() to solve another problem 8. Optionally user may call MinBLEICRestartFrom() to solve another problem
with same N but another starting point. with same N but another starting point.
MinBLEICRestartFrom() allows to reuse already initialized structure. MinBLEICRestartFrom() allows to reuse already initialized structure.
INPUT PARAMETERS: INPUT PARAMETERS:
N - problem dimension, N>0: N - problem dimension, N>0:
* if given, only leading N elements of X are used * if given, only leading N elements of X are used
* if not given, automatically determined from size ofX * if not given, automatically determined from size ofX
X - starting point, array[N]: X - starting point, array[N]:
* it is better to set X to a feasible point * it is better to set X to a feasible point
* but X can be infeasible, in which case algorithm will try * but X can be infeasible, in which case algorithm will try
skipping to change at line 2023 skipping to change at line 2534
INPUT PARAMETERS: INPUT PARAMETERS:
State - structure stores algorithm state State - structure stores algorithm state
BndL - lower bounds, array[N]. BndL - lower bounds, array[N].
If some (all) variables are unbounded, you may specify If some (all) variables are unbounded, you may specify
very small number or -INF. very small number or -INF.
BndU - upper bounds, array[N]. BndU - upper bounds, array[N].
If some (all) variables are unbounded, you may specify If some (all) variables are unbounded, you may specify
very large number or +INF. very large number or +INF.
NOTE 1: it is possible to specify BndL[i]=BndU[i]. In this case I-th
variable will be "frozen" at X[i]=BndL[i]=BndU[i].
NOTE 2: this solver has following useful properties:
* bound constraints are always satisfied exactly
* function is evaluated only INSIDE area specified by bound constraints
-- ALGLIB -- -- ALGLIB --
Copyright 28.11.2010 by Bochkanov Sergey Copyright 28.11.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void minbleicsetbc(const minbleicstate &state, const real_1d_array &bndl, c onst real_1d_array &bndu); void minbleicsetbc(const minbleicstate &state, const real_1d_array &bndl, c onst real_1d_array &bndu);
/************************************************************************* /*************************************************************************
This function sets linear constraints for BLEIC optimizer. This function sets linear constraints for BLEIC optimizer.
Linear constraints are inactive by default (after initial creation). Linear constraints are inactive by default (after initial creation).
They are preserved after algorithm restart with MinBLEICRestartFrom(). They are preserved after algorithm restart with MinBLEICRestartFrom().
skipping to change at line 2064 skipping to change at line 2582
void minbleicsetlc(const minbleicstate &state, const real_2d_array &c, cons t integer_1d_array &ct); void minbleicsetlc(const minbleicstate &state, const real_2d_array &c, cons t integer_1d_array &ct);
/************************************************************************* /*************************************************************************
This function sets stopping conditions for the underlying nonlinear CG This function sets stopping conditions for the underlying nonlinear CG
optimizer. It controls overall accuracy of solution. These conditions optimizer. It controls overall accuracy of solution. These conditions
should be strict enough in order for algorithm to converge. should be strict enough in order for algorithm to converge.
INPUT PARAMETERS: INPUT PARAMETERS:
State - structure which stores algorithm state State - structure which stores algorithm state
EpsG - >=0 EpsG - >=0
Algorithm finishes its work if 2-norm of the Lagrangian The subroutine finishes its work if the condition
gradient is less than or equal to EpsG. |v|<EpsG is satisfied, where:
* |.| means Euclidian norm
* v - scaled gradient vector, v[i]=g[i]*s[i]
* g - gradient
* s - scaling coefficients set by MinBLEICSetScale()
EpsF - >=0 EpsF - >=0
The subroutine finishes its work if on k+1-th iteration The subroutine finishes its work if on k+1-th iteration
the condition |F(k+1)-F(k)|<=EpsF*max{|F(k)|,|F(k+1)|,1} the condition |F(k+1)-F(k)|<=EpsF*max{|F(k)|,|F(k+1)|,1}
is satisfied. is satisfied.
EpsX - >=0 EpsX - >=0
The subroutine finishes its work if on k+1-th iteration The subroutine finishes its work if on k+1-th iteration
the condition |X(k+1)-X(k)| <= EpsX is fulfilled. the condition |v|<=EpsX is fulfilled, where:
* |.| means Euclidian norm
* v - scaled step vector, v[i]=dx[i]/s[i]
* dx - ste pvector, dx=X(k+1)-X(k)
* s - scaling coefficients set by MinBLEICSetScale()
Passing EpsG=0, EpsF=0 and EpsX=0 (simultaneously) will lead to Passing EpsG=0, EpsF=0 and EpsX=0 (simultaneously) will lead to
automatic stopping criterion selection. automatic stopping criterion selection.
These conditions are used to terminate inner iterations. However, you These conditions are used to terminate inner iterations. However, you
need to tune termination conditions for outer iterations too. need to tune termination conditions for outer iterations too.
-- ALGLIB -- -- ALGLIB --
Copyright 28.11.2010 by Bochkanov Sergey Copyright 28.11.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
skipping to change at line 2116 skipping to change at line 2642
EpsI controls feasibility properties - algorithm won't stop until all EpsI controls feasibility properties - algorithm won't stop until all
inequality constraints will be satisfied with error (distance from current inequality constraints will be satisfied with error (distance from current
point to the feasible area) at most EpsI. point to the feasible area) at most EpsI.
-- ALGLIB -- -- ALGLIB --
Copyright 28.11.2010 by Bochkanov Sergey Copyright 28.11.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void minbleicsetoutercond(const minbleicstate &state, const double epsx, co nst double epsi); void minbleicsetoutercond(const minbleicstate &state, const double epsx, co nst double epsi);
/************************************************************************* /*************************************************************************
This function sets initial barrier width. This is obsolete function which was used by previous version of the BLEIC
optimizer. It does nothing in the current version of BLEIC.
-- ALGLIB --
Copyright 28.11.2010 by Bochkanov Sergey
*************************************************************************/
void minbleicsetbarrierwidth(const minbleicstate &state, const double mu);
/*************************************************************************
This is obsolete function which was used by previous version of the BLEIC
optimizer. It does nothing in the current version of BLEIC.
-- ALGLIB --
Copyright 28.11.2010 by Bochkanov Sergey
*************************************************************************/
void minbleicsetbarrierdecay(const minbleicstate &state, const double mudec
ay);
/*************************************************************************
This function sets scaling coefficients for BLEIC optimizer.
ALGLIB optimizers use scaling matrices to test stopping conditions (step
size and gradient are scaled before comparison with tolerances). Scale of
the I-th variable is a translation invariant measure of:
a) "how large" the variable is
b) how large the step should be to make significant changes in the function
In most optimizers (and in the BLEIC too) scaling is NOT a form of
preconditioning. It just affects stopping conditions. You should set
preconditioner by separate call to one of the MinBLEICSetPrec...()
functions.
There is a special preconditioning mode, however, which uses scaling
coefficients to form diagonal preconditioning matrix. You can turn this
mode on, if you want. But you should understand that scaling is not the
same thing as preconditioning - these are two different, although related
forms of tuning solver.
INPUT PARAMETERS:
State - structure stores algorithm state
S - array[N], non-zero scaling coefficients
S[i] may be negative, sign doesn't matter.
-- ALGLIB --
Copyright 14.01.2011 by Bochkanov Sergey
*************************************************************************/
void minbleicsetscale(const minbleicstate &state, const real_1d_array &s);
BLEIC optimizer uses modified barrier functions to handle inequality /*************************************************************************
constraints. These functions are almost constant in the inner parts of the Modification of the preconditioner: preconditioning is turned off.
feasible area, but grow rapidly to the infinity OUTSIDE of the feasible
area. Barrier width is a distance from feasible area to the point where
modified barrier function becomes infinite.
Barrier width must be:
* small enough (below some problem-dependent value) in order for algorithm
to converge. Necessary condition is that the target function must be
well described by linear model in the areas as small as barrier width.
* not VERY small (in order to avoid difficulties associated with rapid
changes in the modified function, ill-conditioning, round-off issues).
Choosing appropriate barrier width is very important for efficient
optimization, and it often requires error and trial. You can use two
strategies when choosing barrier width:
* set barrier width with MinBLEICSetBarrierWidth() call. In this case you
should try different barrier widths and examine results.
* set decreasing barrier width by combining MinBLEICSetBarrierWidth() and
MinBLEICSetBarrierDecay() calls. In this case algorithm will decrease
barrier width after each outer iteration until it encounters optimal
barrier width.
INPUT PARAMETERS: INPUT PARAMETERS:
State - structure which stores algorithm state State - structure which stores algorithm state
Mu - >0, initial barrier width
-- ALGLIB -- -- ALGLIB --
Copyright 28.11.2010 by Bochkanov Sergey Copyright 13.10.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void minbleicsetbarrierwidth(const minbleicstate &state, const double mu); void minbleicsetprecdefault(const minbleicstate &state);
/*************************************************************************
Modification of the preconditioner: diagonal of approximate Hessian is
used.
INPUT PARAMETERS:
State - structure which stores algorithm state
D - diagonal of the approximate Hessian, array[0..N-1],
(if larger, only leading N elements are used).
NOTE 1: D[i] should be positive. Exception will be thrown otherwise.
NOTE 2: you should pass diagonal of approximate Hessian - NOT ITS INVERSE.
-- ALGLIB --
Copyright 13.10.2010 by Bochkanov Sergey
*************************************************************************/
void minbleicsetprecdiag(const minbleicstate &state, const real_1d_array &d
);
/************************************************************************* /*************************************************************************
This function sets decay coefficient for barrier width. Modification of the preconditioner: scale-based diagonal preconditioning.
By default, no barrier decay is used (Decay=1.0). This preconditioning mode can be useful when you don't have approximate
diagonal of Hessian, but you know that your variables are badly scaled
(for example, one variable is in [1,10], and another in [1000,100000]),
and most part of the ill-conditioning comes from different scales of vars.
BLEIC optimizer uses modified barrier functions to handle inequality In this case simple scale-based preconditioner, with H[i] = 1/(s[i]^2),
constraints. These functions are almost constant in the inner parts of the can greatly improve convergence.
feasible area, but grow rapidly to the infinity OUTSIDE of the feasible
area. Barrier width is a distance from feasible area to the point where
modified barrier function becomes infinite. Decay coefficient allows us to
decrease barrier width from the initial (suboptimial) value until
optimal value will be met.
We recommend you either to set MuDecay=1.0 (no decay) or use some moderate IMPRTANT: you should set scale of your variables with MinBLEICSetScale()
value like 0.5-0.7 call (before or after MinBLEICSetPrecScale() call). Without knowledge of
the scale of your variables scale-based preconditioner will be just unit
matrix.
INPUT PARAMETERS: INPUT PARAMETERS:
State - structure which stores algorithm state State - structure which stores algorithm state
MuDecay - 0<MuDecay<=1, decay coefficient
-- ALGLIB -- -- ALGLIB --
Copyright 28.11.2010 by Bochkanov Sergey Copyright 13.10.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void minbleicsetbarrierdecay(const minbleicstate &state, const double mudec ay); void minbleicsetprecscale(const minbleicstate &state);
/************************************************************************* /*************************************************************************
This function allows to stop algorithm after specified number of inner This function allows to stop algorithm after specified number of inner
iterations. iterations.
INPUT PARAMETERS: INPUT PARAMETERS:
State - structure which stores algorithm state State - structure which stores algorithm state
MaxIts - maximum number of inner iterations. MaxIts - maximum number of inner iterations.
If MaxIts=0, the number of iterations is unlimited. If MaxIts=0, the number of iterations is unlimited.
skipping to change at line 2207 skipping to change at line 2774
provided to MinBLEICOptimize(). provided to MinBLEICOptimize().
-- ALGLIB -- -- ALGLIB --
Copyright 28.11.2010 by Bochkanov Sergey Copyright 28.11.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void minbleicsetxrep(const minbleicstate &state, const bool needxrep); void minbleicsetxrep(const minbleicstate &state, const bool needxrep);
/************************************************************************* /*************************************************************************
This function sets maximum step length This function sets maximum step length
IMPORTANT: this feature is hard to combine with preconditioning. You can't
set upper limit on step length, when you solve optimization problem with
linear (non-boundary) constraints AND preconditioner turned on.
When non-boundary constraints are present, you have to either a) use
preconditioner, or b) use upper limit on step length. YOU CAN'T USE BOTH!
In this case algorithm will terminate with appropriate error code.
INPUT PARAMETERS: INPUT PARAMETERS:
State - structure which stores algorithm state State - structure which stores algorithm state
StpMax - maximum step length, >=0. Set StpMax to 0.0, if you don't StpMax - maximum step length, >=0. Set StpMax to 0.0, if you don't
want to limit step length. want to limit step length.
Use this subroutine when you optimize target function which contains exp() Use this subroutine when you optimize target function which contains exp()
or other fast growing functions, and optimization algorithm makes too or other fast growing functions, and optimization algorithm makes too
large steps which lead to overflow. This function allows us to reject large steps which lead to overflow. This function allows us to reject
steps that are too large (and therefore expose us to the possible steps that are too large (and therefore expose us to the possible
overflow) without actually calculating function value at the x+stp*d. overflow) without actually calculating function value at the x+stp*d.
skipping to change at line 2259 skipping to change at line 2834
void *ptr = NULL); void *ptr = NULL);
/************************************************************************* /*************************************************************************
BLEIC results BLEIC results
INPUT PARAMETERS: INPUT PARAMETERS:
State - algorithm state State - algorithm state
OUTPUT PARAMETERS: OUTPUT PARAMETERS:
X - array[0..N-1], solution X - array[0..N-1], solution
Rep - optimization report: Rep - optimization report. You should check Rep.TerminationType
* Rep.TerminationType completetion code: in order to distinguish successful termination from
* -3 inconsistent constraints. Feasible point is unsuccessful one.
either nonexistent or too hard to find. Try to More information about fields of this structure can be
restart optimizer with better initial found in the comments on MinBLEICReport datatype.
approximation
* -2 rounding errors prevent further improvement.
X contains best point found.
* 4 conditions on constraints are fulfilled
with error less than or equal to EpsC
* 5 MaxIts steps was taken
* 7 stopping conditions are too stringent,
further improvement is impossible,
X contains best point found so far.
* Rep.IterationsCount contains iterations count
* NFEV countains number of function calculations
-- ALGLIB -- -- ALGLIB --
Copyright 28.11.2010 by Bochkanov Sergey Copyright 28.11.2010 by Bochkanov Sergey
*************************************************************************/ *************************************************************************/
void minbleicresults(const minbleicstate &state, real_1d_array &x, minbleic report &rep); void minbleicresults(const minbleicstate &state, real_1d_array &x, minbleic report &rep);
/************************************************************************* /*************************************************************************
BLEIC results BLEIC results
Buffered implementation of MinBLEICResults() which uses pre-allocated buffe r Buffered implementation of MinBLEICResults() which uses pre-allocated buffe r
skipping to change at line 2335 skipping to change at line 2899
double epsf, double epsf,
double epsx, double epsx,
ae_int_t maxits, ae_int_t maxits,
ae_state *_state); ae_state *_state);
void minlbfgssetxrep(minlbfgsstate* state, void minlbfgssetxrep(minlbfgsstate* state,
ae_bool needxrep, ae_bool needxrep,
ae_state *_state); ae_state *_state);
void minlbfgssetstpmax(minlbfgsstate* state, void minlbfgssetstpmax(minlbfgsstate* state,
double stpmax, double stpmax,
ae_state *_state); ae_state *_state);
void minlbfgssetscale(minlbfgsstate* state,
/* Real */ ae_vector* s,
ae_state *_state);
void minlbfgscreatex(ae_int_t n, void minlbfgscreatex(ae_int_t n,
ae_int_t m, ae_int_t m,
/* Real */ ae_vector* x, /* Real */ ae_vector* x,
ae_int_t flags, ae_int_t flags,
minlbfgsstate* state, minlbfgsstate* state,
ae_state *_state); ae_state *_state);
void minlbfgssetdefaultpreconditioner(minlbfgsstate* state, void minlbfgssetprecdefault(minlbfgsstate* state, ae_state *_state);
ae_state *_state); void minlbfgssetpreccholesky(minlbfgsstate* state,
void minlbfgssetcholeskypreconditioner(minlbfgsstate* state,
/* Real */ ae_matrix* p, /* Real */ ae_matrix* p,
ae_bool isupper, ae_bool isupper,
ae_state *_state); ae_state *_state);
void minlbfgssetprecdiag(minlbfgsstate* state,
/* Real */ ae_vector* d,
ae_state *_state);
void minlbfgssetprecscale(minlbfgsstate* state, ae_state *_state);
ae_bool minlbfgsiteration(minlbfgsstate* state, ae_state *_state); ae_bool minlbfgsiteration(minlbfgsstate* state, ae_state *_state);
void minlbfgsresults(minlbfgsstate* state, void minlbfgsresults(minlbfgsstate* state,
/* Real */ ae_vector* x, /* Real */ ae_vector* x,
minlbfgsreport* rep, minlbfgsreport* rep,
ae_state *_state); ae_state *_state);
void minlbfgsresultsbuf(minlbfgsstate* state, void minlbfgsresultsbuf(minlbfgsstate* state,
/* Real */ ae_vector* x, /* Real */ ae_vector* x,
minlbfgsreport* rep, minlbfgsreport* rep,
ae_state *_state); ae_state *_state);
void minlbfgsrestartfrom(minlbfgsstate* state, void minlbfgsrestartfrom(minlbfgsstate* state,
/* Real */ ae_vector* x, /* Real */ ae_vector* x,
ae_state *_state); ae_state *_state);
ae_bool _minlbfgsstate_init(minlbfgsstate* p, ae_state *_state, ae_bool mak e_automatic); ae_bool _minlbfgsstate_init(minlbfgsstate* p, ae_state *_state, ae_bool mak e_automatic);
ae_bool _minlbfgsstate_init_copy(minlbfgsstate* dst, minlbfgsstate* src, ae _state *_state, ae_bool make_automatic); ae_bool _minlbfgsstate_init_copy(minlbfgsstate* dst, minlbfgsstate* src, ae _state *_state, ae_bool make_automatic);
void _minlbfgsstate_clear(minlbfgsstate* p); void _minlbfgsstate_clear(minlbfgsstate* p);
ae_bool _minlbfgsreport_init(minlbfgsreport* p, ae_state *_state, ae_bool m ake_automatic); ae_bool _minlbfgsreport_init(minlbfgsreport* p, ae_state *_state, ae_bool m ake_automatic);
ae_bool _minlbfgsreport_init_copy(minlbfgsreport* dst, minlbfgsreport* src, ae_state *_state, ae_bool make_automatic); ae_bool _minlbfgsreport_init_copy(minlbfgsreport* dst, minlbfgsreport* src, ae_state *_state, ae_bool make_automatic);
void _minlbfgsreport_clear(minlbfgsreport* p); void _minlbfgsreport_clear(minlbfgsreport* p);
void minlmcreatevj(ae_int_t n, void minqpcreate(ae_int_t n, minqpstate* state, ae_state *_state);
ae_int_t m, void minqpsetlinearterm(minqpstate* state,
/* Real */ ae_vector* b,
ae_state *_state);
void minqpsetquadraticterm(minqpstate* state,
/* Real */ ae_matrix* a,
ae_bool isupper,
ae_state *_state);
void minqpsetstartingpoint(minqpstate* state,
/* Real */ ae_vector* x, /* Real */ ae_vector* x,
minlmstate* state,
ae_state *_state); ae_state *_state);
void minlmcreatev(ae_int_t n, void minqpsetorigin(minqpstate* state,
ae_int_t m, /* Real */ ae_vector* xorigin,
ae_state *_state);
void minqpsetalgocholesky(minqpstate* state, ae_state *_state);
void minqpsetbc(minqpstate* state,
/* Real */ ae_vector* bndl,
/* Real */ ae_vector* bndu,
ae_state *_state);
void minqpoptimize(minqpstate* state, ae_state *_state);
void minqpresults(minqpstate* state,
/* Real */ ae_vector* x, /* Real */ ae_vector* x,
double diffstep, minqpreport* rep,
minlmstate* state,
ae_state *_state); ae_state *_state);
void minlmcreatefgh(ae_int_t n, void minqpresultsbuf(minqpstate* state,
/* Real */ ae_vector* x, /* Real */ ae_vector* x,
minlmstate* state, minqpreport* rep,
ae_state *_state); ae_state *_state);
void minlmcreatevgj(ae_int_t n, void minqpsetlineartermfast(minqpstate* state,
/* Real */ ae_vector* b,
ae_state *_state);
void minqpsetquadratictermfast(minqpstate* state,
/* Real */ ae_matrix* a,
ae_bool isupper,
double s,
ae_state *_state);
void minqprewritediagonal(minqpstate* state,
/* Real */ ae_vector* s,
ae_state *_state);
void minqpsetstartingpointfast(minqpstate* state,
/* Real */ ae_vector* x,
ae_state *_state);
void minqpsetoriginfast(minqpstate* state,
/* Real */ ae_vector* xorigin,
ae_state *_state);
ae_bool _minqpstate_init(minqpstate* p, ae_state *_state, ae_bool make_auto
matic);
ae_bool _minqpstate_init_copy(minqpstate* dst, minqpstate* src, ae_state *_
state, ae_bool make_automatic);
void _minqpstate_clear(minqpstate* p);
ae_bool _minqpreport_init(minqpreport* p, ae_state *_state, ae_bool make_au
tomatic);
ae_bool _minqpreport_init_copy(minqpreport* dst, minqpreport* src, ae_state
*_state, ae_bool make_automatic);
void _minqpreport_clear(minqpreport* p);
void minlmcreatevj(ae_int_t n,
ae_int_t m, ae_int_t m,
/* Real */ ae_vector* x, /* Real */ ae_vector* x,
minlmstate* state, minlmstate* state,
ae_state *_state); ae_state *_state);
void minlmcreatefgj(ae_int_t n, void minlmcreatev(ae_int_t n,
ae_int_t m, ae_int_t m,
/* Real */ ae_vector* x, /* Real */ ae_vector* x,
double diffstep,
minlmstate* state, minlmstate* state,
ae_state *_state); ae_state *_state);
void minlmcreatefj(ae_int_t n, void minlmcreatefgh(ae_int_t n,
ae_int_t m,
/* Real */ ae_vector* x, /* Real */ ae_vector* x,
minlmstate* state, minlmstate* state,
ae_state *_state); ae_state *_state);
void minlmsetcond(minlmstate* state, void minlmsetcond(minlmstate* state,
double epsg, double epsg,
double epsf, double epsf,
double epsx, double epsx,
ae_int_t maxits, ae_int_t maxits,
ae_state *_state); ae_state *_state);
void minlmsetxrep(minlmstate* state, ae_bool needxrep, ae_state *_state); void minlmsetxrep(minlmstate* state, ae_bool needxrep, ae_state *_state);
void minlmsetstpmax(minlmstate* state, double stpmax, ae_state *_state); void minlmsetstpmax(minlmstate* state, double stpmax, ae_state *_state);
void minlmsetscale(minlmstate* state,
/* Real */ ae_vector* s,
ae_state *_state);
void minlmsetbc(minlmstate* state,
/* Real */ ae_vector* bndl,
/* Real */ ae_vector* bndu,
ae_state *_state);
void minlmsetacctype(minlmstate* state, void minlmsetacctype(minlmstate* state,
ae_int_t acctype, ae_int_t acctype,
ae_state *_state); ae_state *_state);
ae_bool minlmiteration(minlmstate* state, ae_state *_state); ae_bool minlmiteration(minlmstate* state, ae_state *_state);
void minlmresults(minlmstate* state, void minlmresults(minlmstate* state,
/* Real */ ae_vector* x, /* Real */ ae_vector* x,
minlmreport* rep, minlmreport* rep,
ae_state *_state); ae_state *_state);
void minlmresultsbuf(minlmstate* state, void minlmresultsbuf(minlmstate* state,
/* Real */ ae_vector* x, /* Real */ ae_vector* x,
minlmreport* rep, minlmreport* rep,
ae_state *_state); ae_state *_state);
void minlmrestartfrom(minlmstate* state, void minlmrestartfrom(minlmstate* state,
/* Real */ ae_vector* x, /* Real */ ae_vector* x,
ae_state *_state); ae_state *_state);
void minlmcreatevgj(ae_int_t n,
ae_int_t m,
/* Real */ ae_vector* x,
minlmstate* state,
ae_state *_state);
void minlmcreatefgj(ae_int_t n,
ae_int_t m,
/* Real */ ae_vector* x,
minlmstate* state,
ae_state *_state);
void minlmcreatefj(ae_int_t n,
ae_int_t m,
/* Real */ ae_vector* x,
minlmstate* state,
ae_state *_state);
ae_bool _minlmstate_init(minlmstate* p, ae_state *_state, ae_bool make_auto matic); ae_bool _minlmstate_init(minlmstate* p, ae_state *_state, ae_bool make_auto matic);
ae_bool _minlmstate_init_copy(minlmstate* dst, minlmstate* src, ae_state *_ state, ae_bool make_automatic); ae_bool _minlmstate_init_copy(minlmstate* dst, minlmstate* src, ae_state *_ state, ae_bool make_automatic);
void _minlmstate_clear(minlmstate* p); void _minlmstate_clear(minlmstate* p);
ae_bool _minlmreport_init(minlmreport* p, ae_state *_state, ae_bool make_au tomatic); ae_bool _minlmreport_init(minlmreport* p, ae_state *_state, ae_bool make_au tomatic);
ae_bool _minlmreport_init_copy(minlmreport* dst, minlmreport* src, ae_state *_state, ae_bool make_automatic); ae_bool _minlmreport_init_copy(minlmreport* dst, minlmreport* src, ae_state *_state, ae_bool make_automatic);
void _minlmreport_clear(minlmreport* p); void _minlmreport_clear(minlmreport* p);
void minlbfgssetdefaultpreconditioner(minlbfgsstate* state,
ae_state *_state);
void minlbfgssetcholeskypreconditioner(minlbfgsstate* state,
/* Real */ ae_matrix* p,
ae_bool isupper,
ae_state *_state);
void minasacreate(ae_int_t n, void minasacreate(ae_int_t n,
/* Real */ ae_vector* x, /* Real */ ae_vector* x,
/* Real */ ae_vector* bndl, /* Real */ ae_vector* bndl,
/* Real */ ae_vector* bndu, /* Real */ ae_vector* bndu,
minasastate* state, minasastate* state,
ae_state *_state); ae_state *_state);
void minasasetcond(minasastate* state, void minasasetcond(minasastate* state,
double epsg, double epsg,
double epsf, double epsf,
double epsx, double epsx,
skipping to change at line 2471 skipping to change at line 3105
void mincgcreate(ae_int_t n, void mincgcreate(ae_int_t n,
/* Real */ ae_vector* x, /* Real */ ae_vector* x,
mincgstate* state, mincgstate* state,
ae_state *_state); ae_state *_state);
void mincgsetcond(mincgstate* state, void mincgsetcond(mincgstate* state,
double epsg, double epsg,
double epsf, double epsf,
double epsx, double epsx,
ae_int_t maxits, ae_int_t maxits,
ae_state *_state); ae_state *_state);
void mincgsetscale(mincgstate* state,
/* Real */ ae_vector* s,
ae_state *_state);
void mincgsetxrep(mincgstate* state, ae_bool needxrep, ae_state *_state); void mincgsetxrep(mincgstate* state, ae_bool needxrep, ae_state *_state);
void mincgsetdrep(mincgstate* state, ae_bool needdrep, ae_state *_state); void mincgsetdrep(mincgstate* state, ae_bool needdrep, ae_state *_state);
void mincgsetcgtype(mincgstate* state, ae_int_t cgtype, ae_state *_state); void mincgsetcgtype(mincgstate* state, ae_int_t cgtype, ae_state *_state);
void mincgsetstpmax(mincgstate* state, double stpmax, ae_state *_state); void mincgsetstpmax(mincgstate* state, double stpmax, ae_state *_state);
void mincgsuggeststep(mincgstate* state, double stp, ae_state *_state); void mincgsuggeststep(mincgstate* state, double stp, ae_state *_state);
void mincgsetprecdefault(mincgstate* state, ae_state *_state);
void mincgsetprecdiag(mincgstate* state,
/* Real */ ae_vector* d,
ae_state *_state);
void mincgsetprecscale(mincgstate* state, ae_state *_state);
ae_bool mincgiteration(mincgstate* state, ae_state *_state); ae_bool mincgiteration(mincgstate* state, ae_state *_state);
void mincgresults(mincgstate* state, void mincgresults(mincgstate* state,
/* Real */ ae_vector* x, /* Real */ ae_vector* x,
mincgreport* rep, mincgreport* rep,
ae_state *_state); ae_state *_state);
void mincgresultsbuf(mincgstate* state, void mincgresultsbuf(mincgstate* state,
/* Real */ ae_vector* x, /* Real */ ae_vector* x,
mincgreport* rep, mincgreport* rep,
ae_state *_state); ae_state *_state);
void mincgrestartfrom(mincgstate* state, void mincgrestartfrom(mincgstate* state,
/* Real */ ae_vector* x, /* Real */ ae_vector* x,
ae_state *_state); ae_state *_state);
void mincgsetprecdiagfast(mincgstate* state,
/* Real */ ae_vector* d,
ae_state *_state);
void mincgsetpreclowrankfast(mincgstate* state,
/* Real */ ae_vector* d1,
/* Real */ ae_vector* c,
/* Real */ ae_matrix* v,
ae_int_t vcnt,
ae_state *_state);
void mincgsetprecvarpart(mincgstate* state,
/* Real */ ae_vector* d2,
ae_state *_state);
ae_bool _mincgstate_init(mincgstate* p, ae_state *_state, ae_bool make_auto matic); ae_bool _mincgstate_init(mincgstate* p, ae_state *_state, ae_bool make_auto matic);
ae_bool _mincgstate_init_copy(mincgstate* dst, mincgstate* src, ae_state *_ state, ae_bool make_automatic); ae_bool _mincgstate_init_copy(mincgstate* dst, mincgstate* src, ae_state *_ state, ae_bool make_automatic);
void _mincgstate_clear(mincgstate* p); void _mincgstate_clear(mincgstate* p);
ae_bool _mincgreport_init(mincgreport* p, ae_state *_state, ae_bool make_au tomatic); ae_bool _mincgreport_init(mincgreport* p, ae_state *_state, ae_bool make_au tomatic);
ae_bool _mincgreport_init_copy(mincgreport* dst, mincgreport* src, ae_state *_state, ae_bool make_automatic); ae_bool _mincgreport_init_copy(mincgreport* dst, mincgreport* src, ae_state *_state, ae_bool make_automatic);
void _mincgreport_clear(mincgreport* p); void _mincgreport_clear(mincgreport* p);
void minbleiccreate(ae_int_t n, void minbleiccreate(ae_int_t n,
/* Real */ ae_vector* x, /* Real */ ae_vector* x,
minbleicstate* state, minbleicstate* state,
ae_state *_state); ae_state *_state);
skipping to change at line 2522 skipping to change at line 3176
void minbleicsetoutercond(minbleicstate* state, void minbleicsetoutercond(minbleicstate* state,
double epsx, double epsx,
double epsi, double epsi,
ae_state *_state); ae_state *_state);
void minbleicsetbarrierwidth(minbleicstate* state, void minbleicsetbarrierwidth(minbleicstate* state,
double mu, double mu,
ae_state *_state); ae_state *_state);
void minbleicsetbarrierdecay(minbleicstate* state, void minbleicsetbarrierdecay(minbleicstate* state,
double mudecay, double mudecay,
ae_state *_state); ae_state *_state);
void minbleicsetscale(minbleicstate* state,
/* Real */ ae_vector* s,
ae_state *_state);
void minbleicsetprecdefault(minbleicstate* state, ae_state *_state);
void minbleicsetprecdiag(minbleicstate* state,
/* Real */ ae_vector* d,
ae_state *_state);
void minbleicsetprecscale(minbleicstate* state, ae_state *_state);
void minbleicsetmaxits(minbleicstate* state, void minbleicsetmaxits(minbleicstate* state,
ae_int_t maxits, ae_int_t maxits,
ae_state *_state); ae_state *_state);
void minbleicsetxrep(minbleicstate* state, void minbleicsetxrep(minbleicstate* state,
ae_bool needxrep, ae_bool needxrep,
ae_state *_state); ae_state *_state);
void minbleicsetstpmax(minbleicstate* state, void minbleicsetstpmax(minbleicstate* state,
double stpmax, double stpmax,
ae_state *_state); ae_state *_state);
ae_bool minbleiciteration(minbleicstate* state, ae_state *_state); ae_bool minbleiciteration(minbleicstate* state, ae_state *_state);
skipping to change at line 2543 skipping to change at line 3205
/* Real */ ae_vector* x, /* Real */ ae_vector* x,
minbleicreport* rep, minbleicreport* rep,
ae_state *_state); ae_state *_state);
void minbleicresultsbuf(minbleicstate* state, void minbleicresultsbuf(minbleicstate* state,
/* Real */ ae_vector* x, /* Real */ ae_vector* x,
minbleicreport* rep, minbleicreport* rep,
ae_state *_state); ae_state *_state);
void minbleicrestartfrom(minbleicstate* state, void minbleicrestartfrom(minbleicstate* state,
/* Real */ ae_vector* x, /* Real */ ae_vector* x,
ae_state *_state); ae_state *_state);
void barrierfunc(double x,
double mu,
double* f,
double* df,
double* d2f,
ae_state *_state);
ae_bool _minbleicstate_init(minbleicstate* p, ae_state *_state, ae_bool mak e_automatic); ae_bool _minbleicstate_init(minbleicstate* p, ae_state *_state, ae_bool mak e_automatic);
ae_bool _minbleicstate_init_copy(minbleicstate* dst, minbleicstate* src, ae _state *_state, ae_bool make_automatic); ae_bool _minbleicstate_init_copy(minbleicstate* dst, minbleicstate* src, ae _state *_state, ae_bool make_automatic);
void _minbleicstate_clear(minbleicstate* p); void _minbleicstate_clear(minbleicstate* p);
ae_bool _minbleicreport_init(minbleicreport* p, ae_state *_state, ae_bool m ake_automatic); ae_bool _minbleicreport_init(minbleicreport* p, ae_state *_state, ae_bool m ake_automatic);
ae_bool _minbleicreport_init_copy(minbleicreport* dst, minbleicreport* src, ae_state *_state, ae_bool make_automatic); ae_bool _minbleicreport_init_copy(minbleicreport* dst, minbleicreport* src, ae_state *_state, ae_bool make_automatic);
void _minbleicreport_clear(minbleicreport* p); void _minbleicreport_clear(minbleicreport* p);
} }
#endif #endif
 End of changes. 101 change blocks. 
289 lines changed or deleted 956 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/