-
Notifications
You must be signed in to change notification settings - Fork 0
/
weibcdf.py
37 lines (31 loc) · 1.13 KB
/
weibcdf.py
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
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 21 09:37:17 2017
@author: lojp
"""
from scipy import stats
from scipy.optimize import curve_fit
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy import asarray as ar,exp
ydata = [0.0041999999999999997, 0.0099869999999999994, 0.015879000000000001,
0.021288000000000001, 0.027421000000000001, 0.035160999999999998,
0.041052999999999999, 0.049036000000000003, 0.057980999999999998,
0.066203999999999999, 0.072849999999999998, 0.079033000000000006,
0.083266999999999994, 0.086085999999999996, 0.0929999999999997]
x = ar(range(1,len(ydata)+1))
y = ar(ydata)
xx = ar(range(1,37))
def weibCumDist(x, a, b):
return 1 - np.exp(-(x / b) ** a)
popt,pcov = curve_fit(weibCumDist,x,y, bounds=(0, [5, 100])) #you need add the bounds to set the range, or we have an error.
print(popt)
fig = plt.figure(figsize=(8,6))
plt.step(x,y,'b-',where='mid',label='data')
plt.plot(xx,weibCumDist(xx,*popt),'r--',label='fit')
plt.ylabel("Cumulative density")
plt.xlabel("TIS")
plt.title('Weibull-CDF Distribution')
plt.legend()
plt.show()