[R] optim doesnt work with my function

nmolanogunal nmolanog at gmail.com
Fri Apr 2 22:28:43 CEST 2010


#Hello, i have created this function, but optim doesnt maximize it, just
return the value at the inits

W<-function(l){
w<-rep(0,dim(D)[1])
for(i in 1:dim(D)[1]){
w[i]<-PAitk(D[i,],D[-i,],l)
}
return(prod(w))
}
#D is a matrix with entires in {0,1}, l is a vector which length(l)=
dim(D)[2]
#PAitk is an other function defined as

PAitk<-function(y,D,lambda){
o<-rep(0,dim(D)[1])
for(i in 1:dim(D)[1]){
o[i]<-Aitk(lambda,y,D[i,])
}
return(sum(o)/dim(D)[1])
}
#with the same restriction on l and 

Aitk<-function(l,x,y){
prod((l^(1-abs(x-y)))*((1-l)^abs(x-y)))
}
#with the same restriction on l
#i want to maximize W in this way
optim(rep(.75,5),W,method ="L-BFGS-B",lower
=rep(0.50001,5),upper=rep(0.9999,5),control=list(fnscale=-1))

#but as i tell you before it just returns the W´s value at the inits
rep(.75,5) or any you put on it.
#I am grateful for the help that you could offer to me
-- 
View this message in context: http://n4.nabble.com/optim-doesnt-work-with-my-function-tp1749591p1749591.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list