// Numbas version: finer_feedback_settings {"name": "PC2 - Entropy", "extensions": [], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"name": "PC2 - Entropy", "tags": [], "metadata": {"description": "", "licence": "Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International"}, "statement": "

We have information about nests and the number of eggs that they contain. The information is summarised in the following table.

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
Clutch Size$3$$4$$5$$6$$7$$8$$9$
$P(C=c)${p3}{p4}{p5}{p6}{p7}{p8}{p9}
", "advice": "

a) The formula for Shannon entropy is:

\n

\\begin{align}
H(x) &= -\\sum_{i=1}^n P(x_i)\\cdot ln(P(x_i)).
\\end{align}

\n

Calculating this using the information about Clutch sizes in the table gives,

\n

\\begin{align}
H(x) &= -\\left(\\var{p3}\\cdot ln(\\var{p3}) + \\var{p4}\\cdot ln(\\var{p4}) + \\var{p5}\\cdot ln(\\var{p5}) + \\var{p6}\\cdot ln(\\var{p6}) + \\var{p7}\\cdot ln(\\var{p7}) + \\var{p8}\\cdot ln(\\var{p8}) + \\var{p9}\\cdot ln(\\var{p9})\\right) \\\\
&= \\var{shanent}.
\\end{align}

\n

Hence, $H(x) = \\var{round_shanent}$ to two decimal places.

\n

b) An even clutch size will mean the nest contains $4$, $6$, or $8$ eggs. Therefore, 

\n

\\begin{align}
P(c\\text{ is even}) &= P(C=4) + P(C=6) + P(c=8) \\\\
&= \\var{p4} + \\var{p6} + \\var{p8} \\\\
&= \\var{even}.
\\end{align}

\n

c) If we know the clutch size is even we immediately know that the probability that the nests contain an odd number of eggs will be 0. Hence, 

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
Clutch Size$3$$4$$5$$6$$7$$8$$9$
$P(C=c|C\\text{ is even})$$0$$0$$0$$0$
\n

Now, using the formula for conditional probability, 

\n

\\begin{align}
P(C=c|C\\text{ is even}) &= \\frac{P(C=c\\text{ and }C\\text{ is even})}{P(C\\text{ is even})}.
\\end{align}

\n

So, for $c=4$,

\n

\\begin{align}
P(C=4|C\\text{ is even}) &= \\frac{P(C=4)}{P(C\\text{ is even})} \\\\
&= \\frac{\\var{p4}}{\\var{even}} \\\\
&= \\var{p4e2}, \\text{ to two decimal places}.
\\end{align}

\n

We use the same formula for $c=6$ and $c=8$, 

\n

\\begin{align}
P(C=6|C\\text{ is even}) &= \\frac{P(C=6)}{P(C\\text{ is even})} \\\\
&= \\frac{\\var{p6}}{\\var{even}} \\\\
&= \\var{p6e2}, \\text{ to two decimal places} \\\\
& \\text{and} \\\\
P(C=8|C\\text{ is even}) &= \\frac{P(C=8)}{P(C\\text{ is even})} \\\\
&= \\frac{\\var{p8}}{\\var{even}} \\\\
&= \\var{p8e2}, \\text{ to two decimal places}.
\\end{align}

\n

So our completed probability distribution is:

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
Clutch Size$3$$4$$5$$6$$7$$8$$9$
$P(C=c|C\\text{ is even})$$0${p4e2}$0${p6e2}$0${p8e2}$0$
\n

d) We calculate the Shannon entropy utilising the same formula from part b,

\n

\\begin{align}
H(x) &= -\\left(\\var{p4e2}\\cdot ln(\\var{p4e2}) + \\var{p6e2}\\cdot ln(\\var{p6e2}) + \\var{p8e2}\\cdot ln(\\var{p8e2}) \\right) \\\\
&= \\var{even_shanent}.
\\end{align}

\n

Hence, $H(x) = \\var{roundeven_shanent}$, rounded to two decimal places.

\n

e) Since the entropy decreases when we learn that the clutch size is even, we can say that we are more certan about the outcome.

", "rulesets": {}, "extensions": [], "builtin_constants": {"e": true, "pi,\u03c0": true, "i": true, "j": false}, "constants": [], "variables": {"p3": {"name": "p3", "group": "Ungrouped variables", "definition": "if(randnum=1,0.01,if(randnum=2,0.02,if(randnum=3,0.02,0)))", "description": "

probability of the nest having 3 eggs

", "templateType": "anything", "can_override": false}, "p4": {"name": "p4", "group": "Ungrouped variables", "definition": "if(randnum=1,0.17,if(randnum=2,0.13,if(randnum=3,0.17,0)))", "description": "

probability of the nest having 4 eggs

", "templateType": "anything", "can_override": false}, "p5": {"name": "p5", "group": "Ungrouped variables", "definition": "if(randnum=1,0.35,if(randnum=2,0.4,if(randnum=3,0.34,0)))", "description": "

probability of the nest having 5 eggs

", "templateType": "anything", "can_override": false}, "p6": {"name": "p6", "group": "Ungrouped variables", "definition": "if(randnum=1,0.33,if(randnum=2,0.32,if(randnum=3,0.3,0)))", "description": "

probability of the nest having 6 eggs

", "templateType": "anything", "can_override": false}, "p7": {"name": "p7", "group": "Ungrouped variables", "definition": "if(randnum=1,0.09,if(randnum=2,0.1,if(randnum=3,0.08,0)))", "description": "

probability of the nest having 7 eggs

", "templateType": "anything", "can_override": false}, "p8": {"name": "p8", "group": "Ungrouped variables", "definition": "if(randnum=1,0.03,if(randnum=2,0.02,if(randnum=3,0.06,0)))", "description": "

probability of the nest having 8 eggs

", "templateType": "anything", "can_override": false}, "p9": {"name": "p9", "group": "Ungrouped variables", "definition": "if(randnum=1,0.02,if(randnum=2,0.01,if(randnum=3,0.03,0)))", "description": "

probability of the nest having 9 eggs

", "templateType": "anything", "can_override": false}, "randnum": {"name": "randnum", "group": "Ungrouped variables", "definition": "random(1,2,3,1,2,3)", "description": "

Random number generator to decide which set of probabilities the question will use

", "templateType": "anything", "can_override": false}, "shanent": {"name": "shanent", "group": "Ungrouped variables", "definition": "-(p3*ln(p3)+p4*ln(p4)+p5*ln(p5)+p6*ln(p6)+p7*ln(p7)+p8*ln(p8)+p9*ln(p9))", "description": "

Calculation of shannon entropy

", "templateType": "anything", "can_override": false}, "round_shanent": {"name": "round_shanent", "group": "Ungrouped variables", "definition": "precround(shanent,2)", "description": "

Shannon entropy rounded to 2 decimal places

", "templateType": "anything", "can_override": false}, "even": {"name": "even", "group": "Even Clutch Size (Part b & c)", "definition": "p4+p6+p8", "description": "

The probability that the clutch size is even

", "templateType": "anything", "can_override": false}, "p4e": {"name": "p4e", "group": "Even Clutch Size (Part b & c)", "definition": "p4/even", "description": "

probability clutch size has 4 eggs given clutch size is even

", "templateType": "anything", "can_override": false}, "p6e": {"name": "p6e", "group": "Even Clutch Size (Part b & c)", "definition": "p6/even", "description": "

probability clutch size has 6 eggs given clutch size is even

", "templateType": "anything", "can_override": false}, "p8e": {"name": "p8e", "group": "Even Clutch Size (Part b & c)", "definition": "p8/even", "description": "

probability clutch size has 8 eggs given clutch size is even

", "templateType": "anything", "can_override": false}, "p4e2": {"name": "p4e2", "group": "Even Clutch Size (Part b & c)", "definition": "precround(p4e,2)", "description": "

probability clutch size has 4 eggs given clutch size is even, rounded to 2 d.p.

", "templateType": "anything", "can_override": false}, "p6e2": {"name": "p6e2", "group": "Even Clutch Size (Part b & c)", "definition": "precround(p6e,2)", "description": "

probability clutch size has 6 eggs given clutch size is even, rounded to 2 d.p.

", "templateType": "anything", "can_override": false}, "p8e2": {"name": "p8e2", "group": "Even Clutch Size (Part b & c)", "definition": "precround(p8e,2)", "description": "

probability clutch size has 8 eggs given clutch size is even, rounded to 2 d.p.

", "templateType": "anything", "can_override": false}, "even_shanent": {"name": "even_shanent", "group": "Even Clutch Size (Part b & c)", "definition": "-(p4e*ln(p4e)+p6e*ln(p6e)+p8e*ln(p8e))", "description": "

Shannon entropy

", "templateType": "anything", "can_override": false}, "roundeven_shanent": {"name": "roundeven_shanent", "group": "Even Clutch Size (Part b & c)", "definition": "precround(even_shanent,2)", "description": "

Shannon entropy, rounded to 2 decimla places

