R: Pseudo-random Search Optimisation Algorithm of Price (1977)
pseudoOptim
R 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 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.
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.
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(FME)
Loading required package: deSolve
Attaching package: 'deSolve'
The following object is masked from 'package:graphics':
matplot
Loading required package: rootSolve
Loading required package: coda
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/FME/pseudoOptim.Rd_%03d_medium.png", width=480, height=480)
> ### Name: pseudoOptim
> ### Title: Pseudo-random Search Optimisation Algorithm of Price (1977)
> ### Aliases: pseudoOptim
> ### Keywords: optimize
>
> ### ** 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"))
>
>
>
>
> dev.off()
null device
1
>