View Single Post
  #8  
Old 05-08-2013, 07:25 PM
catherine catherine is offline
Member
 
Join Date: Apr 2013
Posts: 18
Default Re: *ANSWER* HW5 Q8/9 - Help with R code

Yes, I now get average number of epochs = 340.17 and average error out = 0.1036295 after correcting the exit condition for the gradient descent:

Code:
# Gradient descent
  repeat {
    wbase = w;
    nEpoch = nEpoch +1;
    # Permutate In-sample and update weight vector with each data point in turn
    permuted.ind = sample(nIn, nIn, replace=FALSE);
    for (j in permuted.ind) {
      v = (-YIn[j] * XIn[j,]) / (1 + exp(YIn[j] * (XIn[j,] %*% w)));
      w = w - eta * v;
    }
    # Stop gradient descent as soon as delta(w, wbase) < 0.01
    if (sqrt(sum((w - wbase)^2)) < 0.01) break()
  }
There is nothing wrong with your code ... except for the eta value you're using: 0.1 instead of 0.01. Sorry ...
Reply With Quote