Question: 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
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
