Skip to content
Snippets Groups Projects
Commit 2b60cdd5 authored by Robert Lanzafame's avatar Robert Lanzafame
Browse files

Merge branch 'exercise-checking' into 'main'

Exercise checking

See merge request !53
parents c015c60b ad90d535
No related branches found
No related tags found
2 merge requests!80check toc purge,!53Exercise checking
Pipeline #206484 passed
......@@ -10,15 +10,16 @@ check_float = lambda a, b: isclose(a, b, rel_tol=0, abs_tol=tolerance)
@check
def check_example(glob):
mu, beta = glob["mu"], glob["beta"]
if (check_float(mu, -3.21953) and check_float(beta, -8.65617)):
print(f"You got the parameters right (Part 1), well done! (checked with tolerance {tolerance})")
if (check_float(mu, -1.7461520011511888) and check_float(beta, 2.553428469837263)):
print(f"Part 1: you got the parameters right, well done! (checked with tolerance {tolerance})")
else:
print(f"Your parameters (Part 1) are incorrect, your inverse (Part 2) won't be graded until these are right. (checked with tolerance {tolerance})")
print(f"Part 1: your parameters are incorrect. (checked with tolerance {tolerance})")
print(f" Other parts won't be graded until these are fixed. ")
return
function = glob["find_x_with_probability_p"]
test_inputs = [(0.001, 13.50977500432694), (0.2, 0.8998147005530068), (0.9, -22.699089535951632)]
test_inputs = [(1 - 0.001, 15.891029744351862), (1 - 0.2, 2.0838374640878863), (1 - 0.9, -3.875794191615308)]
failed = []
for x, out in test_inputs:
......@@ -27,23 +28,34 @@ def check_example(glob):
failed.append((x, out, result))
if len(failed) == 0:
print(f"Well done, your inverse function is correct! (checked with tolerance {tolerance})")
print(f"Part 2: Well done, your inverse function is correct! (checked with tolerance {tolerance})")
else:
print(f"Your function (Part 2) failed some tests. Keep in mind the tolerance is {tolerance}")
print("Failed inputs:")
print(f"Part 2: Your function failed some tests. Keep in mind the tolerance is {tolerance}")
print(" --> Failed inputs:")
for case in failed:
print(f"{case[0]} gave {case[2]}, expected {case[1]}")
print(f" Other parts won't be graded until these are fixed.")
x = glob["x"]
if check_float(x, 15.891029744351862):
print(f"Part 3: you got the value of x right, well done! (checked with tolerance {tolerance})")
else:
print(f"Part 3: your value of x is incorrect. (checked with tolerance {tolerance})")
return
"""
Task 0:
x_1 = 4
p_e_1 = 1-.9
p_e_1 = .1
x_2 = 10
p_e_2 = 1-.99
p_e_2 = .01
Task 1:
beta = -(x_2 - x_1) / log(log(p_e_2) / log(p_e_1))
mu = x_1 + beta * log(-log(p_e_1))
beta = -(x_2 - x_1) / log(log(p_2) / log(p_1))
mu = x_1 + beta * log(-log(p_1))
Task 2:
x = mu - beta * log(-log(p))
Task 3:
x = find_x_with_probability_p(1 - 0.001)
"""
\ No newline at end of file
This diff is collapsed.
......@@ -4,7 +4,7 @@ from IPython.display import display
def check(f):
def wrapper(*args, **kwargs):
output = widgets.Output()
button = widgets.Button(description="Check answer")
button = widgets.Button(description="Check Answer(s)")
@output.capture(clear_output=True,wait=True)
def _inner_check(button):
try:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment