Skip to content

Commit

Permalink
Fix/fit power forgetting curve in analysis (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
L-M-Sherlock committed Apr 7, 2024
1 parent e81789e commit a7504d0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "FSRS-Optimizer"
version = "4.27.3"
version = "4.27.4"
readme = "README.md"
dependencies = [
"matplotlib>=3.7.0",
Expand Down
22 changes: 10 additions & 12 deletions src/fsrs_optimizer/fsrs_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from torch.nn.utils.rnn import pad_sequence
from sklearn.model_selection import TimeSeriesSplit
from sklearn.metrics import root_mean_squared_error, mean_absolute_error, r2_score
from scipy.optimize import minimize
from scipy.optimize import minimize, curve_fit
from itertools import accumulate
from tqdm.auto import tqdm
import warnings
Expand Down Expand Up @@ -709,15 +709,15 @@ def cal_stability(group: pd.DataFrame) -> pd.DataFrame:
return pd.DataFrame()
group["group_cnt"] = group_cnt
if group["i"].values[0] > 1:
r_ivl_cnt = sum(
group["delta_t"]
* group["retention"].map(np.log)
* pow(group["total_cnt"], 2)
group["stability"] = round(
curve_fit(
power_forgetting_curve,
group["delta_t"],
group["retention"],
sigma=1 / group["total_cnt"],
)[0][0],
1,
)
ivl_ivl_cnt = sum(
group["delta_t"].map(lambda x: x**2) * pow(group["total_cnt"], 2)
)
group["stability"] = round(np.log(0.9) / (r_ivl_cnt / ivl_ivl_cnt), 1)
else:
group["stability"] = 0.0
group["avg_retention"] = round(
Expand Down Expand Up @@ -1011,9 +1011,7 @@ def train(
w.append(trainer.train(verbose=verbose))
self.w = w[-1]
self.evaluate()
metrics, figures = self.calibration_graph(
self.dataset.iloc[test_index]
)
metrics, figures = self.calibration_graph(self.dataset.iloc[test_index])
for j, f in enumerate(figures):
f.savefig(f"graph_{j}_test_{i}.png")
plt.close(f)
Expand Down

0 comments on commit a7504d0

Please sign in to comment.