I have an optimization problem with no constraints (at least none for now). I'm wondering if the error I'll describe arises from not specifying any constraints? I wouldn't think so.
I have a function with two arguments, lagg
and thres
I have a vector of zeros and ones representing recession dates. I want to manipulate an economic time series (turning it into zeros and ones) and get it as close to "dating" recessions as possible.
Here is the function, which is passed to eval_f
hoping to maximize the F1 score.
fxn_unsmoothed2 <- function(input)
{ lagg <- input[1]
thres <- input[2]
truth <- data.matrix(USREC[-1:-lagg,])
chng <- percentchange(goodsmtx,lagg)
chng[chng<thres] <- 1
chng[chng!=1] <- 0
FP <- length(which(chng==1 & truth==0))
FN <- length(which(chng==0 & truth==1))
TP <- length(which(chng==1 & truth==1))
TN <- length(which(chng==0 & truth==0))
return (2*(TP/(TP+FP))*(TP/(TP+FN)) / ((TP/(TP+FP))+(TP/(TP+FN))))
}
The whole input[1]
thing is confusing to me. I saw it on a separate post.
I then do
x0 <- c(11,.005)
opts <- list("algorithm"="NLOPT_GN_ISRES",maxeval=100000)
res <- nloptr( x0=x0,
eval_f=fxn_unsmoothed2,
opts=opts)
It runs zero iterations and tells me:
NLOPT_INVALID_ARGS: Invalid arguments (e.g. lower bounds are bigger than upper bounds, an unknown algorithm was specified, etcetera
I have no idea what I'm doing wrong. At least I finally figured out how to pass initial arguments, lol.