spect_match {pomp} | R Documentation |
Spectrum matching
Description
Estimation of parameters by matching power spectra
Usage
## S4 method for signature 'data.frame'
spect_objfun(
data,
est = character(0),
weights = 1,
fail.value = NA,
vars,
kernel.width,
nsim,
seed = NULL,
transform.data = identity,
detrend = c("none", "mean", "linear", "quadratic"),
params,
rinit,
rprocess,
rmeasure,
partrans,
...,
verbose = getOption("verbose", FALSE)
)
## S4 method for signature 'pomp'
spect_objfun(
data,
est = character(0),
weights = 1,
fail.value = NA,
vars,
kernel.width,
nsim,
seed = NULL,
transform.data = identity,
detrend = c("none", "mean", "linear", "quadratic"),
...,
verbose = getOption("verbose", FALSE)
)
## S4 method for signature 'spectd_pomp'
spect_objfun(
data,
est = character(0),
weights = 1,
fail.value = NA,
vars,
kernel.width,
nsim,
seed = NULL,
transform.data = identity,
detrend,
...,
verbose = getOption("verbose", FALSE)
)
## S4 method for signature 'spect_match_objfun'
spect_objfun(
data,
est,
weights,
fail.value,
seed = NULL,
...,
verbose = getOption("verbose", FALSE)
)
Arguments
data |
either a data frame holding the time series data,
or an object of class ‘pomp’,
i.e., the output of another pomp calculation.
Internally, |
est |
character vector; the names of parameters to be estimated. |
weights |
optional numeric or function.
The mismatch between model and data is measured by a weighted average of mismatch at each frequency.
By default, all frequencies are weighted equally.
|
fail.value |
optional numeric scalar;
if non- |
vars |
optional; names of observed variables for which the power spectrum will be computed. By default, the spectrum will be computed for all observables. |
kernel.width |
width parameter for the smoothing kernel used for calculating the estimate of the spectrum. |
nsim |
the number of model simulations to be computed. |
seed |
integer.
When fitting, it is often best to fix the seed of the random-number generator (RNG).
This is accomplished by setting |
transform.data |
function; this transformation will be applied to the observables prior to estimation of the spectrum, and prior to any detrending. |
detrend |
de-trending operation to perform. Options include no detrending, and subtraction of constant, linear, and quadratic trends from the data. Detrending is applied to each data series and to each model simulation independently. |
params |
optional; named numeric vector of parameters.
This will be coerced internally to storage mode |
rinit |
simulator of the initial-state distribution.
This can be furnished either as a C snippet, an R function, or the name of a pre-compiled native routine available in a dynamically loaded library.
Setting |
rprocess |
simulator of the latent state process, specified using one of the rprocess plugins.
Setting |
rmeasure |
simulator of the measurement model, specified either as a C snippet, an R function, or the name of a pre-compiled native routine available in a dynamically loaded library.
Setting |
partrans |
optional parameter transformations, constructed using Many algorithms for parameter estimation search an unconstrained space of parameters.
When working with such an algorithm and a model for which the parameters are constrained, it can be useful to transform parameters.
One should supply the |
... |
additional arguments are passed to |
verbose |
logical; if |
Details
In spectrum matching, one attempts to minimize the discrepancy between a POMP model's predictions and data, as measured in the frequency domain by the power spectrum.
spect_objfun
constructs an objective function that measures the discrepancy.
It can be passed to any one of a variety of numerical optimization routines, which will adjust model parameters to minimize the discrepancies between the power spectrum of model simulations and that of the data.
Value
spect_objfun
constructs a stateful objective function for spectrum matching.
Specifically, spect_objfun
returns an object of class ‘spect_match_objfun’, which is a function suitable for use in an optim
-like optimizer.
This function takes a single numeric-vector argument that is assumed to contain the parameters named in est
, in that order.
When called, it will return the (optionally weighted) L^2
distance between the data spectrum and simulated spectra.
It is a stateful function:
Each time it is called, it will remember the values of the parameters and the discrepancy measure.
Note for Windows users
Some Windows users report problems when using C snippets in parallel computations.
These appear to arise when the temporary files created during the C snippet compilation process are not handled properly by the operating system.
To circumvent this problem, use the cdir
and cfile
options to cause the C snippets to be written to a file of your choice, thus avoiding the use of temporary files altogether.
Important Note
Since pomp cannot guarantee that the final call an optimizer makes to the function is a call at the optimum, it cannot guarantee that the parameters stored in the function are the optimal ones. Therefore, it is a good idea to evaluate the function on the parameters returned by the optimization routine, which will ensure that these parameters are stored.
Warning! Objective functions based on C snippets
If you use C snippets (see Csnippet
), a dynamically loadable library will be built.
As a rule, pomp functions load this library as needed and unload it when it is no longer needed.
The stateful objective functions are an exception to this rule.
For efficiency, calls to the objective function do not execute pompLoad
or pompUnload
:
rather, it is assumed that pompLoad
has been called before any call to the objective function.
When a stateful objective function using one or more C snippets is created, pompLoad
is called internally to build and load the library:
therefore, within a single R session, if one creates a stateful objective function, one can freely call that objective function and (more to the point) pass it to an optimizer that calls it freely, without needing to call pompLoad
.
On the other hand, if one retrieves a stored objective function from a file, or passes one to another R session, one must call pompLoad
before using it.
Failure to do this will typically result in a segmentation fault (i.e., it will crash the R session).
References
D.C. Reuman, R.A. Desharnais, R.F. Costantino, O. Ahmad, J.E. Cohen. Power spectra reveal the influence of stochasticity on nonlinear population dynamics. Proceedings of the National Academy of Sciences 103, 18860-18865, 2006. doi:10.1073/pnas.0608571103.
D.C. Reuman, R.F. Costantino, R.A. Desharnais, J.E. Cohen. Color of environmental noise affects the nonlinear dynamics of cycling, stage-structured populations. Ecology Letters 11, 820-830, 2008. doi:10.1111/j.1461-0248.2008.01194.x.
See Also
More on pomp estimation algorithms:
abc()
,
bsmc2()
,
estimation_algorithms
,
mif2()
,
nlf
,
pmcmc()
,
pomp-package
,
probe_match
More on methods based on summary statistics:
abc()
,
basic_probes
,
nlf
,
probe()
,
probe_match
,
spect()
More on maximization-based estimation methods:
mif2()
,
nlf
,
probe_match
,
traj_match
Examples
ricker() |>
spect_objfun(
est=c("r","sigma","N_0"),
partrans=parameter_trans(log=c("r","sigma","N_0")),
paramnames=c("r","sigma","N_0"),
kernel.width=3,
nsim=100,
seed=5069977
) -> f
f(log(c(20,0.3,10)))
f |> spect() |> plot()
if (require(subplex)) {
subplex(fn=f,par=log(c(20,0.3,10)),control=list(reltol=1e-5)) -> out
} else {
optim(fn=f,par=log(c(20,0.3,10)),control=list(reltol=1e-5)) -> out
}
f(out$par)
f |> summary()
f |> spect() |> plot()