How does one optimize if the parameter space is only integers (or is otherwise discontinuous)?
Using an integer check in optim() does not seem to work and would be very inefficient anyways.
fr <- function(x) { ## Rosenbrock Banana function
x1 <- x[1]
x2 <- x[2]
value<-100 * (x2 - x1 * x1)^2 + (1 - x1)^2
check.integer <- function(N){
!length(grep("[^[:digit:]]", as.character(N)))
}
if(!all(check.integer(abs(x1)), check.integer(abs(x2)))){
value<-NA
}
return(value)
}
optim(c(-2,1), fr)
Here are a few ideas.
1. Penalized optimization.
You could round the arguments of the objective function
and add a penalty for non-integers.
But this creates a lot of local extrema,
so you may prefer a more robust optimization routine,
e.g., differential evolution or particle swarm optimization.
2. Exhaustive search.
If the search space is small, you can also use a grid search.
3. Local search, with user-specified neighbourhoods.
Without tweaking the objective function, you could use some form of local search,
in which you can specify which points to examine.
This should be much faster, but is extremely sensitive to the choice of the neighbourhood function.
4. Tabu search.
To avoid exploring the same points again and again, you can use
tabu search,
i.e., remember the last k points to avoid visiting them again.
In the following example, it does not really work:
we only move to the nearest local minimum.
And in higher dimensions, things get even worse:
the neighbourhood is so large that we never hit the cache
of already visited points.
Differential evolution works better: we only get a local minimum,
but it is better than the nearest one.
Tabu search is often used for purely combinatorial problems
(e.g., when the search space is a set of trees or graphs)
and does not seem to be a great idea for integer problems.