I am exploring using R optim() or optimx() for a (very) nonlinear optimization. Essentially I wrote a function that takes as its inputs:
1) a data.frame with specific column names/types
2) a numeric vector of length 1
3) a numeric vector of length > 1
The function then takes the inputs, performs some calculations and logic tests, then either returns a very negative value if the logic tests are FALSE, or the value of input #2 if the logic tests are TRUE. The goal is to maximize #2 without tripping the logic tests to FALSE.
I tried using optimx() with the following code (the par values correspond to the inputs I refer to above):
optimout <-
optimx:::optimx(
par = c(inputDF, 5000, rep(99,20)),
fn = MyFunction,
maximize = TRUE)
I received the following error message:
Error in optimx.check(par, optcfg$ufn, optcfg$ugr, optcfg$uhess, lower, : Cannot evaluate function at initial parameters
Ralph
MyFunction
at the initial conditionsc(inputDF, 5000, rep(99,20))
. What do you get ? – Marco SandriMyFunction
has 3 or 1 inputs ? – Marco Sandrioptimx
: fn = A function to be minimized (or maximized), with first argument the vector of parameters over which minimization is to take place. – Marco Sandri