feat: minor config update with massive module management update to dynamically import based on arguments
This commit is contained in:
1 parent
dd21fd19c6
commit
85e0f16f7d
12 files changed
+271
-252
No files matched your search
@@ -1,6 +1,6 @@
|
||||
## This module represents the second chapter of the book
|
||||
## This module represents the second chapter of the book
|
||||
## "Essential Math for Data Science" - Thomas Nield
|
||||
## Chapter 2 - Probability
|
||||
## Chapter 2 - Probability
|
||||
|
||||
from scipy.stats import binom, beta
|
||||
from math import factorial
|
||||
@@ -31,7 +31,7 @@ class BinomialDistribution:
|
||||
# For each number calc the probability of that exact number of outcomes (no order)
|
||||
for k in range(n + 1):
|
||||
# 1. Simple combinatory with the binomial coeficient (combinations of k elements out of a pool of n without repetition without order)
|
||||
combinatory = BinomialDistribution.binomial_coeficient(n, k)
|
||||
combinatory = BinomialDistribution.binomial_coeficient(n, k)
|
||||
# 2. Probability of success, the probability of making it k times
|
||||
probability_of_success = p ** k
|
||||
# 3. Probability of failure, inverse of the success
|
||||
@@ -44,14 +44,14 @@ class BinomialDistribution:
|
||||
# > Returns a continuous function, so the final probability of X or better must be calculated using integrals (the area under the curve)
|
||||
class BetaDistribution:
|
||||
@staticmethod
|
||||
def calc(probability, success_count, failure_count):
|
||||
def calc(probability, success_count, failure_count):
|
||||
# Only calcs the rpbability to the left
|
||||
return beta.cdf(probability, success_count, failure_count)
|
||||
|
||||
@staticmethod
|
||||
def calc_right(probability, success_count, failure_count):
|
||||
return 1.0 - BetaDistribution.calc(probability, success_count, failure_count)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def calc_region(init_probability, end_probability, success_count, failure_count):
|
||||
return BetaDistribution.calc(end_probability, success_count, failure_count) - BetaDistribution.calc(init_probability, success_count, failure_count)
|
||||
@@ -63,7 +63,7 @@ class Exercises:
|
||||
def one():
|
||||
# 30% change of rain and 40% change your umbrella order will arrive. P(R AND U)
|
||||
return p_r * p_u
|
||||
|
||||
|
||||
@staticmethod
|
||||
def two():
|
||||
# Same Ps as previous. P(!R OR U)
|
||||
@@ -81,7 +81,7 @@ class Exercises:
|
||||
p_bail = 0.4
|
||||
p_at_least_50_bail = 0.0
|
||||
for x in range(50, n + 1):
|
||||
p_at_least_50_bail += binom.pmf(x, n, p_bail)
|
||||
p_at_least_50_bail += binom.pmf(x, n, p_bail)
|
||||
return p_at_least_50_bail
|
||||
|
||||
@staticmethod
|
||||
@@ -91,7 +91,7 @@ class Exercises:
|
||||
t = 2
|
||||
return 1.0 - BetaDistribution.calc(0.5, 8, 2)
|
||||
|
||||
|
||||
|
||||
@staticmethod
|
||||
def test():
|
||||
print("P(R AND U) = {0}".format(Exercises.one()))
|
||||
@@ -101,7 +101,7 @@ class Exercises:
|
||||
print("P(fair) = {0}".format(Exercises.five()))
|
||||
|
||||
|
||||
def test_probability_module():
|
||||
def run():
|
||||
print("=== Probability module ===")
|
||||
print(">> Binomial distribution")
|
||||
BinomialDistribution.example()
|
||||
|
||||
Reference in new issue
Block a user