", "templateType": "anything", "can_override": false}}, "variablesTest": {"condition": "", "maxRuns": 100}, "ungrouped_variables": ["p3", "p4", "p5", "p6", "p7", "p8", "p9", "randnum", "shanent", "round_shanent"], "variable_groups": [{"name": "Even Clutch Size (Part b & c)", "variables": ["even", "p4e", "p4e2", "p6e", "p6e2", "p8e", "p8e2", "even_shanent", "roundeven_shanent"]}], "functions": {}, "preamble": {"js": "", "css": ""}, "parts": [{"type": "numberentry", "useCustomName": true, "customName": "a)", "marks": 1, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "

Calculate the Shannon entropy (in nats) of the clutch size.

\n

Round your answer to two decimal places if necessary.

", "minValue": "round_shanent", "maxValue": "round_shanent", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "displayAnswer": "", "showFractionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}, {"type": "numberentry", "useCustomName": true, "customName": "b)", "marks": 1, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "

What is the probability that the clutch size is even i.e., $P(c\\text{ is even})$?

", "minValue": "even", "maxValue": "even", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "displayAnswer": "", "showFractionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}, {"type": "gapfill", "useCustomName": true, "customName": "c)", "marks": 0, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "

If we know the clutch size is an even number, compute the new distribution $P(C=c|c\\text{ is even})$.

\n

Round your answers to two decimal places where necessary.

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
Clutch Size$3$$4$$5$$6$$7$$8$$9$
$P(C=c|C\\text{ is even})$[[0]][[1]][[2]][[3]][[4]][[5]][[6]]
", "gaps": [{"type": "numberentry", "useCustomName": true, "customName": "3", "marks": 1, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "minValue": "0", "maxValue": "0", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "displayAnswer": "", "showFractionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}, {"type": "numberentry", "useCustomName": true, "customName": "4", "marks": 1, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "minValue": "p4e2", "maxValue": "p4e2", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "displayAnswer": "", "showFractionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}, {"type": "numberentry", "useCustomName": true, "customName": "5", "marks": 1, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "minValue": "0", "maxValue": "0", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "displayAnswer": "", "showFractionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}, {"type": "numberentry", "useCustomName": true, "customName": "6", "marks": 1, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "minValue": "p6e2", "maxValue": "p6e2", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "displayAnswer": "", "showFractionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}, {"type": "numberentry", "useCustomName": true, "customName": "7", "marks": 1, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "minValue": "0", "maxValue": "0", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "displayAnswer": "", "showFractionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}, {"type": "numberentry", "useCustomName": true, "customName": "8", "marks": 1, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "minValue": "p8e2", "maxValue": "p8e2", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "displayAnswer": "", "showFractionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}, {"type": "numberentry", "useCustomName": true, "customName": "9", "marks": 1, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "minValue": "0", "maxValue": "0", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "displayAnswer": "", "showFractionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}], "sortAnswers": false}, {"type": "numberentry", "useCustomName": true, "customName": "d)", "marks": 1, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "

Recalculate the Shannon Entropy using the distribution you found in part c.

\n

Round your answer to 2 decimal places.

", "minValue": "roundeven_shanent", "maxValue": "roundeven_shanent", "correctAnswerFraction": false, "allowFractions": false, "mustBeReduced": false, "mustBeReducedPC": 0, "displayAnswer": "", "showFractionHint": true, "notationStyles": ["plain", "en", "si-en"], "correctAnswerStyle": "plain"}, {"type": "1_n_2", "useCustomName": true, "customName": "e)", "marks": 0, "scripts": {}, "customMarkingAlgorithm": "", "extendBaseMarkingAlgorithm": true, "unitTests": [], "showCorrectAnswer": true, "showFeedbackIcon": true, "variableReplacements": [], "variableReplacementStrategy": "originalfirst", "nextParts": [], "suggestGoingBack": false, "adaptiveMarkingPenalty": 0, "exploreObjective": null, "prompt": "

Comparing your Shannon entropy with the one you calculated in part b, which statement in true about our sysem?

", "minMarks": 0, "maxMarks": 0, "shuffleChoices": true, "displayType": "radiogroup", "displayColumns": 0, "showCellAnswerState": true, "choices": ["We are more certain about the outcome i.e., the number of eggs in a nest.", "We are less certain about the outcome i.e., the number of eggs in a nest."], "matrix": ["1", 0], "distractors": ["", ""]}], "partsMode": "all", "maxMarks": 0, "objectives": [], "penalties": [], "objectiveVisibility": "always", "penaltyVisibility": "always", "contributors": [{"name": "Lauren Desoysa", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/21504/"}, {"name": "Megan Oliver", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/23526/"}], "resources": []}]}], "contributors": [{"name": "Lauren Desoysa", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/21504/"}, {"name": "Megan Oliver", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/23526/"}]}