Displaying 1 result from an estimated 1 matches for "theta_all".
Did you mean:
theta_a1
2009 Apr 26
1
Stochastic Gradient Ascent for logistic regression
...moke, ht, ui)
#y<-low
my_logistic<-function(X,y)
{
alpha <- 0.005
n<-5
m<-189
max_iters <- 189 #number of obs
ll<-0
X<-cbind(1,X)
theta <-rep(0,6) # intercept and 5 regerssors
#theta <- c(1.39, -0.034, -0.01, 0.64, 1.89, 0.88) #glm estimates as
starting values
theta_all<-theta
for (i in 1:max_iters)
{
dim(X)
length(theta)
hx <- sigmoid(X %*% theta) # matrix
product
ix<-i
for (j in 1:6)
{
theta[j] <- theta[j] + alpha * ((y-hx)[ix]) * X[ix,j]
#stochastic gradient !
}
logl <- sum( y * log(hx) + (1 - y) * log(1 - hx) ) #direct
multiplicatio...