也遇到类似问题,我的函数如下:
StochApprom=function(theta,feasiblespace,u,t,z,c){
for (k in 1:10000){
gradient=SGrad(theta,u,t,z,c)
a_k=0.001/k # step size is tunable
theta=theta-a_k*gradient
for (i in 2:length(theta)){
if (theta[i]<feasiblespace[1,i-1]) {
theta[i]=feasiblespace[1,i-1]
} else if (theta[i]>feasiblespace[2,i-1]) {
theta[i]=feasiblespace[2,i-1]
}
}
}
theta
}
调用出错如下:
> StochApprom(theta,fsblsp,u,t,z,c)
Error in if (theta[i] < feasiblespace[1, i - 1]) { :
missing value where TRUE/FALSE needed