Question: is this implementation of DEF method correct? def dfp ( w _ 0 , B _ 0 , data, labels, pred _ f = prediction,

is this implementation of DEF method correct?
def dfp(w_0, B_0, data, labels, pred_f=prediction, grad_f=gradient, loss_f=logloss, max_iter=100, tol=0.0001):
w = w_0
B_inv = np.linalg.inv(B_0) # We only compute the inverse at initialization
grad_w = grad_f(len(w), w, data, labels)
for i in range(max_iter):
# Step 1:
p =-np.dot(B_inv, grad_w) # Use np.dot instead of np.outer
# Step 2:
alpha = wolfe(w, p, data, labels)
# Step 3:
s = alpha * p
w_new = w + s
grad_new = grad_f(len(w), w_new, data, labels)
# Step 4:
if np.linalg.norm(grad_new - grad_w)< tol:
break
y = grad_new - grad_w
grad_w = grad_new
sy = np.dot(s, y)
# Step 5(DFP Update):
Bs = np.dot(B_inv, s)
B_inv = B_inv + np.outer(s, s)/ np.dot(s, y)- np.outer(Bs, Bs)/ np.dot(s, Bs)
# Step 6(print):
predictions = pred_f(w, data)
loss = loss_f(predictions, labels)
print("iter:", i," loss:", loss)
w = w_new
return w

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!