2013-07-30 19 views
9

Kümülatif yoğunluk fonksiyonunun tam türevi olasılık yoğunluk fonksiyonu (PDF) midir? Ben numpy.diff() kullanarak türev hesaplıyor, bu doğru mu? Aşağıdaki kodu aşağıya bakın:Kümülatif yoğunluk fonksiyonunun türevinin hesaplanması Python

import scipy.stats as s 
import matplotlib.pyplot as plt 
import numpy as np 

wei = s.weibull_min(2, 0, 2) # shape, loc, scale - creates weibull object 
sample = wei.rvs(1000) 
shape, loc, scale = s.weibull_min.fit(sample, floc=0) 

x = np.linspace(np.min(sample), np.max(sample)) 

plt.hist(sample, normed=True, fc="none", ec="grey", label="frequency") 
plt.plot(x, wei.cdf(x), label="cdf") 
plt.plot(x, wei.pdf(x), label="pdf") 
plt.plot(x[1:], np.diff(wei.cdf(x)), label="derivative") 
plt.legend(loc=1) 
plt.show() 

Compariosn of CDF, PDF and derivative

Eğer öyleyse, nasıl PDF eşdeğer olarak türevi ölçek edersiniz?

cevap

6

CDF'nin türevi PDF'dir. deriv ilişkili x-locations tarafından kaymış olduğu

dx = x[1]-x[0] 
deriv = np.diff(wei.cdf(x))/dx 

import scipy.stats as s 
import matplotlib.pyplot as plt 
import numpy as np 

wei = s.weibull_min(2, 0, 2) # shape, loc, scale - creates weibull object 
sample = wei.rvs(1000) 
shape, loc, scale = s.weibull_min.fit(sample, floc=0) 

x = np.linspace(np.min(sample), np.max(sample)) 
dx = x[1]-x[0] 
deriv = np.diff(wei.cdf(x))/dx 
plt.hist(sample, normed=True, fc="none", ec="grey", label="frequency") 
plt.plot(x, wei.cdf(x), label="cdf") 
plt.plot(x, wei.pdf(x), label="pdf") 
plt.plot(x[1:]-dx/2, deriv, label="derivative") 
plt.legend(loc=1) 
plt.show() 

verimleri

enter image description here

Not: Burada

bir CDF türevinin yaklaşımdır dx/2 böylece yaklaşık hesaplamak için kullanılan değerler arasında ortalanır.