def returnDistData(cls, self): gammaParam = gamma.fit(10**(self.data / 10)) gammaDist = gamma.pdf(self.data, *gammaParam) rayleighParam = rayleigh.fit(self.data) rayleighDist = rayleigh.pdf(self.data, *rayleighParam) normParam = norm.fit(self.data) normDist = norm.pdf(self.data, *normParam) logNormParam = lognorm.fit(self.data) lognormDist = lognorm.pdf(self.data, *logNormParam) nakagamiParam = nakagami.fit(self.data) nakagamiDist = nakagami.pdf(self.data, *nakagamiParam) exponParam = expon.fit(self.data) exponDist = expon.pdf(self.data, *exponParam) exponweibParam = exponweib.fit(self.data) weibDist = exponweib.pdf(self.data, *exponweibParam) distDF = pd.DataFrame(np.column_stack([ gammaDist, rayleighDist, normDist, lognormDist, nakagamiDist, exponDist, weibDist ]), columns=[ 'gammaDist', 'rayleighDist', 'normDist', 'lognormDist', 'nakagamiDist', 'exponDist', 'weibDist' ]) self.distDF = distDF
def fit(data, filename): Pr = 10**(data / 10) h = np.sqrt(Pr / np.mean(Pr)) paramh = nakagami.fit(h) x = np.linspace(0, 3, 1000) fig, ax = plt.subplots(sharey=False) ax.plot(x, nakagami.pdf(x, nu=paramh[0], loc=paramh[1], scale=paramh[2])) ax.set_ylabel('Nakagami') ax2 = ax.twinx() h.plot(kind='hist', ax=ax2, color='g') fig.savefig(filename + '_dist' + '.png', bbox_inches='tight', dpi=300) pass
# Variando a média e plotando os gráficos #plt.figure(1,[15,5]) #sigma = np.sqrt(vtVar[0]); #for il in range(0,len(vtMu)): # mu = vtMu[il] # plt.subplot(2,2,1) # plt.plot(x, norm.pdf(x,mu), label='Média = {}'.format(mu)) # plt.subplot(2,2,2) # plt.plot(x, norm.cdf(x,mu), label='Média = {}'.format(mu)) # Variando a variância e plotando os gráficos mu = vtMu[0] for il in range(0, len(vtVar)): sigma = (vtVar[il]) plt.subplot(2, 1, 1) plt.plot(x, nakagami.pdf(x, nu=sigma), label='$\ni$ = {:01.2f}'.format(sigma)) # plt.xlim([0,10]) plt.subplot(2, 1, 2) plt.plot(x, nakagami.cdf(x, nu=sigma), label='$\ni$ = {:01.2f}'.format(sigma)) # plt.xlim([0,10]) #plt.subplot(2,2,1) #plt.legend() #plt.subplot(2,2,2) #plt.legend() plt.subplot(2, 1, 1) plt.legend() plt.subplot(2, 1, 2)
from scipy.stats import nakagami import matplotlib.pyplot as plt fig, ax = plt.subplots(1, 1) # Calculate a few first moments: nu = 4.97 mean, var, skew, kurt = nakagami.stats(nu, moments='mvsk') # Display the probability density function (``pdf``): x = np.linspace(nakagami.ppf(0.01, nu), nakagami.ppf(0.99, nu), 100) ax.plot(x, nakagami.pdf(x, nu), 'r-', lw=5, alpha=0.6, label='nakagami pdf') # Alternatively, the distribution object can be called (as a function) # to fix the shape, location and scale parameters. This returns a "frozen" # RV object holding the given parameters fixed. # Freeze the distribution and display the frozen ``pdf``: rv = nakagami(nu) ax.plot(x, rv.pdf(x), 'k-', lw=2, label='frozen pdf') # Check accuracy of ``cdf`` and ``ppf``: vals = nakagami.ppf([0.001, 0.5, 0.999], nu) np.allclose([0.001, 0.5, 0.999], nakagami.cdf(vals, nu)) # True # Generate random numbers:
def fitDist(self): n = len(self.data) # gamma distribution gammaParam = gamma.fit(self.data) gammaNumPar = len(gammaParam) gammaSum = -1 * np.sum(np.log(gamma.pdf(self.data, *gammaParam))) aicGamma = 2 * gammaNumPar + 2 * gammaSum + (2 * gammaNumPar * (gammaNumPar + 1) / (n - gammaNumPar - 1)) # rayleigh distribution rayleighParam = rayleigh.fit(self.data) rayleighNumPar = len(rayleighParam) rayleighSum = -1 * np.sum( np.log(rayleigh.pdf(self.data, *rayleighParam))) aicRayleigh = 2 * rayleighNumPar + 2 * rayleighSum + ( 2 * rayleighNumPar * (rayleighNumPar + 1) / (n - rayleighNumPar - 1)) # normal distribution normParam = norm.fit(self.data) normNumPar = len(normParam) normSum = -1 * np.sum(np.log(norm.pdf(self.data, *normParam))) aicNorm = 2 * normNumPar + 2 * normSum + (2 * normNumPar * (normNumPar + 1) / (n - normNumPar - 1)) # LogNormal distribution logNormParam = lognorm.fit(self.data) logNormNumPar = len(logNormParam) logNormSum = -1 * np.sum(np.log(lognorm.pdf(self.data, *logNormParam))) aicLogNorm = 2 * logNormNumPar + 2 * logNormSum + ( 2 * logNormNumPar * (logNormNumPar + 1) / (n - logNormNumPar - 1)) # Nakagami distribution nakagamiParam = nakagami.fit(self.data) nakagamiNumPar = len(nakagamiParam) nakagamiSum = -1 * np.sum( np.log(nakagami.pdf(self.data, *nakagamiParam))) aicNakagami = 2 * nakagamiNumPar + 2 * nakagamiSum + ( 2 * nakagamiNumPar * (nakagamiNumPar + 1) / (n - nakagamiNumPar - 1)) # exponential distribution exponParam = expon.fit(self.data) exponNumPar = len(exponParam) exponSum = -1 * np.sum(np.log(expon.pdf(self.data, *exponParam))) aicExpon = 2 * exponNumPar + 2 * exponSum + (2 * exponNumPar * (exponNumPar + 1) / (n - exponNumPar - 1)) # weibul distribution exponweibParam = exponweib.fit(self.data) exponweibNumPar = len(exponweibParam) exponweibSum = -1 * np.sum( np.log(exponweib.pdf(self.data, *exponweibParam))) aicExpWeib = 2 * exponweibNumPar + 2 * exponweibSum + ( 2 * exponweibNumPar * (exponweibNumPar + 1) / (n - exponweibNumPar - 1)) return (aicGamma, aicRayleigh, aicNorm, aicLogNorm, aicNakagami, aicExpon, aicExpWeib)