mirror of
https://github.com/open-thought/reasoning-gym.git
synced 2026-04-27 17:23:19 +00:00
Apply pre-commit fixes
This commit is contained in:
parent
f93c00a16b
commit
e2ce20bcbb
1 changed files with 7 additions and 7 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
import cmath
|
import cmath
|
||||||
import random
|
|
||||||
import math
|
import math
|
||||||
|
import random
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Optional, Tuple
|
from typing import Optional, Tuple
|
||||||
|
|
||||||
|
|
@ -89,7 +89,7 @@ class ComplexArithmeticDataset(ProceduralDataset):
|
||||||
"result": (result.real, result.imag),
|
"result": (result.real, result.imag),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_string_to_complex(answer: str) -> complex:
|
def parse_string_to_complex(answer: str) -> complex:
|
||||||
try:
|
try:
|
||||||
|
|
@ -97,7 +97,7 @@ class ComplexArithmeticDataset(ProceduralDataset):
|
||||||
answer = answer.replace(" ", "").lower()
|
answer = answer.replace(" ", "").lower()
|
||||||
# Convert mathematical notation 'i' to Python's 'j' for complex numbers
|
# Convert mathematical notation 'i' to Python's 'j' for complex numbers
|
||||||
answer = answer.replace("i", "j")
|
answer = answer.replace("i", "j")
|
||||||
|
|
||||||
# Handle real numbers (no imaginary part)
|
# Handle real numbers (no imaginary part)
|
||||||
if "j" not in answer:
|
if "j" not in answer:
|
||||||
student_result = complex(float(answer))
|
student_result = complex(float(answer))
|
||||||
|
|
@ -110,19 +110,19 @@ class ComplexArithmeticDataset(ProceduralDataset):
|
||||||
elif answer[-1] == "j" and not any(c in answer[:-1] for c in "+-"):
|
elif answer[-1] == "j" and not any(c in answer[:-1] for c in "+-"):
|
||||||
# Convert "3j" to "3+1j"
|
# Convert "3j" to "3+1j"
|
||||||
answer = answer.replace("j", "+1j")
|
answer = answer.replace("j", "+1j")
|
||||||
|
|
||||||
# Ensure the string has an imaginary part, even if zero
|
# Ensure the string has an imaginary part, even if zero
|
||||||
if "j" not in answer:
|
if "j" not in answer:
|
||||||
answer += "+0j"
|
answer += "+0j"
|
||||||
|
|
||||||
# Parse the normalized string into a complex number
|
# Parse the normalized string into a complex number
|
||||||
student_result = complex(answer)
|
student_result = complex(answer)
|
||||||
|
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return student_result
|
return student_result
|
||||||
|
|
||||||
def score_answer(self, answer: str, metadata: dict) -> float:
|
def score_answer(self, answer: str, metadata: dict) -> float:
|
||||||
"""Score the answer using exponential distance-based scoring."""
|
"""Score the answer using exponential distance-based scoring."""
|
||||||
if answer is None:
|
if answer is None:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue