Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- # big beans
- B = 100
- # small beans
- b = 100
- # beans on plate ( p = numB + numb )
- p = 10
- # EXAMPLE: probability for p = 10 big beans
- probability_10bigbeans = 1
- for i in range(p):
- probability_10bigbeans *= (B-i)/(B+b-i)
- print(probability_10bigbeans)
- # probability for (numB, numb) distribution:
- def distribution_probability(numB, numb):
- probability_numB_numb = math.factorial(numB+numb)/(math.factorial(numb+1)*math.factorial(numB))
- for i in range(numB):
- probability_numB_numb *= (B-i)/(B+b-i)
- for i in range(numb):
- probability_numB_numb *= (b-i)/(B+b-numB-i)
- return(probability_numB_numb)
- print(distribution_probability(0,10))
- def expectation_value(p):
- expected_i_B = 0
- expected_i_b = 0
- for i_B in range(p):
- for i_b in range(p):
- expected_i_B += distribution_probability(i_B, i_b)*i_B
- expected_i_b += distribution_probability(i_B, i_b)*i_b
- print("The expectation value for", str(p), "beans on the plate", "(out of", str(B), "big beans and", str(b), "small beans in the pot) is:\n\n", str(expected_i_B), "big beans,\n", "and", str(expected_i_b), "small beans.")
- expectation_value(10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement