Skip to content

Commit 48e7ac7

Browse files
committed
feat: rework desctiption
1 parent 584657e commit 48e7ac7

File tree

14 files changed

+345
-66
lines changed

14 files changed

+345
-66
lines changed

‎distributions/base.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ def get_formula(self):
1818
pass
1919

2020
@abstractmethod
21-
def get_properties(self):
21+
def get_properties(self, st):
2222
"""Return distribution properties"""
23-
pass
23+
pass

‎distributions/continuous/__init__.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
from .mutivariative_normal import MultivariateNormalDistribution
33
from .chi_squared import ChiSquaredDistribution
44
from .uniform import UniformDistribution
5+
from .exponential import ExponentialDistribution
56

6-
__all__ = ['NormalDistribution', 'MultivariateNormalDistribution', 'ChiSquaredDistribution', 'UniformDistribution']
7+
__all__ = ['NormalDistribution', 'MultivariateNormalDistribution', 'ChiSquaredDistribution', 'UniformDistribution', 'ExponentialDistribution']

‎distributions/continuous/chi_squared.py‎

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,32 @@ def plot(self, ax):
1818
def get_formula(self):
1919
return r'f(x) = \frac{1}{2^{k/2}\Gamma(k/2)}x^{k/2-1}e^{-x/2}'
2020

21-
def get_properties(self):
22-
return """
23-
- Support is x > 0
24-
- Mean equals degrees of freedom (k)
25-
- Variance equals 2k
26-
- Right-skewed distribution
27-
- Sum of k squared standard normal variables
28-
"""
21+
def get_properties(self, st):
22+
st.write("""
23+
The **Chi-squared distribution** is a continuous probability distribution that is commonly used in statistical inference.
24+
It is characterized by one parameter:
25+
- **k (degrees of freedom)**: determines the shape of the distribution
26+
27+
Key Properties:
28+
- **Support is x > 0** (non-negative values only)
29+
- **Mean equals degrees of freedom (k)**
30+
- **Variance equals 2k**
31+
- **Right-skewed distribution**
32+
- **Sum of k squared standard normal variables**
33+
34+
The probability density function (PDF) is given by:
35+
""")
36+
37+
st.latex(r'f(x) = \frac{1}{2^{k/2}\Gamma(k/2)}x^{k/2-1}e^{-x/2}')
38+
39+
st.write("""
40+
Common applications include:
41+
- **Goodness-of-fit tests**
42+
- **Testing independence in contingency tables**
43+
- **Confidence intervals for population variance**
44+
- **Component in other distributions** (e.g., F-distribution)
45+
46+
Important links:
47+
- [**Properties**](https://en.wikipedia.org/wiki/Chi-square_distribution#Properties)
48+
- [**Applications**](https://en.wikipedia.org/wiki/Chi-square_distribution#Applications)
49+
""")
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import numpy as np
2+
from scipy.stats import expon
3+
import streamlit as st
4+
from ..base import Distribution
5+
6+
class ExponentialDistribution(Distribution):
7+
def get_parameters(self):
8+
self.rate = st.slider('Rate parameter (λ)', 0.1, 5.0, 1.0, 0.1)
9+
return {'rate': self.rate}
10+
11+
def plot(self, ax):
12+
x = np.linspace(0, 5/self.rate, 200)
13+
y = self.rate * np.exp(-self.rate * x)
14+
ax.plot(x, y)
15+
ax.set_xlabel('x')
16+
ax.set_ylabel('Probability Density')
17+
18+
def get_formula(self):
19+
return r'f(x) = \lambda e^{-\lambda x}'
20+
21+
def get_properties(self, st):
22+
st.write("""
23+
The **Exponential Distribution** is a continuous probability distribution that describes the time between events in a Poisson point process.
24+
It is characterized by one parameter:
25+
- **λ (rate parameter)**: determines the rate of decay
26+
27+
Key Properties:
28+
- **Support is x ≥ 0** (non-negative values only)
29+
- **Mean = 1/λ**
30+
- **Variance = 1/λ²**
31+
- **Memoryless property**: P(X > s + t | X > s) = P(X > t)
32+
- **Maximum entropy** distribution for a given mean
33+
34+
The probability density function (PDF) is given by:
35+
""")
36+
37+
st.latex(r'f(x) = \lambda e^{-\lambda x} \text{ for } x \geq 0')
38+
39+
st.write("""
40+
The cumulative distribution function (CDF) is:
41+
""")
42+
43+
st.latex(r'F(x) = 1 - e^{-\lambda x} \text{ for } x \geq 0')
44+
45+
st.write("""
46+
Common applications:
47+
- **Lifetime/survival analysis**
48+
- **Time between events**
49+
- **Reliability engineering**
50+
- **Queueing theory**
51+
52+
Important links:
53+
- [**Properties**](https://en.wikipedia.org/wiki/Exponential_distribution#Properties)
54+
- [**Applications**](https://en.wikipedia.org/wiki/Exponential_distribution#Applications)
55+
- [**Relationship to other distributions**](https://en.wikipedia.org/wiki/Exponential_distribution#Related_distributions)
56+
""")

