Created
April 11, 2020 15:03
-
-
Save yesview/cad8a3f44b0e68535d3fd266f2eca533 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import json | |
def generate_test_result(is_healthy): | |
result = random.randrange(0, 10) | |
if result <= 7: | |
return is_healthy | |
return not is_healthy | |
# Don't mind this function, it's just for test random | |
def test_general_probability(iterations): | |
res_dict = { | |
True: 0, | |
False: 0 | |
} | |
for i in range(iterations): | |
res = generate_test_result(True) | |
res_dict[res] += 1 | |
return res_dict | |
# print(test_general_probability(1000000)) | |
def test_virus_probability(iterations): | |
# First both are healthy | |
healthy_res = {True: 0, False: 0} | |
healthy_match = 0 | |
for i in range(iterations): | |
david_res = generate_test_result(0) | |
lamara_res = generate_test_result(0) | |
if david_res == lamara_res: | |
healthy_match += 1 | |
healthy_res[david_res == 0] += 1 | |
# First both are unhealthy | |
unhealthy_res = {True: 0, False: 0} | |
unhealthy_match = 0 | |
for i in range(iterations): | |
david_res = generate_test_result(1) | |
lamara_res = generate_test_result(1) | |
if david_res == lamara_res: | |
unhealthy_match += 1 | |
unhealthy_res[david_res == 1] += 1 | |
return json.dumps({ | |
"healthy": { | |
"correct": healthy_res[True], | |
"incorrect": healthy_res[False], | |
"matching_tests": healthy_match, | |
"correct_probability": healthy_res[True]/healthy_match, | |
}, | |
"unhealthy": { | |
"correct": unhealthy_res[True], | |
"incorrect": unhealthy_res[False], | |
"matching_tests": unhealthy_match, | |
"correct_probability": unhealthy_res[True]/unhealthy_match, | |
} | |
}) | |
print(test_virus_probability(1000000)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment