def cauchyFunc(): for i in range(len(size)): n = size[i] fig, ax = plt.subplots(1, 1) ax.set_title("Распределение Коши, n = " + str(n)) x = np.linspace(cauchy.ppf(0.01), cauchy.ppf(0.99), 100) ax.plot(x, cauchy.pdf(x), 'b-', lw=5, alpha=0.6) r = cauchy.rvs(size=n) ax.hist(r, density=True, histtype='stepfilled', alpha=0.2) plt.show()
def ppf(self, q): """ Percentile function (inverse cumulative distribution function) :param q: np.ndarray, quantiles to evaluate :return: np.ndarray, quantiles """ return cauchy.ppf(q, self.mu, self.eta)
def test_voigt_ppf(): resonance_energy = 1e6 pseudo_voigt = PseudoVoigtDistribution(resonance_energy, 1.0, 1.0, 100.0) # Test scalar and array input. assert np.isclose(pseudo_voigt.ppf(0.5), resonance_energy, 1e-5) assert np.allclose( pseudo_voigt.ppf(np.array([0.5, 0.5])), np.array([resonance_energy, resonance_energy]), 1e-5, ) # Test fallback approximation. # The result should be somewhere in between the results of the two constituent PPFs. extremely_small_quantile = 1e-7 with pytest.warns(UserWarning): assert pseudo_voigt.ppf(extremely_small_quantile) > cauchy.ppf( extremely_small_quantile ) assert pseudo_voigt.ppf(extremely_small_quantile) < norm.ppf( extremely_small_quantile )
def tune_scale(self, u: float, y: float): self.scale = abs(u - y) / cauchy.ppf(q=((self.p + 1) / 2))
#!/usr/bin/python import numpy as np import matplotlib.pyplot as plt from scipy.stats import cauchy fig, ax = plt.subplots(figsize=(8, 7)) ax.set_xlim([0.4, 0.68]) ax.set_ylim([0, 9.5]) mean, var, skew, kurt = cauchy.stats(moments='mvsk') x = np.linspace(cauchy.ppf(0.01), cauchy.ppf(0.99), 1000000) y = np.linspace(0, 6.6, 100) ons = np.ones(100) plt.rc('text', usetex=True) plt.rc('font', family='serif') fsize = 18 #2c0032 ax.plot(x, cauchy.pdf(x, loc=0.53432, scale=0.0382), color='#6ca6cd', lw=3) #, label='$\Delta=0.0382, \sigma=0.0079$') #ax.plot(x, cauchy.pdf(x, loc=0.55334, scale=0.0102 ), color='#8c07ee', lw=3, label='$\Delta=0.0102$') #ax.plot(x, cauchy.pdf(x, loc=0.54545, scale=0.0024 ), color='#ad1927', lw=3, label='$\Delta=0.0024$') #ax.plot(x, cauchy.pdf(x, loc=0.59613, scale=0.0988 ), color='#f5ce00', lw=3, label='$\Delta=0.0988$') #ax.plot(x, cauchy.pdf(x, loc=0.53622, scale=0.0349 ), color='#ff6600', lw=3, label='$\Delta=0.0349$') midp = 0.5 * (0.488 + 0.580)
from scipy.stats import cauchy import matplotlib.pyplot as plt fig, ax = plt.subplots(1, 1) # Calculate a few first moments: mean, var, skew, kurt = cauchy.stats(moments='mvsk') # Display the probability density function (``pdf``): x = np.linspace(cauchy.ppf(0.01), cauchy.ppf(0.99), 100) ax.plot(x, cauchy.pdf(x), 'r-', lw=5, alpha=0.6, label='cauchy 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 = cauchy() ax.plot(x, rv.pdf(x), 'k-', lw=2, label='frozen pdf') # Check accuracy of ``cdf`` and ``ppf``: vals = cauchy.ppf([0.001, 0.5, 0.999]) np.allclose([0.001, 0.5, 0.999], cauchy.cdf(vals)) # True # Generate random numbers: r = cauchy.rvs(size=1000)
#!/usr/bin/python import numpy as np import matplotlib.pyplot as plt from scipy.stats import cauchy fig, ax = plt.subplots(1,1) mean,var,skew,kurt = cauchy.stats(moments='mvsk') x = np.linspace(cauchy.ppf(0.01),cauchy.ppf(0.99),100000) y = np.linspace(0,140,100) y2 = np.linspace(0,80,100) ons = np.ones(100) plt.rc('text', usetex=True) plt.rc('font', family='serif') ax.plot(x, cauchy.pdf(x, loc=0.53432, scale=0.0382 ), color='#2c0032', lw=3, label='$\Delta=0.0382$') ax.plot(x, cauchy.pdf(x, loc=0.55334, scale=0.0102 ), color='#8c07ee', lw=3, label='$\Delta=0.0102$') ax.plot(x, cauchy.pdf(x, loc=0.54545, scale=0.0024 ), color='#ad1927', lw=3, label='$\Delta=0.0024$') ax.plot(x, cauchy.pdf(x, loc=0.59613, scale=0.0988 ), color='#f5ce00', lw=3, label='$\Delta=0.0988$') ax.plot(x, cauchy.pdf(x, loc=0.53622, scale=0.0349 ), color='#ff6600', lw=3, label='$\Delta=0.0349$') ax.plot(x, cauchy.pdf(x, loc=0.5237, scale=0.0295 ), color='#6ca6cd', lw=3, label='$\Delta=0.0295$') ax.plot(0.695*ons,y2,'k--',lw=1) ax.plot(0.494*ons,y,'k--',lw=1) ax.legend(loc='best',frameon=False) ax.set_xlim([0.425,0.75]) #ax.set_title('Cauchy PDF') #plt.text(-2.0,0.2,'$\Delta=0.53$',fontsize=12)
x3 = np.linspace(min(laplace.ppf(0.01), min(r3)), max(laplace.ppf(0.99), max(r3)), 100) ax[2].plot(x3, laplace.cdf(x3, 0, sqrt(2))) ax[2].hist(r3, density=True, bins=floor(len(r3)), histtype='step', cumulative=True) ax[2].set_xlabel('x') ax[2].set_title('Распределение Лапласа, n=100') #plt.show()#Лапласа fig2, ay = plt.subplots(1, 3) r = cauchy.rvs(size=20) y = np.linspace(min(cauchy.ppf(0.01), min(r)), max(cauchy.ppf(0.99), max(r)), 100) ay[0].plot(y, cauchy.cdf(y, 0, 1)) ay[0].hist(r, density=True, bins=floor(len(r)), histtype='step', cumulative=True) ay[0].set_xlabel('x') ay[0].set_title('Распределение Коши, n=20') r2 = cauchy.rvs(size=60) y2 = np.linspace(min(cauchy.ppf(0.01), min(r2)), max(cauchy.ppf(0.99), max(r2)), 100) ay[1].plot(y2, cauchy.cdf(y2, 0, 1)) ay[1].hist(r2,
def vot_distribution(sample_size, loc=10, scale=3): x = np.linspace(cauchy.ppf(0.01), cauchy.ppf(0.99), 1000) rv = cauchy(loc, scale) y = rv.pdf(x) samples = rv.rvs(size=size) return samples