‎distributions/continuous/mutivariative_normal.py‎

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,40 @@ def plot(self, ax):
3737
def get_formula(self):
3838
return r'f(x) = \frac{1}{2\pi|\Sigma|^{1/2}} \exp\left(-\frac{1}{2}(x-\mu)^T\Sigma^{-1}(x-\mu)\right)'
3939

40-
def get_properties(self):
41-
return """
42-
- Generalizes univariate normal to multiple dimensions
43-
- Characterized by mean vector and covariance matrix
44-
- Elliptical contours of constant density
45-
- Marginal and conditional distributions are normal
46-
- Linear combinations are normally distributed
47-
"""
40+
def get_properties(self, st):
41+
st.write("""
42+
The **Multivariate Normal Distribution** is a generalization of the univariate normal distribution to multiple dimensions.
43+
It is characterized by two parameters:
44+
- **μ (mean vector)**: determines the center of the distribution
45+
- **Σ (covariance matrix)**: determines the shape, spread and orientation of the distribution
46+
47+
Key Properties:
48+
- **Generalizes univariate normal to multiple dimensions**
49+
- **Characterized by mean vector and covariance matrix**
50+
- **Elliptical contours of constant density**
51+
- **Marginal and conditional distributions are normal**
52+
- **Linear combinations are normally distributed**
53+
54+
The probability density function (PDF) is given by:
55+
""")
56+
57+
st.latex(r'f(x) = \frac{1}{(2\pi)^{n/2}|\Sigma|^{1/2}} \exp\left(-\frac{1}{2}(x-\mu)^T\Sigma^{-1}(x-\mu)\right)')
58+
59+
st.write("""
60+
where:
61+
- **x** is an n-dimensional vector
62+
- **μ** is the mean vector
63+
- **Σ** is the covariance matrix
64+
- **|Σ|** is the determinant of Σ
65+
66+
The cumulative distribution function (CDF) does not have a closed form for n>1, but can be expressed as:
67+
""")
68+
69+
st.latex(r'F(x) = \int_{-\infty}^{x_1}\cdots\int_{-\infty}^{x_n} f(t_1,\ldots,t_n)dt_1\cdots dt_n')
70+
71+
st.write("""
72+
Important links:
73+
- [**Maximum Likelihood Estimation**](https://en.wikipedia.org/wiki/Multivariate_normal_distribution#Maximum_likelihood_estimation)
74+
- [**Properties**](https://en.wikipedia.org/wiki/Multivariate_normal_distribution#Properties)
75+
- [**Applications**](https://en.wikipedia.org/wiki/Multivariate_normal_distribution#Applications)
76+
""")

‎distributions/continuous/normal.py‎

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,35 @@ def plot(self, ax):
1919
def get_formula(self):
2020
return r'f(x) = \frac{1}{\sigma\sqrt{2\pi}} e^{-\frac{(x-\mu)^2}{2\sigma^2}}'
2121

