Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop using math.exp and math.pow #78

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions fsrs/fsrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ def _initial_stability(self, rating: Rating) -> float:

def _initial_difficulty(self, rating: Rating) -> float:
initial_difficulty = (
self.parameters[4] - math.exp(self.parameters[5] * (rating - 1)) + 1
self.parameters[4] - (math.e ** (self.parameters[5] * (rating - 1))) + 1
)

# bound initial_difficulty between 1 and 10
Expand All @@ -683,8 +683,8 @@ def _next_interval(self, stability: float) -> int:
return next_interval

def _short_term_stability(self, stability: float, rating: Rating) -> float:
return stability * math.exp(
self.parameters[17] * (rating - 3 + self.parameters[18])
return stability * (
math.e ** (self.parameters[17] * (rating - 3 + self.parameters[18]))
)

def _next_difficulty(self, difficulty: float, rating: Rating) -> float:
Expand Down Expand Up @@ -733,13 +733,13 @@ def _next_forget_stability(
) -> float:
next_forget_stability_long_term_params = (
self.parameters[11]
* math.pow(difficulty, -self.parameters[12])
* (math.pow(stability + 1, self.parameters[13]) - 1)
* math.exp((1 - retrievability) * self.parameters[14])
* (difficulty ** -self.parameters[12])
* (((stability + 1) ** (self.parameters[13])) - 1)
* (math.e ** ((1 - retrievability) * self.parameters[14]))
)

next_forget_stability_short_term_params = stability / math.exp(
self.parameters[17] * self.parameters[18]
next_forget_stability_short_term_params = stability / (
math.e ** (self.parameters[17] * self.parameters[18])
)

return min(
Expand All @@ -755,10 +755,10 @@ def _next_recall_stability(

return stability * (
1
+ math.exp(self.parameters[8])
+ (math.e ** (self.parameters[8]))
* (11 - difficulty)
* math.pow(stability, -self.parameters[9])
* (math.exp((1 - retrievability) * self.parameters[10]) - 1)
* (stability ** -self.parameters[9])
* ((math.e ** ((1 - retrievability) * self.parameters[10])) - 1)
* hard_penalty
* easy_bonus
)
Expand Down
Loading