Generate a negated version of your function. Useful for 'nlminb' etc.
You pass it a function f(.)
; it returns a function whose result will be -f(.)
. The arguments, return attributes, and environment are identical to those of f
.
NEG(f)
f |
Normally, a function that returns a scalar; rarely, a NULL. |
A function that returns -f
. However, if is.null(f)
, the result is also NULL; this is useful e.g. for gradient arg to nlminb
.
NEG( sqrt)( 4) # -2 # should put in more complex one here... e <- new.env() e$const <- 3 funco <- function( x) -sum( ( x-const)^2L) environment( funco) <- e nlminb( c( 0, 0), NEG( funco)) # c( 3, 3) dfunco <- NULL nlminb( c( 0, 0), NEG( funco), gradient=NEG( dfunco)) # c( 3, 3)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.