summaryrefslogtreecommitdiffstats
path: root/hw2/p1.py
diff options
context:
space:
mode:
Diffstat (limited to 'hw2/p1.py')
-rw-r--r--hw2/p1.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/hw2/p1.py b/hw2/p1.py
new file mode 100644
index 0000000..682abc1
--- /dev/null
+++ b/hw2/p1.py
@@ -0,0 +1,37 @@
+from scipy.special import gamma
+import numpy as np
+from math import exp
+import matplotlib.pyplot as plt
+from scipy.stats import rv_continuous
+
+
+def pdf(u, D):
+ return 1 / (2 ** ((D / 2.) - 1.)
+ * gamma(D / 2.)) * u ** (D - 1.) * exp(-u ** 2. / 2.)
+
+
+class my(rv_continuous):
+
+ def _pdf(self, u, D):
+ return pdf(u, D)
+
+
+def dist():
+ a = np.linspace(0, 20, 1000)
+ plt.figure(figsize=(9, 6))
+ for D in [1, 2, 5, 10, 20, 50, 100]:
+ b = [pdf(u, D) for u in a]
+ plt.plot(a, b, label="D=" + str(D))
+ plt.legend()
+ plt.savefig("dist1.pdf")
+
+
+def cdf():
+ a = my(a=0, b=float("inf"))
+ px = np.linspace(5, 15, 100)
+ plt.figure(figsize=(9, 6))
+ plt.plot(px, a.cdf(px, 100))
+ plt.savefig("cumul.pdf")
+
+if __name__ == "__main__":
+ cdf()