nlm.prob | R Documentation |
nlm.prob
minimises/maximises a function allowing probability vectors as inputs
nlm.prob( f, p, prob.vectors = list(1:length(p)), ..., lambda = 1, eta0max = 1e+10, maximise = FALSE, maximize = maximise, hessian = FALSE, typsize = rep(1, length(p)), fscale = 1, print.level = 0, ndigit = 12, gradtol = 1e-06, stepmax = max(1000 * sqrt(sum((p/typsize)^2)), 1000), steptol = 1e-06, iterlim = 100, check.analyticals = TRUE )
f |
The objective function to be minimised; output should be a single numeric value. |
p |
Starting argument values for the minimisation. |
prob.vectors |
A list specifying which sets of elements are constrained to be a probability vector (each element in the list should be a vector specifying indices in the argument vector; elements cannot overlap into multiple probability vectors). |
... |
Additional arguments to be passed to |
lambda |
The tuning parameter used in the softmax transformation for the optimisation (a single positive numeric value). |
eta0max |
The maximum absolute value for the elements of eta0 (the starting value in the unconstrained optimisation problem). |
maximise, maximize |
Logical value; if |
hessian |
Logical; if |
typsize |
An estimate of the size of each parameter at the minimum. |
fscale |
An estimate of the size of |
print.level |
This argument determines the level of printing which is done during the minimisation process. The default value
of |
ndigit |
The number of significant digits in the function |
gradtol |
A positive scalar giving the tolerance at which the scaled gradient is considered close enough to zero to terminate
the algorithm. The scaled gradient is a measure of the relative change in |
stepmax |
A positive scalar which gives the maximum allowable scaled step length. |
steptol |
A positive scalar providing the minimum allowable relative step length. |
iterlim |
A positive integer specifying the maximum number of iterations to be performed before the routine is terminated. |
check.analyticals |
Logical; if |
This is a variation of the stats::nlm
function for nonlinear minimisation. The present function is designed to
minimise an objective function with one or more arguments that are probability vectors. (The objective function may also
have other arguments that are not probability vectors.) The function uses the same inputs as the stats::nlm
function,
except that the user can use the input prob.vectors
to specify which inputs are constrained to be probability vectors.
This input is a list where each element in the list specifies a set of indices for the argument of the objective function; the
specified set of indices is constrained to be a probability vector (i.e., each corresponding argument is non-negative and the
set of these arguments must sum to one). The input prob.vectors
may list one or more probability vectors, but they must
use disjoint elements of the argument (i.e., a variable in the argument cannot appear in more than one probability vector).
Optimisation is performed by first converting the objective function into unconstrained form using the softmax transformation
and its inverse to convert from unconstrained space to probability space and back. Optimisation is done on the unconstrained
objective function and the results are converted back to probability space to solve the constrained optimisation problem. For
purposes of conversion, this function allows specification of a tuning parameter lambda
for the softmax and inverse-
softmax transformations. (This input can either be a single tuning value used for all conversions, or a vector of values for
the respective probability vectors; if the latter, there must be one value for each element of the prob.vector
input.)
Most of the input descriptions below are adapted from the corresponding descriptions in stat::nlm
, since our function is
a wrapper to that function. The additional inputs for this function are prob.vectors
, lambda
and eta0max
.
The function also adds an option maximise
to conduct maximisation instead of minimisation.
A list showing the computed minimising point and minimum of f
and other related information.
x <- rbinom(100, 1, .2) nlm.prob(function(p) sum(dbinom(x,1,p[2],log=TRUE)), c(.5, .5), maximise = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.