Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatial Database Systems Design Implementation And Project Management

Authors: Albert K.W. Yeung, G. Brent Hall

1st Edition

1402053932, 978-1402053931

More Books

Students also viewed these Databases questions

Question

What types of nonverbal behavior have scholars identifi ed?

Answered: 1 week ago