Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Is this implementation of L - BFGS method correct? def l _ bfgs ( w _ 0 , data, labels, m = 1 0 ,
Is this implementation of LBFGS method correct?
def lbfgsw data, labels, m predfprediction, gradfgradient, lossflogloss maxiter tol:
w w
n lenw
slist
ylist
rholist
alphalist
gradw gradfn w data, labels
for i in rangemaxiter:
q gradw
alphalist.clear
for j in rangelenslist:
s slistj
y ylistj
rho rholistj
alpha rho npdots q
alphalist.appendalpha
q q alpha y
if lenslist:
gamma npdotslist ylist npdotylist ylist
H gamma npeyen
else:
H npeyen
z npdotH q
for j in rangelenslist:
s slistj
y ylistj
rho rholistj
beta rho npdoty z
alpha alphalistlenslist j
z z s alpha beta
p z
alpha wolfew p data, labels
s alpha p
wnew w s
gradnew gradfn wnew, data, labels
if nplinalg.normgradnew gradw tol:
break
y gradnew gradw
rho npdoty s
if lenslist m:
slist.pop
ylist.pop
rholist.pop
slist.appends
ylist.appendy
rholist.appendrho
gradw gradnew
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
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