From 6adbd922f7d68d4fa15fb9b408b5b44e78bc7bd8 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 21 Oct 2024 18:10:08 +1000 Subject: [PATCH] Rename remaining 'weights' references to 'params' --- proto/anki/collection.proto | 8 +- proto/anki/deck_config.proto | 4 +- proto/anki/scheduler.proto | 32 ++--- pylib/anki/_backend.py | 4 +- qt/aqt/mediasrv.py | 8 +- rslib/src/backend/error.rs | 2 +- rslib/src/deckconfig/mod.rs | 2 +- rslib/src/deckconfig/schema11.rs | 10 +- rslib/src/deckconfig/update.rs | 38 +++--- rslib/src/error/mod.rs | 4 +- rslib/src/progress.rs | 14 +- rslib/src/scheduler/answering/mod.rs | 4 +- rslib/src/scheduler/fsrs/error.rs | 4 +- rslib/src/scheduler/fsrs/memory_state.rs | 18 +-- rslib/src/scheduler/fsrs/mod.rs | 2 +- .../scheduler/fsrs/{weights.rs => params.rs} | 43 +++--- rslib/src/scheduler/fsrs/retention.rs | 2 +- rslib/src/scheduler/fsrs/simulator.rs | 2 +- rslib/src/scheduler/service/mod.rs | 41 +++--- rslib/src/scheduler/states/load_balancer.rs | 8 +- rslib/src/stats/card.rs | 2 +- ts/routes/deck-options/FsrsOptions.svelte | 128 +++++++++--------- .../deck-options/FsrsOptionsOuter.svelte | 2 +- ...WeightsInput.svelte => ParamsInput.svelte} | 4 +- ...sInputRow.svelte => ParamsInputRow.svelte} | 4 +- ...earchRow.svelte => ParamsSearchRow.svelte} | 0 ts/routes/deck-options/SaveButton.svelte | 4 +- 27 files changed, 194 insertions(+), 200 deletions(-) rename rslib/src/scheduler/fsrs/{weights.rs => params.rs} (95%) rename ts/routes/deck-options/{WeightsInput.svelte => ParamsInput.svelte} (85%) rename ts/routes/deck-options/{WeightsInputRow.svelte => ParamsInputRow.svelte} (84%) rename ts/routes/deck-options/{WeightsSearchRow.svelte => ParamsSearchRow.svelte} (100%) diff --git a/proto/anki/collection.proto b/proto/anki/collection.proto index c08c36e27..fea70a787 100644 --- a/proto/anki/collection.proto +++ b/proto/anki/collection.proto @@ -127,21 +127,21 @@ message Progress { DatabaseCheck database_check = 6; string importing = 7; string exporting = 8; - ComputeWeightsProgress compute_weights = 9; + ComputeParamsProgress compute_params = 9; ComputeRetentionProgress compute_retention = 10; ComputeMemoryProgress compute_memory = 11; } } -message ComputeWeightsProgress { +message ComputeParamsProgress { // Current iteration uint32 current = 1; // Total iterations uint32 total = 2; uint32 reviews = 3; - // Only used in 'compute all weights' case + // Only used in 'compute all params' case uint32 current_preset = 4; - // Only used in 'compute all weights' case + // Only used in 'compute all params' case uint32 total_presets = 5; } diff --git a/proto/anki/deck_config.proto b/proto/anki/deck_config.proto index 1ac48c969..c3fc5298b 100644 --- a/proto/anki/deck_config.proto +++ b/proto/anki/deck_config.proto @@ -165,7 +165,7 @@ message DeckConfig { // used for fsrs_reschedule in the past reserved 39; float historical_retention = 40; - string weight_search = 45; + string param_search = 45; bytes other = 255; } @@ -215,7 +215,7 @@ message DeckConfigsForUpdate { enum UpdateDeckConfigsMode { UPDATE_DECK_CONFIGS_MODE_NORMAL = 0; UPDATE_DECK_CONFIGS_MODE_APPLY_TO_CHILDREN = 1; - UPDATE_DECK_CONFIGS_MODE_COMPUTE_ALL_WEIGHTS = 2; + UPDATE_DECK_CONFIGS_MODE_COMPUTE_ALL_PARAMS = 2; } message UpdateDeckConfigsRequest { diff --git a/proto/anki/scheduler.proto b/proto/anki/scheduler.proto index e0e653082..947a7812c 100644 --- a/proto/anki/scheduler.proto +++ b/proto/anki/scheduler.proto @@ -45,15 +45,15 @@ service SchedulerService { rpc CustomStudyDefaults(CustomStudyDefaultsRequest) returns (CustomStudyDefaultsResponse); rpc RepositionDefaults(generic.Empty) returns (RepositionDefaultsResponse); - rpc ComputeFsrsWeights(ComputeFsrsWeightsRequest) - returns (ComputeFsrsWeightsResponse); + rpc ComputeFsrsParams(ComputeFsrsParamsRequest) + returns (ComputeFsrsParamsResponse); rpc GetOptimalRetentionParameters(GetOptimalRetentionParametersRequest) returns (GetOptimalRetentionParametersResponse); rpc ComputeOptimalRetention(ComputeOptimalRetentionRequest) returns (ComputeOptimalRetentionResponse); rpc SimulateFsrsReview(SimulateFsrsReviewRequest) returns (SimulateFsrsReviewResponse); - rpc EvaluateWeights(EvaluateWeightsRequest) returns (EvaluateWeightsResponse); + rpc EvaluateParams(EvaluateParamsRequest) returns (EvaluateParamsResponse); rpc ComputeMemoryState(cards.CardId) returns (ComputeMemoryStateResponse); // The number of days the calculated interval was fuzzed by on the previous // review (if any). Utilized by the FSRS add-on. @@ -63,8 +63,8 @@ service SchedulerService { // Implicitly includes any of the above methods that are not listed in the // backend service. service BackendSchedulerService { - rpc ComputeFsrsWeightsFromItems(ComputeFsrsWeightsFromItemsRequest) - returns (ComputeFsrsWeightsResponse); + rpc ComputeFsrsParamsFromItems(ComputeFsrsParamsFromItemsRequest) + returns (ComputeFsrsParamsResponse); // Generates parameters used for FSRS's scheduler benchmarks. rpc FsrsBenchmark(FsrsBenchmarkRequest) returns (FsrsBenchmarkResponse); // Used for exporting revlogs for algorithm research. @@ -341,19 +341,19 @@ message RepositionDefaultsResponse { bool shift = 2; } -message ComputeFsrsWeightsRequest { +message ComputeFsrsParamsRequest { /// The search used to gather cards for training string search = 1; - repeated float current_weights = 2; + repeated float current_params = 2; int64 ignore_revlogs_before_ms = 3; } -message ComputeFsrsWeightsResponse { - repeated float weights = 1; +message ComputeFsrsParamsResponse { + repeated float params = 1; uint32 fsrs_items = 2; } -message ComputeFsrsWeightsFromItemsRequest { +message ComputeFsrsParamsFromItemsRequest { repeated FsrsItem items = 1; } @@ -362,7 +362,7 @@ message FsrsBenchmarkRequest { } message FsrsBenchmarkResponse { - repeated float weights = 1; + repeated float params = 1; } message ExportDatasetRequest { @@ -380,7 +380,7 @@ message FsrsReview { } message SimulateFsrsReviewRequest { - repeated float weights = 1; + repeated float params = 1; float desired_retention = 2; uint32 deck_size = 3; uint32 days_to_simulate = 4; @@ -398,7 +398,7 @@ message SimulateFsrsReviewResponse { } message ComputeOptimalRetentionRequest { - repeated float weights = 1; + repeated float params = 1; uint32 days_to_simulate = 2; uint32 max_interval = 3; string search = 4; @@ -431,13 +431,13 @@ message GetOptimalRetentionParametersResponse { uint32 review_limit = 15; } -message EvaluateWeightsRequest { - repeated float weights = 1; +message EvaluateParamsRequest { + repeated float params = 1; string search = 2; int64 ignore_revlogs_before_ms = 3; } -message EvaluateWeightsResponse { +message EvaluateParamsResponse { float log_loss = 1; float rmse_bins = 2; } diff --git a/pylib/anki/_backend.py b/pylib/anki/_backend.py index c3ac2a114..a0d8f8949 100644 --- a/pylib/anki/_backend.py +++ b/pylib/anki/_backend.py @@ -149,8 +149,8 @@ class RustBackend(RustBackendGenerated): ) return self.format_timespan(seconds=seconds, context=context) - def compute_weights_from_items(self, items: Iterable[FsrsItem]) -> Sequence[float]: - return self.compute_fsrs_weights_from_items(items).weights + def compute_params_from_items(self, items: Iterable[FsrsItem]) -> Sequence[float]: + return self.compute_fsrs_params_from_items(items).params def benchmark(self, train_set: Iterable[FsrsItem]) -> Sequence[float]: return self.fsrs_benchmark(train_set=train_set) diff --git a/qt/aqt/mediasrv.py b/qt/aqt/mediasrv.py index 26e52f503..ca4f23503 100644 --- a/qt/aqt/mediasrv.py +++ b/qt/aqt/mediasrv.py @@ -457,8 +457,8 @@ def update_deck_configs() -> bytes: update.max = val.total_cards update.value = val.current_cards update.label = val.label - elif progress.HasField("compute_weights"): - val2 = progress.compute_weights + elif progress.HasField("compute_params"): + val2 = progress.compute_params # prevent an indeterminate progress bar from appearing at the start of each preset update.max = max(val2.total, 1) update.value = val2.current @@ -621,10 +621,10 @@ exposed_backend_list = [ "update_image_occlusion_note", "get_image_occlusion_fields", # SchedulerService - "compute_fsrs_weights", + "compute_fsrs_params", "compute_optimal_retention", "set_wants_abort", - "evaluate_weights", + "evaluate_params", "get_optimal_retention_parameters", "simulate_fsrs_review", ] diff --git a/rslib/src/backend/error.rs b/rslib/src/backend/error.rs index 9e23c47ce..270a2f703 100644 --- a/rslib/src/backend/error.rs +++ b/rslib/src/backend/error.rs @@ -42,7 +42,7 @@ impl AnkiError { AnkiError::InvalidId => Kind::InvalidInput, AnkiError::InvalidMethodIndex | AnkiError::InvalidServiceIndex - | AnkiError::FsrsWeightsInvalid + | AnkiError::FsrsParamsInvalid | AnkiError::FsrsUnableToDetermineDesiredRetention | AnkiError::FsrsInsufficientData => Kind::InvalidInput, #[cfg(windows)] diff --git a/rslib/src/deckconfig/mod.rs b/rslib/src/deckconfig/mod.rs index ea299da7b..21a75f521 100644 --- a/rslib/src/deckconfig/mod.rs +++ b/rslib/src/deckconfig/mod.rs @@ -79,7 +79,7 @@ const DEFAULT_DECK_CONFIG_INNER: DeckConfigInner = DeckConfigInner { desired_retention: 0.9, other: Vec::new(), historical_retention: 0.9, - weight_search: String::new(), + param_search: String::new(), ignore_revlogs_before_date: String::new(), easy_days_percentages: Vec::new(), }; diff --git a/rslib/src/deckconfig/schema11.rs b/rslib/src/deckconfig/schema11.rs index bde3f2234..73800f38e 100644 --- a/rslib/src/deckconfig/schema11.rs +++ b/rslib/src/deckconfig/schema11.rs @@ -94,8 +94,8 @@ pub struct DeckConfSchema11 { #[serde(default)] /// historical retention sm2_retention: f32, - #[serde(default)] - weight_search: String, + #[serde(default, rename = "weightSearch")] + param_search: String, #[serde(flatten)] other: HashMap, @@ -312,7 +312,7 @@ impl Default for DeckConfSchema11 { fsrs_params_5: vec![], desired_retention: 0.9, sm2_retention: 0.9, - weight_search: "".to_string(), + param_search: "".to_string(), ignore_revlogs_before_date: "".to_string(), easy_days_percentages: vec![1.0; 7], } @@ -395,7 +395,7 @@ impl From for DeckConfig { easy_days_percentages: c.easy_days_percentages, desired_retention: c.desired_retention, historical_retention: c.sm2_retention, - weight_search: c.weight_search, + param_search: c.param_search, other: other_bytes, }, } @@ -506,7 +506,7 @@ impl From for DeckConfSchema11 { fsrs_params_5: i.fsrs_params_5, desired_retention: i.desired_retention, sm2_retention: i.historical_retention, - weight_search: i.weight_search, + param_search: i.param_search, ignore_revlogs_before_date: i.ignore_revlogs_before_date, easy_days_percentages: i.easy_days_percentages, } diff --git a/rslib/src/deckconfig/update.rs b/rslib/src/deckconfig/update.rs index e931dad4a..f56d0bf47 100644 --- a/rslib/src/deckconfig/update.rs +++ b/rslib/src/deckconfig/update.rs @@ -21,7 +21,7 @@ use crate::decks::NormalDeck; use crate::prelude::*; use crate::scheduler::fsrs::memory_state::UpdateMemoryStateEntry; use crate::scheduler::fsrs::memory_state::UpdateMemoryStateRequest; -use crate::scheduler::fsrs::weights::ignore_revlogs_before_ms_from_config; +use crate::scheduler::fsrs::params::ignore_revlogs_before_ms_from_config; use crate::search::JoinSearches; use crate::search::Negated; use crate::search::SearchNode; @@ -159,8 +159,8 @@ impl Collection { configs_after_update.remove(dcid); } - if req.mode == UpdateDeckConfigsMode::ComputeAllWeights { - self.compute_all_weights(&mut req)?; + if req.mode == UpdateDeckConfigsMode::ComputeAllParams { + self.compute_all_params(&mut req)?; } // add/update provided configs @@ -207,13 +207,13 @@ impl Collection { if let Ok(normal) = deck.normal() { let deck_id = deck.id; - // previous order & weights + // previous order & params let previous_config_id = DeckConfigId(normal.config_id); let previous_config = configs_before_update.get(&previous_config_id); let previous_order = previous_config .map(|c| c.inner.new_card_insert_order()) .unwrap_or_default(); - let previous_weights = previous_config.map(|c| c.fsrs_params()); + let previous_params = previous_config.map(|c| c.fsrs_params()); let previous_retention = previous_config.map(|c| c.inner.desired_retention); // if a selected (sub)deck, or its old config was removed, update deck to point @@ -239,11 +239,11 @@ impl Collection { self.sort_deck(deck_id, current_order, usn)?; } - // if weights differ, memory state needs to be recomputed - let current_weights = current_config.map(|c| c.fsrs_params()); + // if params differ, memory state needs to be recomputed + let current_params = current_config.map(|c| c.fsrs_params()); let current_retention = current_config.map(|c| c.inner.desired_retention); if fsrs_toggled - || previous_weights != current_weights + || previous_params != current_params || previous_retention != current_retention { decks_needing_memory_recompute @@ -261,10 +261,10 @@ impl Collection { .into_iter() .map(|(conf_id, search)| { let config = configs_after_update.get(&conf_id); - let weights = config.and_then(|c| { + let params = config.and_then(|c| { if req.fsrs { Some(UpdateMemoryStateRequest { - weights: c.fsrs_params().clone(), + params: c.fsrs_params().clone(), desired_retention: c.inner.desired_retention, max_interval: c.inner.maximum_review_interval, reschedule: req.fsrs_reschedule, @@ -275,7 +275,7 @@ impl Collection { } }); Ok(UpdateMemoryStateEntry { - req: weights, + req: params, search: SearchNode::DeckIdsWithoutChildren(comma_separated_ids(&search)), ignore_before: config .map(ignore_revlogs_before_ms_from_config) @@ -329,7 +329,7 @@ impl Collection { } Ok(()) } - fn compute_all_weights(&mut self, req: &mut UpdateDeckConfigsRequest) -> Result<()> { + fn compute_all_params(&mut self, req: &mut UpdateDeckConfigsRequest) -> Result<()> { require!(req.fsrs, "FSRS must be enabled"); // frontend didn't include any unmodified deck configs, so we need to fill them @@ -344,28 +344,28 @@ impl Collection { // other parts of the code expect the currently-selected preset to come last req.configs.push(previous_last); - // calculate and apply weights to each preset + // calculate and apply params to each preset let config_len = req.configs.len() as u32; for (idx, config) in req.configs.iter_mut().enumerate() { - let search = if config.inner.weight_search.trim().is_empty() { + let search = if config.inner.param_search.trim().is_empty() { SearchNode::Preset(config.name.clone()) .and(SearchNode::State(StateKind::Suspended).negated()) .try_into_search()? .to_string() } else { - config.inner.weight_search.clone() + config.inner.param_search.clone() }; let ignore_revlogs_before_ms = ignore_revlogs_before_ms_from_config(config)?; - match self.compute_weights( + match self.compute_params( &search, ignore_revlogs_before_ms, idx as u32 + 1, config_len, config.fsrs_params(), ) { - Ok(weights) => { - println!("{}: {:?}", config.name, weights.weights); - config.inner.fsrs_params_5 = weights.weights; + Ok(params) => { + println!("{}: {:?}", config.name, params.params); + config.inner.fsrs_params_5 = params.params; } Err(AnkiError::Interrupted) => return Err(AnkiError::Interrupted), Err(err) => { diff --git a/rslib/src/error/mod.rs b/rslib/src/error/mod.rs index 416690e8b..72ba05baf 100644 --- a/rslib/src/error/mod.rs +++ b/rslib/src/error/mod.rs @@ -113,7 +113,7 @@ pub enum AnkiError { }, InvalidMethodIndex, InvalidServiceIndex, - FsrsWeightsInvalid, + FsrsParamsInvalid, /// Returned by fsrs-rs; may happen even if 400+ reviews FsrsInsufficientData, /// Generated by our backend if count < 400 @@ -181,7 +181,7 @@ impl AnkiError { AnkiError::FsrsInsufficientReviews { count } => { tr.deck_config_must_have_400_reviews(*count).into() } - AnkiError::FsrsWeightsInvalid => tr.deck_config_invalid_parameters().into(), + AnkiError::FsrsParamsInvalid => tr.deck_config_invalid_parameters().into(), AnkiError::SchedulerUpgradeRequired => { tr.scheduling_update_required().replace("V2", "v3") } diff --git a/rslib/src/progress.rs b/rslib/src/progress.rs index c1412251f..a404808bf 100644 --- a/rslib/src/progress.rs +++ b/rslib/src/progress.rs @@ -15,8 +15,8 @@ use crate::import_export::ExportProgress; use crate::import_export::ImportProgress; use crate::prelude::Collection; use crate::scheduler::fsrs::memory_state::ComputeMemoryProgress; +use crate::scheduler::fsrs::params::ComputeParamsProgress; use crate::scheduler::fsrs::retention::ComputeRetentionProgress; -use crate::scheduler::fsrs::weights::ComputeWeightsProgress; use crate::sync::collection::normal::NormalSyncProgress; use crate::sync::collection::progress::FullSyncProgress; use crate::sync::collection::progress::SyncStage; @@ -131,7 +131,7 @@ pub enum Progress { DatabaseCheck(DatabaseCheckProgress), Import(ImportProgress), Export(ExportProgress), - ComputeWeights(ComputeWeightsProgress), + ComputeParams(ComputeParamsProgress), ComputeRetention(ComputeRetentionProgress), ComputeMemory(ComputeMemoryProgress), } @@ -209,8 +209,8 @@ pub(crate) fn progress_to_proto( } .into(), ), - Progress::ComputeWeights(progress) => { - Value::ComputeWeights(anki_proto::collection::ComputeWeightsProgress { + Progress::ComputeParams(progress) => { + Value::ComputeParams(anki_proto::collection::ComputeParamsProgress { current: progress.current_iteration, total: progress.total_iterations, reviews: progress.reviews, @@ -296,9 +296,9 @@ impl From for Progress { } } -impl From for Progress { - fn from(p: ComputeWeightsProgress) -> Self { - Progress::ComputeWeights(p) +impl From for Progress { + fn from(p: ComputeParamsProgress) -> Self { + Progress::ComputeParams(p) } } diff --git a/rslib/src/scheduler/answering/mod.rs b/rslib/src/scheduler/answering/mod.rs index 9458e7559..61ff13fbb 100644 --- a/rslib/src/scheduler/answering/mod.rs +++ b/rslib/src/scheduler/answering/mod.rs @@ -14,7 +14,7 @@ use rand::prelude::*; use rand::rngs::StdRng; use revlog::RevlogEntryPartial; -use super::fsrs::weights::ignore_revlogs_before_ms_from_config; +use super::fsrs::params::ignore_revlogs_before_ms_from_config; use super::queue::BuryMode; use super::states::load_balancer::LoadBalancerContext; use super::states::steps::LearningSteps; @@ -433,7 +433,7 @@ impl Collection { let fsrs_next_states = if fsrs_enabled { let fsrs = FSRS::new(Some(config.fsrs_params()))?; if card.memory_state.is_none() && card.ctype != CardType::New { - // Card has been moved or imported into an FSRS deck after weights were set, + // Card has been moved or imported into an FSRS deck after params were set, // and will need its initial memory state to be calculated based on review // history. let revlog = self.revlog_for_srs(SearchNode::CardIds(card.id.to_string()))?; diff --git a/rslib/src/scheduler/fsrs/error.rs b/rslib/src/scheduler/fsrs/error.rs index 5c9f030ee..d5b596a36 100644 --- a/rslib/src/scheduler/fsrs/error.rs +++ b/rslib/src/scheduler/fsrs/error.rs @@ -12,10 +12,10 @@ impl From for AnkiError { FSRSError::NotEnoughData => AnkiError::FsrsInsufficientData, FSRSError::OptimalNotFound => AnkiError::FsrsUnableToDetermineDesiredRetention, FSRSError::Interrupted => AnkiError::Interrupted, - FSRSError::InvalidParameters => AnkiError::FsrsWeightsInvalid, + FSRSError::InvalidParameters => AnkiError::FsrsParamsInvalid, FSRSError::InvalidInput => AnkiError::InvalidInput { source: InvalidInputError { - message: "invalid weights provided".to_string(), + message: "invalid params provided".to_string(), source: None, backtrace: None, }, diff --git a/rslib/src/scheduler/fsrs/memory_state.rs b/rslib/src/scheduler/fsrs/memory_state.rs index d6836986d..decc9777b 100644 --- a/rslib/src/scheduler/fsrs/memory_state.rs +++ b/rslib/src/scheduler/fsrs/memory_state.rs @@ -9,13 +9,13 @@ use fsrs::MemoryState; use fsrs::FSRS; use itertools::Itertools; -use super::weights::ignore_revlogs_before_ms_from_config; +use super::params::ignore_revlogs_before_ms_from_config; use crate::card::CardType; use crate::prelude::*; use crate::revlog::RevlogEntry; use crate::revlog::RevlogReviewKind; -use crate::scheduler::fsrs::weights::single_card_revlog_to_items; -use crate::scheduler::fsrs::weights::Weights; +use crate::scheduler::fsrs::params::single_card_revlog_to_items; +use crate::scheduler::fsrs::params::Params; use crate::scheduler::states::fuzz::with_review_fuzz; use crate::search::Negated; use crate::search::SearchNode; @@ -29,7 +29,7 @@ pub struct ComputeMemoryProgress { #[derive(Debug)] pub(crate) struct UpdateMemoryStateRequest { - pub weights: Weights, + pub params: Params, pub desired_retention: f32, pub historical_retention: f32, pub max_interval: u32, @@ -43,10 +43,10 @@ pub(crate) struct UpdateMemoryStateEntry { } impl Collection { - /// For each provided set of weights, locate cards with the provided search, + /// For each provided set of params, locate cards with the provided search, /// and update their memory state. /// Should be called inside a transaction. - /// If Weights are None, it means the user disabled FSRS, and the existing + /// If Params are None, it means the user disabled FSRS, and the existing /// memory state should be removed. pub(crate) fn update_memory_state( &mut self, @@ -69,7 +69,7 @@ impl Collection { } else { None }; - let fsrs = FSRS::new(req.as_ref().map(|w| &w.weights[..]).or(Some([].as_slice())))?; + let fsrs = FSRS::new(req.as_ref().map(|w| &w.params[..]).or(Some([].as_slice())))?; let historical_retention = req.as_ref().map(|w| w.historical_retention); let items = fsrs_items_for_memory_state( &fsrs, @@ -337,8 +337,8 @@ mod tests { use super::*; use crate::card::FsrsMemoryState; use crate::revlog::RevlogReviewKind; - use crate::scheduler::fsrs::weights::tests::convert; - use crate::scheduler::fsrs::weights::tests::revlog; + use crate::scheduler::fsrs::params::tests::convert; + use crate::scheduler::fsrs::params::tests::revlog; /// Floating point precision can vary between platforms, and each FSRS /// update tends to result in small changes to these numbers, so we diff --git a/rslib/src/scheduler/fsrs/mod.rs b/rslib/src/scheduler/fsrs/mod.rs index 8a0bd51fe..aa324dddb 100644 --- a/rslib/src/scheduler/fsrs/mod.rs +++ b/rslib/src/scheduler/fsrs/mod.rs @@ -2,7 +2,7 @@ // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html mod error; pub mod memory_state; +pub mod params; pub mod retention; pub mod simulator; pub mod try_collect; -pub mod weights; diff --git a/rslib/src/scheduler/fsrs/weights.rs b/rslib/src/scheduler/fsrs/params.rs similarity index 95% rename from rslib/src/scheduler/fsrs/weights.rs rename to rslib/src/scheduler/fsrs/params.rs index 0c370fbe0..1bedf4ffc 100644 --- a/rslib/src/scheduler/fsrs/weights.rs +++ b/rslib/src/scheduler/fsrs/params.rs @@ -7,7 +7,7 @@ use std::thread; use std::time::Duration; use anki_io::write_file; -use anki_proto::scheduler::ComputeFsrsWeightsResponse; +use anki_proto::scheduler::ComputeFsrsParamsResponse; use anki_proto::stats::revlog_entry; use anki_proto::stats::Dataset; use anki_proto::stats::DeckEntry; @@ -29,7 +29,7 @@ use crate::search::Node; use crate::search::SearchNode; use crate::search::SortMode; -pub(crate) type Weights = Vec; +pub(crate) type Params = Vec; fn ignore_revlogs_before_date_to_ms( ignore_revlogs_before_date: &String, @@ -53,15 +53,15 @@ impl Collection { /// Note this does not return an error if there are less than 400 items - /// the caller should instead check the fsrs_items count in the return /// value. - pub fn compute_weights( + pub fn compute_params( &mut self, search: &str, ignore_revlogs_before: TimestampMillis, current_preset: u32, total_presets: u32, - current_weights: &Weights, - ) -> Result { - let mut anki_progress = self.new_progress_handler::(); + current_params: &Params, + ) -> Result { + let mut anki_progress = self.new_progress_handler::(); let timing = self.timing_today()?; let revlogs = self.revlog_for_srs(search)?; let (items, review_count) = @@ -69,8 +69,8 @@ impl Collection { let fsrs_items = items.len() as u32; if fsrs_items == 0 { - return Ok(ComputeFsrsWeightsResponse { - weights: current_weights.to_vec(), + return Ok(ComputeFsrsParamsResponse { + params: current_params.to_vec(), fsrs_items, }); } @@ -97,20 +97,17 @@ impl Collection { } } }); - let mut weights = FSRS::new(None)?.compute_parameters(items.clone(), Some(progress2))?; - if let Ok(fsrs) = FSRS::new(Some(current_weights)) { + let mut params = FSRS::new(None)?.compute_parameters(items.clone(), Some(progress2))?; + if let Ok(fsrs) = FSRS::new(Some(current_params)) { let current_rmse = fsrs.evaluate(items.clone(), |_| true)?.rmse_bins; - let optimized_fsrs = FSRS::new(Some(&weights))?; + let optimized_fsrs = FSRS::new(Some(¶ms))?; let optimized_rmse = optimized_fsrs.evaluate(items.clone(), |_| true)?.rmse_bins; if current_rmse <= optimized_rmse { - weights = current_weights.to_vec(); + params = current_params.to_vec(); } } - Ok(ComputeFsrsWeightsResponse { - weights, - fsrs_items, - }) + Ok(ComputeFsrsParamsResponse { params, fsrs_items }) } pub(crate) fn revlog_for_srs( @@ -180,14 +177,14 @@ impl Collection { Ok(()) } - pub fn evaluate_weights( + pub fn evaluate_params( &mut self, - weights: &Weights, + params: &Params, search: &str, ignore_revlogs_before: TimestampMillis, ) -> Result { let timing = self.timing_today()?; - let mut anki_progress = self.new_progress_handler::(); + let mut anki_progress = self.new_progress_handler::(); let guard = self.search_cards_into_table(search, SortMode::NoOrder)?; let revlogs: Vec = guard .col @@ -196,7 +193,7 @@ impl Collection { let (items, review_count) = fsrs_items_for_training(revlogs, timing.next_day_at, ignore_revlogs_before); anki_progress.state.reviews = review_count as u32; - let fsrs = FSRS::new(Some(weights))?; + let fsrs = FSRS::new(Some(params))?; Ok(fsrs.evaluate(items, |ip| { anki_progress .update(false, |p| { @@ -209,13 +206,13 @@ impl Collection { } #[derive(Default, Clone, Copy, Debug)] -pub struct ComputeWeightsProgress { +pub struct ComputeParamsProgress { pub current_iteration: u32, pub total_iterations: u32, pub reviews: u32, - /// Only used in 'compute all weights' case + /// Only used in 'compute all params' case pub current_preset: u32, - /// Only used in 'compute all weights' case + /// Only used in 'compute all params' case pub total_presets: u32, } diff --git a/rslib/src/scheduler/fsrs/retention.rs b/rslib/src/scheduler/fsrs/retention.rs index f2951f2dc..a408b6013 100644 --- a/rslib/src/scheduler/fsrs/retention.rs +++ b/rslib/src/scheduler/fsrs/retention.rs @@ -54,7 +54,7 @@ impl Collection { learn_limit, review_limit: usize::MAX, }, - &req.weights, + &req.params, |ip| { anki_progress .update(false, |p| { diff --git a/rslib/src/scheduler/fsrs/simulator.rs b/rslib/src/scheduler/fsrs/simulator.rs index 9b1c0d072..70a6d9001 100644 --- a/rslib/src/scheduler/fsrs/simulator.rs +++ b/rslib/src/scheduler/fsrs/simulator.rs @@ -54,7 +54,7 @@ impl Collection { daily_time_cost, ) = simulate( &config, - &req.weights, + &req.params, req.desired_retention, None, Some(converted_cards), diff --git a/rslib/src/scheduler/service/mod.rs b/rslib/src/scheduler/service/mod.rs index aa71d4829..59a9aa503 100644 --- a/rslib/src/scheduler/service/mod.rs +++ b/rslib/src/scheduler/service/mod.rs @@ -7,7 +7,7 @@ mod states; use anki_proto::cards; use anki_proto::generic; use anki_proto::scheduler; -use anki_proto::scheduler::ComputeFsrsWeightsResponse; +use anki_proto::scheduler::ComputeFsrsParamsResponse; use anki_proto::scheduler::ComputeMemoryStateResponse; use anki_proto::scheduler::ComputeOptimalRetentionRequest; use anki_proto::scheduler::ComputeOptimalRetentionResponse; @@ -254,16 +254,16 @@ impl crate::services::SchedulerService for Collection { self.custom_study_defaults(input.deck_id.into()) } - fn compute_fsrs_weights( + fn compute_fsrs_params( &mut self, - input: scheduler::ComputeFsrsWeightsRequest, - ) -> Result { - self.compute_weights( + input: scheduler::ComputeFsrsParamsRequest, + ) -> Result { + self.compute_params( &input.search, input.ignore_revlogs_before_ms.into(), 1, 1, - &input.current_weights, + &input.current_params, ) } @@ -283,16 +283,16 @@ impl crate::services::SchedulerService for Collection { }) } - fn evaluate_weights( + fn evaluate_params( &mut self, - input: scheduler::EvaluateWeightsRequest, - ) -> Result { - let ret = self.evaluate_weights( - &input.weights, + input: scheduler::EvaluateParamsRequest, + ) -> Result { + let ret = self.evaluate_params( + &input.params, &input.search, input.ignore_revlogs_before_ms.into(), )?; - Ok(scheduler::EvaluateWeightsResponse { + Ok(scheduler::EvaluateParamsResponse { log_loss: ret.log_loss, rmse_bins: ret.rmse_bins, }) @@ -339,20 +339,17 @@ impl crate::services::SchedulerService for Collection { } impl crate::services::BackendSchedulerService for Backend { - fn compute_fsrs_weights_from_items( + fn compute_fsrs_params_from_items( &self, - req: scheduler::ComputeFsrsWeightsFromItemsRequest, - ) -> Result { + req: scheduler::ComputeFsrsParamsFromItemsRequest, + ) -> Result { let fsrs = FSRS::new(None)?; let fsrs_items = req.items.len() as u32; - let weights = fsrs.compute_parameters( + let params = fsrs.compute_parameters( req.items.into_iter().map(fsrs_item_proto_to_fsrs).collect(), None, )?; - Ok(ComputeFsrsWeightsResponse { - weights, - fsrs_items, - }) + Ok(ComputeFsrsParamsResponse { params, fsrs_items }) } fn fsrs_benchmark( @@ -365,8 +362,8 @@ impl crate::services::BackendSchedulerService for Backend { .into_iter() .map(fsrs_item_proto_to_fsrs) .collect(); - let weights = fsrs.benchmark(train_set); - Ok(FsrsBenchmarkResponse { weights }) + let params = fsrs.benchmark(train_set); + Ok(FsrsBenchmarkResponse { params }) } fn export_dataset(&self, req: scheduler::ExportDatasetRequest) -> Result<()> { diff --git a/rslib/src/scheduler/states/load_balancer.rs b/rslib/src/scheduler/states/load_balancer.rs index 5ba2103e1..6cd59d538 100644 --- a/rslib/src/scheduler/states/load_balancer.rs +++ b/rslib/src/scheduler/states/load_balancer.rs @@ -226,8 +226,8 @@ impl LoadBalancer { .collect::>(); let expected_distribution = check_review_distribution(&review_counts, &percentages); - // calculate weights for each day - let intervals_and_weights = interval_days + // calculate params for each day + let intervals_and_params = interval_days .iter() .enumerate() .map(|(interval_index, interval_day)| { @@ -262,10 +262,10 @@ impl LoadBalancer { let mut rng = StdRng::seed_from_u64(fuzz_seed?); let weighted_intervals = - WeightedIndex::new(intervals_and_weights.iter().map(|k| k.1)).ok()?; + WeightedIndex::new(intervals_and_params.iter().map(|k| k.1)).ok()?; let selected_interval_index = weighted_intervals.sample(&mut rng); - Some(intervals_and_weights[selected_interval_index].0) + Some(intervals_and_params[selected_interval_index].0) } pub fn add_card(&mut self, cid: CardId, nid: NoteId, dcid: DeckConfigId, interval: u32) { diff --git a/rslib/src/stats/card.rs b/rslib/src/stats/card.rs index ad713c813..1b2b1d376 100644 --- a/rslib/src/stats/card.rs +++ b/rslib/src/stats/card.rs @@ -7,7 +7,7 @@ use crate::card::CardType; use crate::prelude::*; use crate::revlog::RevlogEntry; use crate::scheduler::fsrs::memory_state::single_card_revlog_to_item; -use crate::scheduler::fsrs::weights::ignore_revlogs_before_ms_from_config; +use crate::scheduler::fsrs::params::ignore_revlogs_before_ms_from_config; use crate::scheduler::timing::is_unix_epoch_timestamp; impl Collection { diff --git a/ts/routes/deck-options/FsrsOptions.svelte b/ts/routes/deck-options/FsrsOptions.svelte index aa4d0aae6..42a5e891d 100644 --- a/ts/routes/deck-options/FsrsOptions.svelte +++ b/ts/routes/deck-options/FsrsOptions.svelte @@ -5,7 +5,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html