You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is normal, although the code could be more self-explanatory:
In this code, the gradient step is not applied every time the gradient is computed. Indeed, if the data is sparse, the random sample X_i will change the averaged gradient only on features j where X_ij != 0. In some cases, the average gradient on feature j might change only after k random samples with no change. In these cases, instead of applying k times the same gradient step on feature j, we apply the gradient step only once, scaled by k. This is called the "Just-in-time update" (or lagged_update in the code).
So the gradient step is performed in lagged_update. This function also applies the prox operator after the weights update. Note that because the lagged update actually performs k gradient steps, we need to apply prox(gradient_step(prox(gradient_step(...)))), which kind of defeats the purpose of the lagged update, but this can be avoided sometimes with a trick actually taken from lightning.
For SAGA, there are also these lines, which change the weights outside of the lagged update because it is a term in SAGA that does not depend on the average gradient. The prox is applied later, in the following lagged update, before computing the following prediction.
On top of that, the SAG/A update scales down all the weights at each iteration. So to avoid updating all the weights at each iteration, there is a trick to factor out the scaling down, and to only apply it in the lagged update. When the factored-out scale is too small, it is reset for numerical stability, and this reset requires applying all remaining lagged updates.
This scale reset is also performed every n_samples iterations before each convergence check, so when the algorithm stops, we are sure that there is no remaining lagged updates.
Activity
ogrisel commentedon Oct 18, 2022
ping @arthurmensch
ogrisel commentedon Nov 17, 2022
Maybe @agramfort @mblondel or @pierreablin would like to confirm this and someone might want to open a PR with non-regression test if possible?
agramfort commentedon Nov 20, 2022
ping @TomDLT
I don't know this code very well
TomDLT commentedon Nov 22, 2022
This is normal, although the code could be more self-explanatory:
In this code, the gradient step is not applied every time the gradient is computed. Indeed, if the data is sparse, the random sample
X_iwill change the averaged gradient only on featuresjwhereX_ij != 0. In some cases, the average gradient on featurejmight change only afterkrandom samples with no change. In these cases, instead of applyingktimes the same gradient step on featurej, we apply the gradient step only once, scaled byk. This is called the "Just-in-time update" (orlagged_updatein the code).So the gradient step is performed in
lagged_update. This function also applies the prox operator after the weights update. Note that because the lagged update actually performskgradient steps, we need to applyprox(gradient_step(prox(gradient_step(...)))), which kind of defeats the purpose of the lagged update, but this can be avoided sometimes with a trick actually taken from lightning.For SAGA, there are also these lines, which change the weights outside of the lagged update because it is a term in SAGA that does not depend on the average gradient. The prox is applied later, in the following lagged update, before computing the following prediction.
On top of that, the SAG/A update scales down all the weights at each iteration. So to avoid updating all the weights at each iteration, there is a trick to factor out the scaling down, and to only apply it in the lagged update. When the factored-out scale is too small, it is reset for numerical stability, and this reset requires applying all remaining lagged updates.
This scale reset is also performed every
n_samplesiterations before each convergence check, so when the algorithm stops, we are sure that there is no remaining lagged updates.ogrisel commentedon Dec 2, 2022
@NikZak does this answer your concern?
ogrisel commentedon Dec 2, 2022
Maybe someone could open a PR to add some inline comments with either a copy of @TomDLT's comment or a link to it.