极大似然估计
__________________________________________________________________________________
One Dimensional Optimization
Description
The function optimize
searches the interval from lower
to upper
for a minimum or maximum of the function f
with respect to its first argument.
optimise
is an alias for optimize
.
Usage
optimize(f = , interval = , ..., lower = min(interval), upper = max(interval), maximum = FALSE, tol = .Machine$double.eps^0.25) optimise(f = , interval = , ..., lower = min(interval), upper = max(interval), maximum = FALSE, tol = .Machine$double.eps^0.25)
Arguments
f |
the function to be optimized. The function is either minimized or maximized over its first argument depending on the value of |
interval |
a vector containing the end-points of the interval to be searched for the minimum. |
... |
additional named or unnamed arguments to be passed to |
lower |
the lower end point of the interval to be searched. |
upper |
the upper end point of the interval to be searched. |
maximum |
logical. Should we maximize or minimize (the default)? |
tol |
the desired accuracy. |
Value
A list with components minimum
(or maximum
) and objective
which give the location of the minimum (or maximum) and the value of the function at that point.
Examples
require(graphics) f <- function (x,a) (x-a)^2 xmin <- optimize(f, c(0, 1), tol = 0.0001, a = 1/3) xmin ## See where the function is evaluated: optimize(function(x) x^2*(print(x)-1), lower=0, upper=10) ## "wrong" solution with unlucky interval and piecewise constant f(): f <- function(x) ifelse(x > -1, ifelse(x < 4, exp(-1/abs(x - 1)), 10), 10) fp <- function(x) { print(x); f(x) } plot(f, -2,5, ylim = 0:1, col = 2) optimize(fp, c(-4, 20))# doesn't see the minimum optimize(fp, c(-7, 20))# ok