Update distribution.py
This commit is contained in:
parent
ee9a752d7f
commit
e3566d1c21
2
.idea/.gitignore
vendored
2
.idea/.gitignore
vendored
@ -6,3 +6,5 @@
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
# GitHub Copilot persisted chat sessions
|
||||
/copilot/chatSessions
|
||||
|
@ -1,7 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.idea/copilot/chatSessions" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Pipenv (casio-calculator)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
|
1
Pipfile
1
Pipfile
@ -9,4 +9,3 @@ name = "pypi"
|
||||
|
||||
[requires]
|
||||
python_version = "3.11"
|
||||
python_full_version = "3.11.7"
|
||||
|
3
Pipfile.lock
generated
3
Pipfile.lock
generated
@ -1,11 +1,10 @@
|
||||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "bc82cd27f07d4e24b750064464bbc233a141778868b9a387125705e2d4e8a830"
|
||||
"sha256": "ed6d5d614626ae28e274e453164affb26694755170ccab3aa5866f093d51d3e4"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
"python_full_version": "3.11.7",
|
||||
"python_version": "3.11"
|
||||
},
|
||||
"sources": [
|
||||
|
126
distribution.py
126
distribution.py
@ -1,4 +1,5 @@
|
||||
import math
|
||||
import statistics
|
||||
|
||||
|
||||
def factorial(n):
|
||||
@ -371,14 +372,117 @@ def pd_gt(x, l):
|
||||
return 1 - pd_leq(x, l)
|
||||
|
||||
|
||||
def sample_mean_e(u):
|
||||
"""
|
||||
Computes the expected value of the sample mean.
|
||||
:param u: The population mean.
|
||||
:return: Returns the expected value of the sample mean.
|
||||
"""
|
||||
return u
|
||||
|
||||
|
||||
def sample_mean_std(u, n):
|
||||
"""
|
||||
Computes the standard deviation of the sample mean.
|
||||
:param u: The population mean.
|
||||
:param n: The sample size.
|
||||
:return: Returns the standard deviation of the sample mean.
|
||||
"""
|
||||
return u / n ** 0.5
|
||||
|
||||
|
||||
def sample_mean_var(u, n):
|
||||
"""
|
||||
Computes the variance of the sample mean.
|
||||
:param u: The population mean.
|
||||
:param n: The sample size.
|
||||
:return: Returns the variance of the sample mean.
|
||||
"""
|
||||
return (sample_mean_std(u, n) ** 2) / n
|
||||
|
||||
|
||||
def z_score(x, u, s):
|
||||
"""
|
||||
Computes the z-score of a sample.
|
||||
:param x: The sample mean.
|
||||
:param u: The population mean.
|
||||
:param s: The standard deviation of the sample mean.
|
||||
:return: Returns the z-score of the sample.
|
||||
"""
|
||||
return (x - u) / s
|
||||
|
||||
|
||||
def z_to_p(z):
|
||||
"""
|
||||
Computes the probability of a z-score.
|
||||
:param z: The z-score.
|
||||
:return: Returns the probability of the z-score.
|
||||
"""
|
||||
nd = statistics.NormalDist()
|
||||
return nd.cdf(z)
|
||||
|
||||
|
||||
def p_to_z(p):
|
||||
"""
|
||||
Computes the z-score of a probability.
|
||||
:param p: The probability.
|
||||
:return: Returns the z-score of the probability.
|
||||
"""
|
||||
nd = statistics.NormalDist()
|
||||
return nd.inv_cdf(p)
|
||||
|
||||
|
||||
def gamma(u, n):
|
||||
"""
|
||||
Computes the gamma of a sample.
|
||||
:param u: The population mean.
|
||||
:param n: The sample size.
|
||||
:return: Returns the gamma of the sample.
|
||||
"""
|
||||
return sample_mean_var(u, n) / sample_mean_e(u)
|
||||
|
||||
|
||||
def alpha(u, n):
|
||||
"""
|
||||
Computes the alpha of a sample.
|
||||
:param u: The population mean.
|
||||
:param n: The sample size.
|
||||
:return: Returns the alpha of the sample.
|
||||
"""
|
||||
return sample_mean_e(u) / gamma(u, n)
|
||||
|
||||
|
||||
def margin_of_error(a, s, n):
|
||||
"""
|
||||
Computes the margin of error of a sample.
|
||||
:param a: The alpha of the sample.
|
||||
:param s: The standard deviation of the sample mean.
|
||||
:param n: The sample size.
|
||||
:return: Returns the margin of error of the sample.
|
||||
"""
|
||||
return abs((p_to_z(a / 2)) * (s / (n ** 0.5)))
|
||||
|
||||
|
||||
def confidence_interval(x, a, s, n):
|
||||
"""
|
||||
Computes the confidence interval of a sample.
|
||||
:param x: The sample mean.
|
||||
:param a: The alpha of the sample.
|
||||
:param s: The standard deviation of the sample mean.
|
||||
:param n: The sample size.
|
||||
:return: Returns the confidence interval of the sample.
|
||||
"""
|
||||
return x - margin_of_error(a, s, n), x + margin_of_error(a, s, n)
|
||||
|
||||
|
||||
def man():
|
||||
"""
|
||||
Prints the manual for the module.
|
||||
"""
|
||||
seperator = "-" * 20
|
||||
separator = "-" * 20
|
||||
print("This module contains functions for computing the total probability of events.")
|
||||
print("The functions are:")
|
||||
print(seperator)
|
||||
print(separator)
|
||||
print("Binomial Distribution")
|
||||
print("bnd(x, n, p)")
|
||||
print("bnd_mean(n, p)")
|
||||
@ -388,7 +492,7 @@ def man():
|
||||
print("bnd_lt(x, n, p)")
|
||||
print("bnd_geq(x, n, p)")
|
||||
print("bnd_gt(x, n, p)")
|
||||
print(seperator)
|
||||
print(separator)
|
||||
print("Geometric Distribution")
|
||||
print("gd(x, p, q)")
|
||||
print("gd_mean(p)")
|
||||
@ -398,7 +502,7 @@ def man():
|
||||
print("gd_lt(x, p, q)")
|
||||
print("gd_geq(x, p, q)")
|
||||
print("gd_gt(x, p, q)")
|
||||
print(seperator)
|
||||
print(separator)
|
||||
print("Hyper Geometric Distribution")
|
||||
print("hgd(x, N, n, k)")
|
||||
print("hgd_mean(N, n, k)")
|
||||
@ -408,7 +512,7 @@ def man():
|
||||
print("hgd_lt(x, N, n, k)")
|
||||
print("hgd_geq(x, N, n, k)")
|
||||
print("hgd_gt(x, N, n, k)")
|
||||
print(seperator)
|
||||
print(separator)
|
||||
print("Poisson Distribution")
|
||||
print("pd(x, l)")
|
||||
print("pd_mean(l)")
|
||||
@ -418,3 +522,15 @@ def man():
|
||||
print("pd_lt(x, l)")
|
||||
print("pd_geq(x, l)")
|
||||
print("pd_gt(x, l)")
|
||||
print(separator)
|
||||
print("Sample Mean")
|
||||
print("sample_mean_e(u)")
|
||||
print("sample_mean_std(u, n)")
|
||||
print("sample_mean_var(u, n)")
|
||||
print("z_score(x, u, s)")
|
||||
print("z_to_p(z)")
|
||||
print("p_to_z(p)")
|
||||
print("gamma(u, n)")
|
||||
print("alpha(u, n)")
|
||||
print("margin_of_error(a, s, n)")
|
||||
print("confidence_interval(x, a, s, n)")
|
||||
|
Loading…
Reference in New Issue
Block a user