synth-inference/synthdid

Proposal to enhance stopping criterion in sc.weight.fw.covariates

PetraTschuchnig opened this issue · 1 comments

When using the sc.weight.fw.covariates function, the stopping criterion is currently defined as follows: while (t < max.iter && (t < 2 || vals[t - 1] - vals[t] > min.decrease^2)) {...}. However, during optimization with covariates, vals can increase from one iteration to the next, causing the difference vals[t - 1] - vals[t] to become negative. This can prematurely terminate the optimization task even if there's actually a deterioration.
To prevent this issue, I suggest using the absolute difference abs(vals[t - 1] - vals[t]) as part of the stopping criterion, like so: while (t < max.iter && (t < 2 || abs(vals[t - 1] - vals[t]) > min.decrease^2)) {...}. If you find this change reasonable, I would be happy to push the changes to a fork and create a merge request.