Edited algorithm to save incremental weights (for calculating marginal likelihood of the data