Displaying 2 results from an estimated 2 matches for "swapfun".
Did you mean:
stepfun
2009 Mar 29
4
Constrined dependent optimization.
I have an optimization question that I was hoping to get some suggestions on how best to go about sovling it. I would think there is probably a package that addresses this problem.
This is an ordering optimzation problem. Best to describe it with a simple example. Say I have 100 "bins" each with a ball in it numbered from 1 to 100. Each bin can only hold one ball. This optimization is
2009 Apr 01
0
回复: R-help Digest, Vol 73, Issue 32
...see that SANN allows you to pass the
"gradient" argument (gr) as a custom function to provide the
candidate distribution. Here's an example:
N <- 10
xvec <- seq(0,1,length=N)
target <- rank((xvec-0.2)^2)
objfun <- function(x) {
sum((x-target)^2)/1e6
}
objfun(1:100)
swapfun <- function(x,N=10) {
loc <- sample(N,size=2,replace=FALSE)
tmp <- x[loc[1]]
x[loc[1]] <- x[loc[2]]
x[loc[2]] <- tmp
x
}
set.seed(1001)
opt1 <- optim(fn=objfun,
par=1:N,
gr=swapfun,method="SANN",
control=list(trace=10)...