Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- from math import factorial
- BlackT = 35
- OrangeT = 5
- BlueT = 2
- RedT = 8
- Total = BlackT + OrangeT + BlueT + RedT
- #Inputs of A
- N = Total
- K = BlackT
- n = 25
- k = 20
- HypergeometricD = ((factorial(K)/(factorial(k)*factorial(K-k)))*(factorial(N-K)/(factorial(n-k)*factorial(N-K-(n-k)))))/(factorial(N)/(factorial(n)*factorial(N-n)))
- Combinations = factorial(N)/(factorial(n)*factorial(N-n))
- Black = 10
- Orange = 0
- Blue = 0
- Red = 0
- i = 0
- df = pd.DataFrame(columns=['Black','Orange','Blue','Red','ProbabilityV', 'Variants'])
- while Black <= 25:
- Orange = 0
- while Orange <= OrangeT:
- Blue = 0
- while Blue <= BlueT:
- Red = 0
- while Red <= RedT:
- if Black+Orange+Blue+Red == 25:
- BlackC = factorial(BlackT)/(factorial(Black)*factorial(BlackT-Black))
- OrangeC = factorial(OrangeT)/(factorial(Orange)*factorial(OrangeT-Orange))
- BlueC = factorial(BlueT)/(factorial(Blue)*factorial(BlueT-Blue))
- RedC = factorial(RedT)/(factorial(Red)*factorial(RedT-Red))
- Variants = BlackC*OrangeC*BlueC*RedC
- ProbabilityV = Variants/Combinations
- df.loc[i] = [Black, Orange, Blue, Red, ProbabilityV, Variants]
- i += 1
- Red += 1
- Blue += 1
- Orange += 1
- Black += 1
- ProbabilityT = 0
- CheckT = 0
- VariantsT = 0
- for index, row in df.iterrows():
- ProbabilityT += row["ProbabilityV"] * row["ProbabilityV"]
- CheckT += row["ProbabilityV"]
- VariantsT += row["Variants"]
- print("Probability of A case =", "{:10.12f}".format(HypergeometricD))
- print("Probability of B case =", "{:10.12f}".format(ProbabilityT))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement