Skip to content

Commit

Permalink
Fix/PLS shouldn't exceed last_s (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
L-M-Sherlock authored Feb 13, 2024
1 parent c6ab4b6 commit 54df730
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fsrs"
version = "0.4.0"
version = "0.4.1"
authors = ["Open Spaced Repetition"]
categories = ["algorithms", "science"]
edition = "2021"
Expand Down
4 changes: 2 additions & 2 deletions src/inference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,14 +468,14 @@ mod tests {
let metrics = fsrs.evaluate(items.clone(), |_| true).unwrap();

Data::from([metrics.log_loss, metrics.rmse_bins])
.assert_approx_eq(&Data::from([0.201_908, 0.013_894]), 5);
.assert_approx_eq(&Data::from([0.201_908, 0.013_964]), 5);

let (self_by_other, other_by_self) = fsrs
.universal_metrics(items, &DEFAULT_PARAMETERS, |_| true)
.unwrap();

Data::from([self_by_other, other_by_self])
.assert_approx_eq(&Data::from([0.015_987_674, 0.019_702_684]), 5);
.assert_approx_eq(&Data::from([0.015_987, 0.019_767]), 5);
Ok(())
}

Expand Down
9 changes: 6 additions & 3 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,13 @@ impl<B: Backend> Model<B> {
last_d: Tensor<B, 1>,
r: Tensor<B, 1>,
) -> Tensor<B, 1> {
self.w.get(11)
let new_s = self.w.get(11)
* last_d.pow(-self.w.get(12))
* ((last_s + 1).pow(self.w.get(13)) - 1)
* ((-r + 1) * self.w.get(14)).exp()
* ((last_s.clone() + 1).pow(self.w.get(13)) - 1)
* ((-r + 1) * self.w.get(14)).exp();
new_s
.clone()
.mask_where(last_s.clone().lower(new_s), last_s)
}

fn mean_reversion(&self, new_d: Tensor<B, 1>) -> Tensor<B, 1> {
Expand Down

0 comments on commit 54df730

Please sign in to comment.