Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started