Skip to content

Commit

Permalink
Replace "weight" with "parameter".py (#113)
Browse files Browse the repository at this point in the history
* Update fsrs_optimizer.py

* Update simulator_test.py
  • Loading branch information
Expertium authored May 22, 2024
1 parent e8b71f1 commit 91b9fc7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions src/fsrs_optimizer/fsrs_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
Review = 2
Relearning = 3

DEFAULT_WEIGHT = [
DEFAULT_PARAMETER = [
0.4872,
1.4003,
3.7145,
Expand Down Expand Up @@ -145,7 +145,7 @@ def mean_reversion(self, init: Tensor, current: Tensor) -> Tensor:
return self.w[7] * init + (1 - self.w[7]) * current


class WeightClipper:
class ParameterClipper:
def __init__(self, frequency: int = 1):
self.frequency = frequency

Expand Down Expand Up @@ -255,7 +255,7 @@ def __init__(
) -> None:
self.model = FSRS(init_w)
self.optimizer = torch.optim.Adam(self.model.parameters(), lr=lr)
self.clipper = WeightClipper()
self.clipper = ParameterClipper()
self.batch_size = batch_size
self.build_dataset(train_set, test_set)
self.n_epoch = n_epoch
Expand Down Expand Up @@ -804,7 +804,7 @@ def cal_stability(group: pd.DataFrame) -> pd.DataFrame:

def define_model(self):
"""Step 3"""
self.init_w = DEFAULT_WEIGHT.copy()
self.init_w = DEFAULT_PARAMETER.copy()
"""
For details about the parameters, please see:
https://github.com/open-spaced-repetition/fsrs4anki/wiki/The-Algorithm
Expand All @@ -831,7 +831,7 @@ def pretrain(self, dataset=None, verbose=True):
rating_count = {}
average_recall = self.dataset["y"].mean()
plots = []
r_s0_default = {str(i): DEFAULT_WEIGHT[i - 1] for i in range(1, 5)}
r_s0_default = {str(i): DEFAULT_PARAMETER[i - 1] for i in range(1, 5)}

for first_rating in ("1", "2", "3", "4"):
group = self.S0_dataset_group[
Expand Down Expand Up @@ -1322,7 +1322,7 @@ def moving_average(data, window_size=365 // 20):
return (fig1, fig2, fig3, fig4, fig5, fig6)

def evaluate(self, save_to_file=True):
my_collection = Collection(DEFAULT_WEIGHT)
my_collection = Collection(DEFAULT_PARAMETER)
stabilities, difficulties = my_collection.batch_predict(self.dataset)
self.dataset["stability"] = stabilities
self.dataset["difficulty"] = difficulties
Expand Down Expand Up @@ -1853,7 +1853,7 @@ def rmse_matrix(df):


if __name__ == "__main__":
model = FSRS(DEFAULT_WEIGHT)
model = FSRS(DEFAULT_PARAMETER)
stability = torch.tensor([5.0] * 4)
difficulty = torch.tensor([1.0, 2.0, 3.0, 4.0])
retention = torch.tensor([0.9, 0.8, 0.7, 0.6])
Expand Down
4 changes: 2 additions & 2 deletions tests/simulator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
class Test_Simulator:
def test_simulate(self):
(_, _, _, memorized_cnt_per_day, _) = simulate(
w=DEFAULT_WEIGHT, forget_cost=125
w=DEFAULT_PARAMETER, forget_cost=125
)
assert memorized_cnt_per_day[-1] == 3145.3779679589484

def test_optimal_retention(self):
default_params = {
"w": DEFAULT_WEIGHT,
"w": DEFAULT_PARAMETER,
"deck_size": 10000,
"learn_span": 1000,
"max_cost_perday": math.inf,
Expand Down

0 comments on commit 91b9fc7

Please sign in to comment.