|
TPCCLIB
|
Header file for library libtpcnlopt. More...
#include "tpcclibConfig.h"#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>#include "tpcextensions.h"#include "tpcrand.h"Go to the source code of this file.
Data Structures | |
| struct | NLOPT |
| struct | NLOPT_DATA |
Functions | |
| void | nloptInit (NLOPT *nlo) |
| void | nloptFree (NLOPT *nlo) |
| int | nloptAllocate (NLOPT *nlo, unsigned int parNr) |
| int | nloptDuplicate (NLOPT *nlo1, NLOPT *nlo2) |
| int | nloptAddP (NLOPT *nlo, double *p, double funval) |
| int | nloptSortP (NLOPT *nlo) |
| int | nloptMeanP (NLOPT *nlo, unsigned int nr, double *meanp, double *sdp) |
| void | nloptPrintP (NLOPT *nlo, unsigned int nr, FILE *fp) |
| void | nloptWrite (NLOPT *d, FILE *fp) |
| unsigned int | nloptLimitFixedNr (NLOPT *d) |
| unsigned int | nloptFixedNr (NLOPT *d) |
| void | nloptRemoveEmpties (NLOPT *d) |
| void | nloptdataInit (NLOPT_DATA *d) |
| int | nloptRandomPoint (double *p, double *low, double *up, unsigned int n, MERTWI *mt) |
| int | nloptGaussianPoint (double *p, double *mean, double *sd, double *low, double *up, unsigned int n, MERTWI *mt) |
| unsigned int | nloptCheckParameters (unsigned int n, double *pLower, double *pUpper, double *p, double *pAccept, double *penalty) |
| Check that model parameters are within given limits. | |
| unsigned int | nloptForceLimits (unsigned int n, double *pLower, double *pUpper, double *p) |
| Enforce the model parameters within given limits. | |
| int | nlopt1D (NLOPT *nlo, unsigned int maxIter, TPCSTATUS *) |
| int | nloptSimplex (NLOPT *nlo, unsigned int maxIter, TPCSTATUS *) |
| int | nloptSimplexARRS (NLOPT *nlo, unsigned int maxIter, TPCSTATUS *status) |
| int | nloptSimplexMS (NLOPT *nlo, unsigned int maxIter, TPCSTATUS *status) |
| int | nloptPowellBrent (NLOPT *nlo, unsigned int ktm, TPCSTATUS *) |
| Powell-Brent (Praxis) non-linear unconstrained optimization. | |
| int | nloptMPSO (NLOPT *nlo, unsigned int maxIter, unsigned int nSwarms, unsigned int nParticles, double wInertia, double wParticle, double wSwarm, double wGlobal, double pDeath, double pImmigration, const int doLocal, TPCSTATUS *) |
| int | nloptITGO1 (NLOPT *nlo, const int doLocal, unsigned int tgoNr, unsigned int sampleNr, unsigned int neighNr, TPCSTATUS *status) |
| int | nloptITGO2 (NLOPT *nlo, const int doLocal, unsigned int tgoNr, unsigned int sampleNr, unsigned int neighNr, TPCSTATUS *status) |
| int | nloptIATGO (NLOPT *nlo, const int doLocal, unsigned int maxIterNr, double neighFract, TPCSTATUS *status) |
Local one-dimensional minimization by bracketing.
| nlo | Pointer to NLOPT structure. |
| maxIter | Maximum number of function evaluations; set to zero to use the default. |
| status | Pointer to status data; enter NULL if not needed |
Definition at line 25 of file nlopt1d.c.
Referenced by nloptSimplex().
|
extern |
Add parameters and value in NLOPT plist.
Parameters are added starting at index plist[(funCalls-1)*(totalNr+1)], and function value at index plist[(funCalls-1)*(totalNr+1)+totalNr], after plist[] size is increased by (totalNr+1).
| nlo | Pointer to initiated NLOPT structure; any old contents are deleted. |
| p | Pointer to parameter array of length nlo->totalNr. |
| funval | Value of objective function. |
Definition at line 149 of file nlopt.c.
Referenced by nlopt1D(), nloptIATGO(), and nloptSimplex().
|
extern |
Allocate memory for NLOPT data. Any previous contents are deleted.
| nlo | Pointer to initiated NLOPT structure; any old contents are deleted. |
| parNr | Nr of parameters. |
Definition at line 74 of file nlopt.c.
Referenced by nloptDuplicate().
|
extern |
Check that model parameters are within given limits.
If one or more parameter(s) are outside of limits, then a penalty factor is optionally computed. Optionally, this function can make a list parameters that are inside the constraints.
| n | Nr of parameters. |
| pLower | Lower limits (array of length par_nr). |
| pUpper | Upper limits (array of length par_nr). |
| p | Parameters to test (array of length par_nr). |
| pAccept | Pointer to corrected parameters (array of length par_nr); NULL if not needed. |
| penalty | Pointer to variable in which the possible penalty factor will be written; 1.0 if no penalty was found is necessary, otherwise >1. Set to NULL if not needed. |
Definition at line 30 of file constraints.c.
|
extern |
Initiate the NLOPT_DATA structure before any use.
| d | Pointer to NLOPT_DATA. |
Make a duplicate of NLOPT data.
NLOPT plist is not copied but usePList parameter is copied.
| nlo1 | Pointer to existing NLOPT structure to be duplicated. |
| nlo2 | Pointer to the target NLOPT; must be initiated; any old contents are deleted. |
Definition at line 112 of file nlopt.c.
Referenced by nloptITGO1(), and nloptITGO2().
|
extern |
Determine the number of fixed parameters, based on constraints or delta.
| d | Pointer to NLOPT |
Definition at line 354 of file nlopt.c.
Referenced by nlopt1D(), and nloptSimplex().
|
extern |
Enforce the model parameters within given limits.
| n | Number of parameters. |
| pLower | Lower limits (array of length par_nr). |
| pUpper | Upper limits (array of length par_nr). |
| p | Parameters to enforce inside limits (array of length par_nr). |
Definition at line 76 of file constraints.c.
Referenced by nloptSimplex().
|
extern |
Free memory allocated for NLOPT data. All contents are destroyed.
| nlo | Pointer to initiated NLOPT structure. |
Definition at line 52 of file nlopt.c.
Referenced by nloptAddP(), nloptAllocate(), nloptDuplicate(), nloptITGO1(), and nloptITGO2().
|
extern |
Create random parameters with Gaussian distribution.
| p | Pointer to parameter list to be filled, allocated for length n. |
| mean | Pointer to list of mean values for each parameter. |
| sd | Pointer to list of standard deviations for each parameter. |
| low | Pointer to parameter lower limits; generated pseudo-random numbers falling below the lower limit will be set to the limit; NULL if not needed. |
| up | Pointer to parameter upper limits; generated pseudo-random numbers falling above the upper limit will be set to the limit; NULL if not needed. |
| n | List length. |
| mt | Pointer to initiated and seeded Mersenne Twister MT19937 data structure; enter NULL to use drandGaussian() instead. |
Definition at line 70 of file rndpoint.c.
Referenced by nloptIATGO(), nloptMPSO(), and nloptSimplexARRS().
|
extern |
Iterative accumulative topographical global optimization algorithm (IATGO).
| nlo | Pointer to NLOPT data. Counter funCalls is initially set to zero, and then increased here. |
| doLocal | Local optimization method: 0=no local optimization, 1=Nelder-Mead. |
| maxIterNr | Number of TGO iterations; enter 0 to use the default; enter 1 to run TGO just once, ie to use TGO instead of iTGO. |
| neighFract | Fraction of samples to define as neighbours (cluster size); enter a large fraction (>0.5) if only few distant local minima are expected. |
| status | Pointer to status data; enter NULL if not needed. |
Definition at line 681 of file tgo.c.
|
extern |
Initiate the NLOPT structure before any use.
| nlo | Pointer to NLOPT |
Definition at line 25 of file nlopt.c.
Referenced by nloptFree(), nloptITGO1(), and nloptITGO2().
|
extern |
Iterative Topographical global optimization algorithm 1 (iTGO1).
| nlo | Pointer to NLOPT data. Counter funCalls is initially set to zero, and then increased here. Parameter maxFunCalls is used as one of the stopping criteria. Parameters xtol[] is used for scaling and as one of the stopping criteria. |
| doLocal | Local optimization method: 0=no local optimization, 1=Nelder-Mead. |
| tgoNr | Number of TGO iterations; enter 0 to use the default; enter 1 to run TGO just once, ie to use TGO instead of iTGO. Iterations are needed if sampleNr (below) would otherwise require too much memory. |
| sampleNr | Number of points to sample in one iteration; may need to be large if the number of iterations (above) is small; enter 0 to let function decide it. |
| neighNr | Number of neighbours to investigate (cluster size); enter a large number relative to sampleNr (above) if only few local minima are expected; enter 0 to let function decide it. |
| status | Pointer to status data; enter NULL if not needed. |
Definition at line 59 of file tgo.c.
|
extern |
Iterative Topographical global optimization algorithm 2 (iTGO2).
| nlo | Pointer to NLOPT data. Counter funCalls is initially set to zero, and then increased here. Parameter maxFunCalls is used as one of the stopping criteria. Parameters xtol[] is used for scaling and as one of the stopping criteria. |
| doLocal | Local optimization method: 0=no local optimization, 1=Nelder-Mead. |
| tgoNr | Number of TGO iterations; enter 0 to use the default; enter 1 to run TGO just once, ie to use TGO instead of iTGO. Iterations are needed if sampleNr (below) would otherwise require too much memory. |
| sampleNr | Number of points to sample in one iteration; may need to be large if the number of iterations (above) is small; enter 0 to let function decide it. |
| neighNr | Number of neighbours to investigate (cluster size); enter a large number relative to sampleNr (above) if only few local minima are expected; enter 0 to let function decide it. |
| status | Pointer to status data; enter NULL if not needed. |
Definition at line 342 of file tgo.c.
|
extern |
Determine the number of fixed parameters, based on constraints.
| d | Pointer to NLOPT. |
Definition at line 333 of file nlopt.c.
Referenced by nloptIATGO(), nloptITGO1(), nloptITGO2(), nloptMPSO(), nloptSimplexARRS(), and nloptSimplexMS().
|
extern |
Calculate mean point from NLOPT plist.
Missing values are omitted from the mean.
Notice that if plist contains fixed parameters, their mean and SD may not be exactly correct because of limited accuracy of calculation with floating points; you may therefore need to set the mean to the limit and SD to zero afterwards.
| nlo | Pointer to NLOPT structure. |
| nr | Number of points to include; enter 0 to use all. |
| meanp | Pointer to array of size totalNr where mean point is saved. |
| sdp | Pointer to array of size totalNr where point SD is saved; enter NULL, if not needed. |
Definition at line 219 of file nlopt.c.
Referenced by nloptIATGO(), and nloptSimplexARRS().
|
extern |
Multi particle swarm optimization (MPSO).
| nlo | Pointer to NLOPT data. Counter funCalls is initially set to zero, and then increased here. Parameter maxFunCalls is used as one of the stopping criteria. Parameters xtol[] is used as one of the stopping criteria. |
| maxIter | Maximum number of iterations; set to zero to use the default; 10 is the minimum. |
| nSwarms | Number of swarms; set to zero to use the default; 2 is the minimum. |
| nParticles | Number of particles per swarm; set to zero to use the default; 5 is the minimum. |
| wInertia | Inertia; weight (0-1) for keeping particles own velocity and direction; enter NaN to use the default. |
| wParticle | Particle independence; weight how much particle is drawn towards the best point in its own memory; enter NaN to use the default. |
| wSwarm | Gravitation to the swarm; weight how much particle is drawn towards the best point in its own swarm memory; enter NaN to use the default. |
| wGlobal | Gravitation to the global optimum; weight how much particle is drawn towards the best point the memory of all the swarms. Set to zero for keeping swarms independent on each other. |
| pDeath | Probability of particle death and rebirth at random position; must be less than 0.1. |
| pImmigration | Probability of two particles switching swarms; must be less than 0.1. |
| doLocal | Use local optimization (Nelder-Mead downhill simplex) intermittently; using it (1) does not much increase the speed than not using it (0), but may increase the success rate. |
| status | Pointer to status data; enter NULL if not needed. |
Definition at line 129 of file mpso.c.
Powell-Brent (Praxis) non-linear unconstrained optimization.
Praxis is a general purpose routine for the minimization of a function in several variables. The algorithm used is a modification of conjugate gradient search method by Powell, with changes by Brent, who gave an algol-w program, which served as a basis for this function.
References:
| nlo | Pointer to NLOPT struct. Initial guess must be given in x[]. Initial step sizes must be given in xdelta[]. Note that constraints are not applied here. Parameter tolerances are used as stopping criteria. |
| ktm | Parameter tolerances (xtol[]) are given in the previous struct. Praxis stops if the criterion 2 * ||x[k]-x[k-1]|| <= sqrt(macheps) * ||x[k]|| + xtol is fulfilled more than ktm times for every parameter x. You should first try with ktm=1, and usually not higher than 4. |
| status | Pointer to status data; enter NULL if not needed. |
Definition at line 59 of file praxis.c.
|
extern |
Print the contents of NLOPT plist.
| nlo | Pointer to NLOPT structure. |
| nr | Number of points to print; enter 0 or a large number to print all. |
| fp | File pointer for the output. |
Definition at line 274 of file nlopt.c.
Referenced by nloptIATGO(), and nloptSimplexARRS().
|
extern |
Create random parameters between specified limits.
| p | Pointer to parameter list to be filled. |
| low | Pointer to parameter lower limits. |
| up | Pointer to parameter upper limits. |
| n | List length. |
| mt | Pointer to initiated and seeded Mersenne Twister MT19937 data structure; enter NULL to use drand() instead. |
Definition at line 28 of file rndpoint.c.
Referenced by nloptIATGO(), nloptITGO1(), nloptITGO2(), nloptMPSO(), and nloptSimplexARRS().
|
extern |
Remove any empty parameters from NLOPT structure.
Parameters which have NaN in place of xfull[] or xdelta[] are removed from the list; if found, totalNr is reduced accordingly.
Definition at line 398 of file nlopt.c.
Nelder-Mead (downhill simplex) optimization.
If the number of free parameters (not fixed) is one, then bracketing method is used instead of downhill simplex.
| nlo | Pointer to NLOPT structure. |
| maxIter | Maximum number of iterations; set to zero to use the default. |
| status | Pointer to status data; enter NULL if not needed. |
Definition at line 32 of file simplex.c.
Referenced by nloptIATGO(), nloptITGO1(), nloptITGO2(), nloptMPSO(), nloptSimplexARRS(), and nloptSimplexMS().
Accumulative Restarting Random start-point Nelder-Mead (downhill simplex) optimization.
| nlo | Pointer to NLOPT structure. |
| maxIter | Maximum number of iterations; set to zero to use the default. |
| status | Pointer to status data; enter NULL if not needed. |
Definition at line 373 of file simplex.c.
Multi-Start-point Nelder-Mead (downhill simplex) optimization.
| nlo | Pointer to NLOPT structure. |
| spNr | Number of start points; set to zero to use the default. |
| status | Pointer to status data; enter NULL if not needed. |
Definition at line 624 of file simplex.c.
|
extern |
Sort NLOPT plist into the order of increasing function values.
The first 'funCalls' items in plist are sorted.
| nlo | Pointer to NLOPT structure. |
Definition at line 182 of file nlopt.c.
Referenced by nloptIATGO(), and nloptSimplexARRS().
|
extern |
Write the contents of NLOPT structure to the specified file pointer.
| d | Pointer to NLOPT |
| fp | Output file pointer |
Definition at line 302 of file nlopt.c.