Skip to content

Instantly share code, notes, and snippets.

@johnhw
Created August 23, 2023 07:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnhw/47c096d05e4534cf9ebeb9afd36ea53e to your computer and use it in GitHub Desktop.
Save johnhw/47c096d05e4534cf9ebeb9afd36ea53e to your computer and use it in GitHub Desktop.
import math
def itr(n, q, v, t):
# Calculate the probability of each choice being selected (assuming equally likely)
p_choice = 1 / q
# Calculate the entropy for each question's choices
entropy_per_question = -p_choice * math.log2(p_choice) * q
# Calculate the total entropy across all questions
total_entropy = n * entropy_per_question
# Calculate the average entropy
average_entropy = total_entropy / n
# Calculate the information transfer rate (ITR)
itr_value = (v / t) * average_entropy
return itr_value
# Example usage
n = 10 # Number of questions
q = 4 # Number of choices per question
v = 8 # Number of correct answers
t = 5 # Time taken in seconds
itr_result = itr(n, q, v, t)
print(f"Information Transfer Rate: {itr_result:.2f} bits per second")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment