Skip to content
Open
Show file tree
Hide file tree
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
10 changes: 5 additions & 5 deletions app/docs/user.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ Note that this function is designed to handle comparisons of mathematical expres

### Optional parameters

There are 15 optional parameters that can be set: `atol`, `complexNumbers`, `convention`, `criteria`, `elementary_functions`, `feedback_for_incorrect_response`, `multiple_answers_criteria`, `physical_quantity`, `plus_minus`/`minus_plus`, `rtol`, `specialFunctions`, `strict_syntax`, `strictness`, `symbol_assumptions`.
There are 15 optional parameters that can be set: `absolute_tolerance`, `complexNumbers`, `convention`, `criteria`, `elementary_functions`, `feedback_for_incorrect_response`, `multiple_answers_criteria`, `physical_quantity`, `plus_minus`/`minus_plus`, `rtol`, `specialFunctions`, `strict_syntax`, `strictness`, `symbol_assumptions`.

#### `atol`
Sets the absolute tolerance, $e_a$, i.e. if the answer, $x$, and response, $\tilde{x}$, are numerical values then the response is considered equal to the answer if $|x-\tilde{x}| \leq e_aBy default `atol` is set to `0`, which means the comparison will be done with as high accuracy as possible. If either the answer or the response aren't numerical expressions this parameter is ignored.
#### `absolute_tolerance` (`atol`)
Sets the absolute tolerance, $e_a$, i.e. if the answer, $x$, and response, $\tilde{x}$, are numerical values then the response is considered equal to the answer if $|x-\tilde{x}| \leq e_aBy default `absolute_tolerance` is set to `0`, which means the comparison will be done with as high accuracy as possible. If either the answer or the response aren't numerical expressions this parameter is ignored.

#### `complexNumbers`

Expand Down Expand Up @@ -77,8 +77,8 @@ When `physical_quantity` the evaluation function will generate feedback based on

**TODO:** Generate new flowchart for updated physical quantity feedback generation procedure.

#### `rtol`
Sets the relative tolerance, $e_r$, i.e. if the answer, $x$, and response, $\tilde{x}$, are numerical values then the response is considered equal to the answer if $\left|\frac{x-\tilde{x}}{x}\right| \leq e_r$. By default `rtol` is set to `0`, which means the comparison will be done with as high accuracy as possible. If either the answer or the response aren't numerical expressions this parameter is ignored.
#### `relative_tolerance` (`rtol`)
Sets the relative tolerance, $e_r$, i.e. if the answer, $x$, and response, $\tilde{x}$, are numerical values then the response is considered equal to the answer if $\left|\frac{x-\tilde{x}}{x}\right| \leq e_r$. By default `relative_tolerance` is set to `0`, which means the comparison will be done with as high accuracy as possible. If either the answer or the response aren't numerical expressions this parameter is ignored.

#### `strictness`

Expand Down
7 changes: 6 additions & 1 deletion app/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,12 @@ def evaluation_function(response, answer, params, include_test_data=False) -> di
- if set to True, use basic dimensional analysis functionality.
"""

if "relative_tolerance" in params:
params["rtol"] = params["relative_tolerance"]

if "absolute_tolerance" in params:
params["atol"] = params["absolute_tolerance"]

evaluation_result = EvaluationResult()
evaluation_result.is_correct = False

Expand Down Expand Up @@ -318,7 +324,6 @@ def evaluation_function(response, answer, params, include_test_data=False) -> di
"reserved_expressions": reserved_expressions_parsed,
"criteria": criteria,
"disabled_evaluation_nodes": parameters.get("disabled_evaluation_nodes", set()),
"evaluation_result": evaluation_result,
"parsing_parameters": parsing_parameters,
"evaluation_result": evaluation_result,
"syntactical_comparison": parameters.get("syntactical_comparison", False),
Expand Down
Empty file added app/tests/__init__.py
Empty file.
24 changes: 24 additions & 0 deletions app/tests/physical_quantity_evaluation_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,18 @@ def test_physical_quantity_with_rtol(self):
result = evaluation_function(res, ans, params, include_test_data=True)
assert result["is_correct"] is True

def test_physical_quantity_with_rel_tol(self):
ans = "7500 m/s"
res = "7504.1 m/s"
params = {
'relative_tolerance': 0.05,
'strict_syntax': False,
'physical_quantity': True,
'elementary_functions': True,
}
result = evaluation_function(res, ans, params, include_test_data=True)
assert result["is_correct"] is True

def test_physical_quantity_with_atol(self):
ans = "7500 m/s"
res = "7504.1 m/s"
Expand All @@ -349,6 +361,18 @@ def test_physical_quantity_with_atol(self):
result = evaluation_function(res, ans, params, include_test_data=True)
assert result["is_correct"] is True

def test_physical_quantity_with_abs_tol(self):
ans = "7500 m/s"
res = "7504.1 m/s"
params = {
'absolute_tolerance': 5,
'strict_syntax': False,
'physical_quantity': True,
'elementary_functions': True,
}
result = evaluation_function(res, ans, params, include_test_data=True)
assert result["is_correct"] is True

def test_tolerance_given_as_string(self):
ans = "4.52 kg"
res = "13.74 kg"
Expand Down
13 changes: 13 additions & 0 deletions app/tests/symbolic_evaluation_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,19 @@ def test_pi_with_rtol(self):
result = evaluation_function(response, answer, params)
assert result["is_correct"] is True

def test_pi_with_rel_tol(self):
answer = "pi"
response = "3.14"
params = {
"strict_syntax": False,
"relative_tolerance": 0.05,
"symbols": {
"pi": {"aliases": ["Pi", "PI", "π"], "latex": "\\(\\pi\\)"},
}
}
result = evaluation_function(response, answer, params)
assert result["is_correct"] is True

@pytest.mark.parametrize(
"response,outcome",
[
Expand Down