Skip to content

Commit

Permalink
Fix/memory_state_from_sm2-FSRS-4.5 (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
L-M-Sherlock committed May 15, 2024
1 parent 64b5f51 commit f438477
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 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.6.2"
version = "0.6.3"
authors = ["Open Spaced Repetition"]
categories = ["algorithms", "science"]
edition = "2021"
Expand Down
29 changes: 14 additions & 15 deletions src/inference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ impl<B: Backend> FSRS<B> {
interval: f32,
sm2_retention: f32,
) -> Result<MemoryState> {
let stability = interval.max(S_MIN) / (9.0 * (1.0 / sm2_retention - 1.0));
let stability =
interval.max(S_MIN) * FACTOR as f32 / (sm2_retention.powf(1.0 / DECAY as f32) - 1.0);
let w = &self.model().w;
let w8: f32 = w.get(8).into_scalar().elem();
let w9: f32 = w.get(9).into_scalar().elem();
Expand Down Expand Up @@ -573,20 +574,18 @@ mod tests {
#[test]
fn memory_from_sm2() -> Result<()> {
let fsrs = FSRS::new(Some(&[]))?;
assert_eq!(
fsrs.memory_state_from_sm2(2.5, 10.0, 0.9).unwrap(),
MemoryState {
stability: 9.999995,
difficulty: 7.4120417
}
);
assert_eq!(
fsrs.memory_state_from_sm2(1.3, 20.0, 0.9).unwrap(),
MemoryState {
stability: 19.99999,
difficulty: 10.0
}
);
let memory_state = fsrs.memory_state_from_sm2(2.5, 10.0, 0.9).unwrap();
Data::from([memory_state.stability, memory_state.difficulty])
.assert_approx_eq(&Data::from([9.999996, 7.4120417]), 5);
let memory_state = fsrs.memory_state_from_sm2(2.5, 10.0, 0.8).unwrap();
Data::from([memory_state.stability, memory_state.difficulty])
.assert_approx_eq(&Data::from([4.170096, 9.491373]), 5);
let memory_state = fsrs.memory_state_from_sm2(2.5, 10.0, 0.95).unwrap();
Data::from([memory_state.stability, memory_state.difficulty])
.assert_approx_eq(&Data::from([21.712555, 2.80758]), 5);
let memory_state = fsrs.memory_state_from_sm2(1.3, 20.0, 0.9).unwrap();
Data::from([memory_state.stability, memory_state.difficulty])
.assert_approx_eq(&Data::from([19.999992, 10.0]), 5);
let interval = 15;
let ease_factor = 2.0;
let fsrs_factor = fsrs
Expand Down

0 comments on commit f438477

Please sign in to comment.