pseudoOptim {FME} | R Documentation |
Fits a model to data, using the pseudo-random search algorithm of Price (1997), a random-based fitting technique.
pseudoOptim(f, p,..., lower, upper, control=list())
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 funtion 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. |
The control
argument is a list that can supply any of the
following components:
numiter
iterations has been performed or when the remaining variation is less
than varleft
.
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.
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. |
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. |
Karline Soetaert <k.soetaert@nioo.knaw.nl>
Soetaert, K. and P.M.J. Herman, 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.
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), cost) p2 <- optim(par=c(amplitude=1,phase=1,period=1), 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"))