pseudoOptim: Pseudo-random Search Optimisation Algorithm of Price (1977)

pseudoOptimR Documentation

Pseudo-random Search Optimisation Algorithm of Price (1977)

Description

Fits a model to data, using the pseudo-random search algorithm of Price (1977), a random-based fitting technique.

Usage

pseudoOptim(f, p,..., lower, upper, control = list())

Arguments

f

function to be minimised, its first argument should be the vector of parameters over which minimization is to take place. It should return a scalar result, the model cost, e.g the sum of squared residuals.

p

initial values of the parameters to be optimised.

...

arguments passed to function f.

lower

minimal values of the parameters to be optimised; these must be specified; they cannot be -Inf.

upper

maximal values of the parameters to be optimised; these must be specified; they cannot be +Inf.

control

a list of control parameters - see details.

Details

The control argument is a list that can supply any of the following components:

  • npop, number of elements in the population. Defaults to max(5*length(p),50).

  • numiter, maximal number of iterations to be performed. Defaults to 10000. The algorithm either stops when numiter iterations has been performed or when the remaining variation is less than varleft.

  • centroid, number of elements from which to estimate a new parameter vector, defaults to 3.

  • varleft, relative variation remaining; if below this value the algorithm stops; defaults to 1e-8.

  • verbose, if TRUE, more verbose output will contain the parameters in the final population, their respective population costs and the cost at each succesful interation. Defaults to FALSE.

see the book of Soetaert and Herman (2009) for a description of the algorithm AND for a line to line explanation of the function code.

Value

a list containing:

par

the optimised parameter values.

cost

the model cost, or function evaluation associated to the optimised parameter values, i.e. the minimal cost.

iterations

the number of iterations performed.

and if control$verbose is TRUE:

poppar

all parameter vectors remaining in the population, matrix of dimension (npop,length(par)).

popcost

model costs associated with all population parameter vectors, vector of length npop.

rsstrace

a 2-columned matrix with the iteration number and the model cost at each succesful iteration.

Author(s)

Karline Soetaert <karline.soetaert@nioz.nl>

References

Soetaert, K. and Herman, P. M. J., 2009. A Practical Guide to Ecological Modelling. Using R as a Simulation Platform. Springer, 372 pp.

Price, W.L., 1977. A Controlled Random Search Procedure for Global Optimisation. The Computer Journal, 20: 367-370.

Examples

amp    <- 6
period <- 5
phase  <- 0.5

x <- runif(20)*13 
y <- amp*sin(2*pi*x/period+phase) + rnorm(20, mean = 0, sd = 0.05)
plot(x, y, pch = 16)


cost <- function(par)
    sum((par[1] * sin(2*pi*x/par[2]+par[3])-y)^2)

p1 <- optim(par = c(amplitude = 1, phase = 1, period = 1), fn = cost)
p2 <- optim(par = c(amplitude = 1, phase = 1, period = 1), fn = cost, 
            method = "SANN")
p3 <- pseudoOptim(p = c(amplitude = 1, phase = 1, period = 1), 
            lower = c(0, 1e-8, 0), upper = c(100, 2*pi, 100), 
            f = cost, control = c(numiter = 3000, verbose = TRUE))

curve(p1$par[1]*sin(2*pi*x/p1$par[2]+p1$par[3]), lty = 2, add = TRUE)
curve(p2$par[1]*sin(2*pi*x/p2$par[2]+p2$par[3]), lty = 3, add = TRUE)
curve(p3$par[1]*sin(2*pi*x/p3$par[2]+p3$par[3]), lty = 1, add = TRUE)
legend ("bottomright", lty = c(1, 2, 3),
         c("Price", "Mathematical", "Simulated annealing"))

FME documentation built on July 9, 2023, 5:59 p.m.