22-
def get_properties(self):
23-
return """
24-
- Symmetric about mean
25-
- 68-95-99.7 rule applies
26-
- Bell-shaped curve
27-
- Infinite support
28-
"""
22+
def get_properties(self, st):
23+
st.write("""
24+
The **Normal** (or **Gaussian**) distribution is one of the most important probability distributions in statistics.
25+
It is characterized by two parameters:
26+
- **μ (mean)**: determines the center of the distribution
27+
- **σ (standard deviation)**: determines the spread/width of the distribution
28+
29+
Key features:
30+
- **Symmetric bell-shaped curve centered at the mean**
31+
- **About 68% of data falls within 1 standard deviation of mean**
32+
- **About 95% of data falls within 2 standard deviations**
33+
- **About 99.7% of data falls within 3 standard deviations**
34+
35+
The probability density function (PDF) gives the relative likelihood of a random variable taking on a specific value:
36+
""")
37+
38+
st.latex(r'f(x) = \frac{1}{\sigma\sqrt{2\pi}} e^{-\frac{(x-\mu)^2}{2\sigma^2}}')
39+
40+
st.write("""
41+
The cumulative distribution function (CDF) gives the probability that a random variable takes a value less than or equal to x:
42+
""")
43+
44+
st.latex(r'F(x) = \frac{1}{2}[1 + \text{erf}(\frac{x-\mu}{\sigma\sqrt{2}})]')
45+
46+
st.write("""
47+
The normal distribution is extremely important because:
48+
- **It appears naturally in many phenomena** ([Central Limit Theorem](https://en.wikipedia.org/wiki/Central_limit_theorem))
49+
- **It is easy to work with mathematically**
50+
- **Many statistical methods assume** [normality](https://en.wikipedia.org/wiki/Normal_distribution#Normality_tests)
51+
- **It is the** [maximum entropy](https://en.wikipedia.org/wiki/Maximum_entropy_probability_distribution) **distribution for given mean and variance**
52+
""")
53+
return

‎distributions/continuous/uniform.py‎

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,41 @@ def plot(self, ax):
2121
def get_formula(self):
2222
return r'f(x) = \frac{1}{b-a} \text{ for } a \leq x \leq b'
2323

24-
def get_properties(self):
25-
return """
26-
- Constant probability density over interval [a,b]
27-
- Mean = (a+b)/2
28-
- Variance = (b-a)²/12
29-
- Maximum entropy continuous distribution for interval [a,b]
30-
- All points in interval equally likely
31-
"""
24+
def get_properties(self, st):
25+
st.write("""
26+
The **Uniform Distribution** is the simplest continuous probability distribution.
27+
It is characterized by two parameters:
28+
- **a (lower bound)**: minimum value of the interval
29+
- **b (upper bound)**: maximum value of the interval
30+
31+
Key Properties:
32+
- **Constant probability density** of 1/(b-a) over interval [a,b]
33+
- **Zero probability density** outside interval [a,b]
34+
- **Mean = (a+b)/2**
35+
- **Variance = (b-a)²/12**
36+
- **Maximum entropy** continuous distribution for a bounded interval
37+
- **All points in interval are equally likely**
38+
39+
The probability density function (PDF) is given by:
40+
""")
41+
42+
st.latex(r'f(x) = \begin{cases} \frac{1}{b-a} & \text{for } a \leq x \leq b \\ 0 & \text{otherwise} \end{cases}')
43+
44+
st.write("""
45+
The cumulative distribution function (CDF) is:
46+
""")
47+
48+
st.latex(r'F(x) = \begin{cases} 0 & \text{for } x < a \\ \frac{x-a}{b-a} & \text{for } a \leq x \leq b \\ 1 & \text{for } x > b \end{cases}')
49+
50+
st.write("""
51+
Common applications:
52+
- **Random number generation**
53+
- **Prior distribution in Bayesian inference**
54+
- **Modeling random errors**
55+
- **Simple random sampling**
56+
57+
Important links:
58+
- [**Properties**](https://en.wikipedia.org/wiki/Continuous_uniform_distribution#Properties)
59+
- [**Applications**](https://en.wikipedia.org/wiki/Continuous_uniform_distribution#Applications)
60+
- [**Relationship to other distributions**](https://en.wikipedia.org/wiki/Continuous_uniform_distribution#Related_distributions)
61+
""")

‎distributions/discrete/__init__.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from .binomial import BinomialDistribution
22
from .poisson import PoissonDistribution
33
from .multinomial import MultinomialDistribution
4-
__all__ = ['BinomialDistribution', 'PoissonDistribution', 'MultinomialDistribution']
4+
from .geometric import GeometricDistribution
5+
__all__ = ['BinomialDistribution', 'PoissonDistribution', 'MultinomialDistribution', 'GeometricDistribution']

