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 dfpw B data, labels, predfprediction, gradfgradient, lossflogloss maxiter tol:
w w
Binv nplinalg.invB # We only compute the inverse at initialization
gradw gradflenw w data, labels
for i in rangemaxiter:
# Step :
p npdotBinv, gradw # Use npdot instead of npouter
# Step :
alpha wolfew p data, labels
# Step :
s alpha p
wnew w s
gradnew gradflenw wnew, data, labels
# Step :
if nplinalg.normgradnew gradw tol:
break
y gradnew gradw
gradw gradnew
sy npdots y
# Step DFP Update:
Bs npdotBinv, s
Binv Binv npouters s npdots y npouterBs Bs npdots Bs
# Step print:
predictions predfw data
loss lossfpredictions labels
printiter: i loss:", loss
w wnew
return w
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
