JinwoongKim / cs231n

0 stars 0 forks source link

assignment1-3 #3

Open JinwoongKim opened 6 years ago

JinwoongKim commented 6 years ago

softmax_loss_naive

screen shot 2018-08-19 at 20 25 43

  loss = 0.0
  for i in xrange(num_train):
    scores = X[i].dot(W)
    score_yi = scores[y[i]]
    sum_esj = 0
    for j in xrange(num_classes):
      if j == y[i]:
        continue
      sum_esj += np.exp(scores[j])
    loss += np.log(np.exp(score_yi)/sum_esj)*-1

screen shot 2018-08-19 at 20 26 12

JinwoongKim commented 6 years ago

screen shot 2018-08-19 at 20 36 09

loss = 0.0
  for i in xrange(num_train):
    scores = X[i].dot(W)
    scores -= np.max(scores)
    sum_esj = np.sum(np.exp(scores))
    loss += np.log(np.exp(scores[y[i]])/sum_esj)*-1
JinwoongKim commented 6 years ago

For gradient descent, I found these codes,

  loss = 0.0
  for i in xrange(num_train):
    scores = X[i].dot(W)
    scores -= np.max(scores)
    sum_esj = np.sum(np.exp(scores))
    loss += np.log(np.exp(scores[y[i]])/sum_esj)*-1

    for j in xrange(num_classes):
        if j == y[i]:
            dW[:, y[i]] += (-1) * (sum_esj - np.exp(scores[y[i]])) / sum_esj * X[i]
        else:
            dW[:, j] += np.exp(scores[j]) / sum_esj * X[i]

But couldn't found any equation and note;