Skip to content

IsSimilar

Edit on GitHub View Code


Supported Response Area Types

This evaluation function is supported by the following Response Area components:

  • NUMBER
  • TEXT

Use this evaluation function to check if a student's response is within a tolerance range of the correct answer. Works like the numpy.isclose function.

A response is accepted if:

|response - answer| ≤ atol + rtol × |answer|

The left-hand side is the absolute difference between the student's response and the correct answer. The right-hand side is the total allowed difference, made up of a fixed part (atol) and a part that scales with the size of the answer (rtol × |answer|). A response is marked correct whenever the actual difference does not exceed the allowed difference.

Parameters

Both parameters default to 0 (exact match required) and can be used individually or together.

atol — Absolute tolerance

Specifies a fixed margin around the answer, regardless of its magnitude. Use this when you know the acceptable error in the same units as the answer.

rtol — Relative tolerance

Specifies an acceptable error as a fraction of the answer's magnitude. Use this when the answer is very large or very small and a percentage-based margin makes more sense than a fixed one.

Examples

Exact match (default)

No params needed. The student must enter exactly 42 (floating-point precision is handled automatically).

Absolute tolerance

{ "atol": 0.05 }

With answer 9.81, accepts any response in the range 9.76 – 9.86. Good for physical measurements where the acceptable error is known in the same units.

Relative tolerance

{ "rtol": 0.01 }

With answer 6.674e-11, accepts any response within 1% of the answer. Good for very large or very small values where a fixed margin would be impractical.

Combined tolerances

{ "atol": 0.01, "rtol": 0.005 }

Both tolerances contribute: with answer 9.81, the allowed difference is 0.01 + 0.005 × 9.81 ≈ 0.059. Useful when you want a minimum floor (atol) plus a proportional allowance (rtol).

Notes

Note: If the answer is not a number, all responses will generate an error.

Note: If the response is not a number, a feedback message asking the student to submit a number will be returned.