theta00=runif(20,-1,1)
obj1 <- function(thetac){
for (j in 1:(N/k)) {
for (i in 1:20) {
ps1 <- vector(mode = "numeric",20)
ps1[i] = thetac[i]*x[i,j]
}
mtheta1[j] <- y[j]*sum(ps1)-log(1+exp(sum(ps1)))
}
Mtheta1=(-1)*sum(mtheta1)/(N/k)
return(Mtheta1)
}
gradobj1 <- grad(obj1,theta00)
19个为零,结果显然是不对的,应该怎么写梯度函数