Skip to content

Commit

Permalink
Fix/fallback to 1 when weights doesn't exist & create "tensor" if it …
Browse files Browse the repository at this point in the history
…doesn't exist (#159)
  • Loading branch information
L-M-Sherlock authored Jan 9, 2025
1 parent 24dfb16 commit df93cfe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
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 = "5.6.4"
version = "5.6.5"
readme = "README.md"
dependencies = [
"matplotlib>=3.7.0",
Expand Down
9 changes: 9 additions & 0 deletions src/fsrs_optimizer/fsrs_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1541,6 +1541,13 @@ def moving_average(data, window_size=365 // 20):

def evaluate(self, save_to_file=True):
my_collection = Collection(DEFAULT_PARAMETER, self.float_delta_t)
if "tensor" not in self.dataset.columns:
self.dataset["tensor"] = self.dataset.progress_apply(
lambda x: lineToTensor(
list(zip([x["t_history"]], [x["r_history"]]))[0]
),
axis=1,
)
stabilities, difficulties = my_collection.batch_predict(self.dataset)
self.dataset["stability"] = stabilities
self.dataset["difficulty"] = difficulties
Expand All @@ -1551,6 +1558,8 @@ def evaluate(self, save_to_file=True):
lambda row: -np.log(row["p"]) if row["y"] == 1 else -np.log(1 - row["p"]),
axis=1,
)
if "weights" not in self.dataset.columns:
self.dataset["weights"] = 1
self.dataset["log_loss"] = (
self.dataset["log_loss"]
* self.dataset["weights"]
Expand Down

0 comments on commit df93cfe

Please sign in to comment.