-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathexample.py
More file actions
48 lines (39 loc) · 1.33 KB
/
example.py
File metadata and controls
48 lines (39 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import VarGamma as vg
from numpy import *
import matplotlib.pyplot as plt
random.seed(1)
c = 0.0 # location
sigma = 1.0 # spread
theta = 0.4 # asymmetry
nu = 0.8 # shape
grid = arange(-10, 10, 0.1)
pdf_values = vg.pdf(grid, c, sigma, theta, nu)
cdf_values = vg.cdf(grid, c, sigma, theta, nu)
data = vg.rnd(100, c, sigma, theta, nu)
# try fitting parameters
print('true parameters:')
print(c, sigma, theta, nu)
print('parameters estimated by Methods of Moments:')
(c_fit, sigma_fit, theta_fit, nu_fit) = vg.fit_moments(data)
print(c_fit, sigma_fit, theta_fit, nu_fit)
print('parameters estimated by Maximum Likelihood:')
(c_fit, sigma_fit, theta_fit, nu_fit) = vg.fit(data)
print(c_fit, sigma_fit, theta_fit, nu_fit)
# prepare plotting tools
fig = plt.figure()
ax1 = fig.add_subplot(211)
ax2 = fig.add_subplot(212)
# plot histogram of random data
hist,bins = histogram(data, bins=20)
hist = double(hist)
hist *= max(pdf_values) / max(hist) # just normalisation
width = 0.5*(bins[1] - bins[0])
center = (bins[:-1]+bins[1:]) / 2
ax1.bar(center, hist, align='center', width=width)
# plot pdf of the distribution
ax1.plot(grid, pdf_values, linewidth=3, color='r')
# plot cdf of the distribution
ax2.plot(grid, cdf_values, linewidth=3, color='g')
ax1.set_title('VarGamma PDF and the histogram of random points')
ax2.set_title('VarGamma CDF')
plt.show()