Question: Is this implementation of stochastic BFGS correct? def s _ bfgs ( w _ 0 , B _ 0 , data, labels, pred _ f
Is this implementation of stochastic BFGS correct?
def sbfgsw B data, labels, predfprediction, gradfstochasticgradient, lossflogloss maxiter tol batchsize:
w w
Binv nplinalg.invB
gradw gradfw data, labels, batchsize
for i in rangemaxiter:
p npdotBinv, gradw # Use npdot instead of npouter
alpha wolfew p data, labels
s
alpha p
wnew w s
gradnew gradfwnew, data, labels, batchsize
if nplinalg.normgradnew gradw tol:
break
y gradnew gradw
gradw gradnew
sy npdots y
Binv Binv npdotyT npdotBinv, y sy npouters s sy npouternpdotBinv, y s npouters npdotBinv, y sy
predictions predfw data
loss lossfpredictions labels
printiter: i loss:", loss
w wnew
gradw gradnew
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