‎distributions/discrete/binomial.py‎

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,34 @@ def plot(self, ax):
1919
def get_formula(self):
2020
return r'P(X=k) = \binom{n}{k}p^k(1-p)^{n-k}'
2121

22-
def get_properties(self):
23-
return """
24-
- Models number of successes in n independent trials
25-
- Each trial has probability p of success
26-
- Mean = np
27-
- Variance = np(1-p)
28-
- Support is k ∈ {0,1,...,n}
29-
"""
22+
def get_properties(self, st):
23+
st.write("""
24+
The **Binomial Distribution** models the number of successes in a fixed number of independent trials.
25+
It is characterized by two parameters:
26+
- **n (number of trials)**: total number of independent experiments
27+
- **p (probability of success)**: probability of success on each trial
28+
29+
Key Properties:
30+
- **Support**: k ∈ {0,1,...,n}
31+
- **Mean**: np
32+
- **Variance**: np(1-p)
33+
- **Independent trials** (no memory between trials)
34+
- **Fixed probability** of success for each trial
35+
36+
The probability mass function (PMF) is given by:
37+
""")
38+
39+
st.latex(r'P(X=k) = \binom{n}{k}p^k(1-p)^{n-k}')
40+
41+
st.write("""
42+
Common applications:
43+
- **Quality control** (number of defective items)
44+
- **Clinical trials** (number of successful treatments)
45+
- **Polling and surveys** (number of positive responses)
46+
- **Genetics** (inheritance patterns)
47+
48+
Important links:
49+
- [**Properties**](https://en.wikipedia.org/wiki/Binomial_distribution#Properties)
50+
- [**Applications**](https://en.wikipedia.org/wiki/Binomial_distribution#Applications)
51+
- [**Relationship to other distributions**](https://en.wikipedia.org/wiki/Binomial_distribution#Related_distributions)
52+
""")
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import numpy as np
2+
from scipy.stats import geom
3+
import streamlit as st
4+
from ..base import Distribution
5+
6+
class GeometricDistribution(Distribution):
7+
def get_parameters(self):
8+
self.p = st.slider('Probability of success (p)', 0.01, 1.0, 0.5, 0.01)
9+
return {'p': self.p}
10+
11+
def plot(self, ax):
12+
x = np.arange(1, min(20, int(5/self.p)))
13+
y = geom.pmf(x, self.p)
14+
ax.bar(x, y, alpha=0.8)
15+
ax.set_xlabel('Number of Trials Until Success')
16+
ax.set_ylabel('Probability')
17+
18+
def get_formula(self):
19+
return r'P(X=k) = (1-p)^{k-1}p'
20+
21+
def get_properties(self, st):
22+
st.write("""
23+
The **Geometric Distribution** models the number of trials needed to get the first success in a sequence of independent Bernoulli trials.
24+
It is characterized by one parameter:
25+
- **p (probability of success)**: probability of success on each trial
26+
27+
Key Properties:
28+
- **Support**: k ∈ {1,2,3,...}
29+
- **Mean = 1/p**
30+
- **Variance = (1-p)/p²**
31+
- **Memoryless property**: P(X > s + t | X > s) = P(X > t)
32+
- **Independent trials** with fixed probability
33+
34+
The probability mass function (PMF) is given by:
35+
""")
36+
37+
st.latex(r'P(X=k) = (1-p)^{k-1}p')
38+
39+
st.write("""
40+
Common applications:
41+
- **Quality control** (number of items inspected until finding a defect)
42+
- **Marketing** (number of attempts until first sale)
43+
- **Reliability** (number of trials until first failure)
44+
- **Game theory** (number of attempts until first win)
45+
46+
Important links:
47+
- [**Properties**](https://en.wikipedia.org/wiki/Geometric_distribution#Properties)
48+
- [**Applications**](https://en.wikipedia.org/wiki/Geometric_distribution#Applications)
49+
- [**Relationship to other distributions**](https://en.wikipedia.org/wiki/Geometric_distribution#Related_distributions)
50+
""")

0 commit comments

Comments
 (0)