open-spaced-repetition / fsrs-rs

FSRS for Rust, including Optimizer and Scheduler
https://crates.io/crates/fsrs
BSD 3-Clause "New" or "Revised" License
185 stars 19 forks source link

[Question] What does `memory_state` do? #242

Closed sineptic closed 4 weeks ago

sineptic commented 1 month ago

What calculating memory_state do? I have this question because it accepts starting state. I need to store previous calculations or if not when I want to pass it?

sineptic commented 1 month ago

How I can in one time have information about card review history and modify memory_state by passing value from memory_state_from_sm2?

L-M-Sherlock commented 1 month ago

https://github.com/open-spaced-repetition/fsrs-rs/blob/4f181264af6060c1fbcba05f09256a180cda1e9f/src/inference.rs#L73-L107

What calculating memory_state do? I have this question because it accepts starting state. I need to store previous calculations or if not when I want to pass it?

The function is used to calculate the latest memory state of a given card from its review history. If the history is incomplete (e.g., the first review is lost), the starting state is required.

How I can in one time have information about card review history and modify memory_state by passing value from memory_state_from_sm2?

You don't need to use memory_state_from_sm2 if you have complete review history. To get card review history in one time, you need to store review history in your database and query them by card_id.

sineptic commented 1 month ago

So is it true, that I can think about this funcion as 2 different(one for migrating, one for main use)?

L-M-Sherlock commented 1 month ago

There are four cases:

  1. You have complete review history but it's your first time to calculate the memory state: use memory_state.
  2. You don't have any review history: use memory_state_from_sm2
  3. You have review history but it's truncated (some earlier logs are lost): use memory_state_from_sm2 in the earliest log to get the starting_state and then use memory_state.
  4. You have calculated the memory state for the card in the last review, and then you do a new review: use next_states.
L-M-Sherlock commented 4 weeks ago

I added three examples:

https://github.com/open-spaced-repetition/fsrs-rs/blob/main/examples/migrate.rs

They may help you understand how memory_state works.

sineptic commented 4 weeks ago

Thank you so much!