maximizing function using optim in r where one of the parameters is an integer

1.4k Views Asked by At

I have a function that I need to maximize that contains 3 parameters, one of which is an integer.

How do I let the optim function know to maximize (instead of minimize which is the default). And how do I let it know that one of the parameters in an integer?

Will it work if one of the parameters is a binary or categorical?

1

There are 1 best solutions below

0
On

Max vs min is easy (set fnscale=-1 in the control parameter).

Integer parameters are not easy. Such problems are called mixed integer programming problems and most available methods only handle mixed linear or quadratic problems. From the Optimization Task View:

MIP (Mixed integer programming and its variants MILP for LP and MIQP for QP, 90C11): glpkAPI, lpSolve, lpSolveAPI, Rcplex, Rglpk, Rmosek, Rsymphony

(I'm not very familiar with these methods.)

Most of the methods implemented in optim assume continuous parameter spaces. (method="SANN" will work since you can give it explicit rules for updating - see the examples - but it's tricky to get it to work efficiently.) Most of the optimizers listed in the Optimization Task View are for continuous optimization - the section on global/stochastic gives the most options for mixed discrete/continuous problems.

If the range of plausible integers is reasonably small you can use brute force (i.e., optimize over the two continuous parameters for each of a range of fixed integer values); you could also use bisection search over the integers.