コード例 #1
0
def GetRandomDistribution(n):

# --- Definition of some standard given values -----------------------

  AverageHousePrice = 228147      # [ £ ]
  Gradient          = 78147.0
  Intercept         = 150000

# --- Number holders -------------------------------------------------

  x   = np.linspace(moyal.ppf(0.01), moyal.ppf(0.99), 1000)
  y   = []
  gen = []

# --- Calculating the distribution based on moyal curve --------------

  for i in x:
    y.append(moyal.pdf(i-2))
  
  cdf = I.cumtrapz(y, dx = ((x[-1] - x[1])/len(x)), initial=0)
  for i in range(n):
    gen.append(np.interp(np.random.uniform(), cdf, x))

  return gen
コード例 #2
0
import numpy as np
from scipy.stats import moyal, crystalball
import matplotlib.pyplot as plt

fig, ax = plt.subplots(1, 1)

# plot moyal pdf
loc, scale = 0, 0.625
x = np.linspace(moyal.ppf(0.01, loc, scale), moyal.ppf(0.99, loc, scale), 100)
ax.plot(x, moyal.pdf(x, loc, scale), 'r-', alpha=0.6, label='moyal pdf')

# plot crystal ball pdf
beta, m = 2, 3
x = np.linspace(crystalball.ppf(0.01, beta, m), crystalball.ppf(0.99, beta, m),
                100)
ax.plot(x,
        crystalball.pdf(x, beta, m),
        'b-',
        alpha=0.6,
        label='crystalball pdf')

plt.legend()
plt.show()
コード例 #3
0
 def fitfunc(x, a, mu, sigma):
     return a * moyal.pdf(x, mu, sigma)
コード例 #4
0
)  # / (%i MeV)"%(int(hEnergy[1][-1]-hEnergy[1][0])/len(hEnergy[0])))
ax2.set_xlabel("Total Energy Deposited in Hadronic Calorimeter [GeV]")
ax2.set_ylabel("Number of Events")
mu1, std1 = moyal.fit(100 - totalECAL[totalECAL < 1.1e5])  #this for electron
#mu1,std1=moyal.fit(totalECAL[totalECAL<1.1e5]) #this for proton and muon
mu2, std2 = moyal.fit(
    totalHCAL[totalHCAL < 1.1e5])  #this for electron and muon
#mu2,std2=moyal.fit(100-totalHCAL[totalHCAL<1.1e5]) #this for proton
xVals1 = 100 - ((hECAL[1][1:] + hECAL[1][:-1]) / 2)  #this for electron
#xVals1=((hECAL[1][1:]+hECAL[1][:-1])/2) #this for proton and muon
xVals2 = (hHCAL[1][1:] + hHCAL[1][:-1]) / 2  #this for electron and muon
#xVals2=100-(hHCAL[1][1:]+hHCAL[1][:-1])/2 #this for proton

normaliser1 = len(
    totalECAL[totalECAL < 1.1e5]) * np.abs(hECAL[1][1] - hECAL[1][0])
fitVals1 = moyal.pdf(xVals1, mu1, std1) * normaliser1

normaliser2 = len(
    totalHCAL[totalHCAL < 1.1e5]) * np.abs(hHCAL[1][1] - hHCAL[1][0])
fitVals2 = moyal.pdf(xVals2, mu2, std2) * normaliser2
#chiSqGauss=np.sum((h[0][boolChooseBins]-normaliser*norm.pdf(((h[1][boolChoose])[:-1]+(h[1][boolChoose])[1:])/2, mu, std))**2/(normaliser*norm.pdf(((h[1][boolChoose])[:-1]+(h[1][boolChoose])[1:])/2, mu, std))**2)/(len(boolChooseBins)-2)

chiSq1 = np.sum(((hECAL[0][hECAL[0] > 0] - fitVals1[hECAL[0] > 0]) /
                 np.sqrt(hECAL[0][hECAL[0] > 0]))**2) / (len(hECAL[0]) - 2)
chiSq2 = np.sum(((hHCAL[0][hHCAL[0] > 0] - fitVals2[hHCAL[0] > 0]) /
                 np.sqrt(hHCAL[0][hHCAL[0] > 0]))**2) / (len(hHCAL[0]) - 2)

ax1.plot(
    np.linspace(hECAL[1][0], hECAL[1][-1], 1000),
    normaliser1 *
    moyal.pdf(100 - np.linspace(hECAL[1][0], hECAL[1][-1], 1000), mu1, std1),
コード例 #5
0
plt.figure()
h = plt.hist(momentumValues,
             bins="auto",
             fill=False,
             ec="b",
             label="Entries: %i" % len(momentumValues))

momentumValues = np.array(momentumValues)
xmin, xmax = initMom - initMom / 100 * 35, initMom + initMom / 100 * 70
#mu,std=norm.fit(momentumValues[(momentumValues>xmin)&(momentumValues<xmax)])
mu, std = moyal.fit(momentumValues[(momentumValues > xmin)
                                   & (momentumValues < xmax)])
xVals = np.linspace(xmin, xmax, 100)
# fitNumbers = norm.pdf(xVals, mu, std)
fitNumbers = moyal.pdf(xVals, mu, std)
boolChoose = (h[1] > xmin) & (h[1] < xmax
                              )  #bool to choose bins within fitting area
boolChooseBins = (boolChoose[:-1].astype(int) +
                  boolChoose[1:].astype(int)) == 2
#boolChooseBins=[]
print(boolChooseBins)
normaliser = len(
    momentumValues[(momentumValues > xmin)
                   & (momentumValues < xmax)]) * np.abs(h[1][1] - h[1][0])
#chiSqGauss=np.sum((h[0][boolChooseBins]-normaliser*norm.pdf(((h[1][boolChoose])[:-1]+(h[1][boolChoose])[1:])/2, mu, std))**2/(normaliser*norm.pdf(((h[1][boolChoose])[:-1]+(h[1][boolChoose])[1:])/2, mu, std))**2)/(len(boolChooseBins)-2)

chiSqGauss = np.sum(
    (h[0][boolChooseBins] - normaliser * moyal.pdf(
        ((h[1][boolChoose])[:-1] + (h[1][boolChoose])[1:]) / 2, mu, std))**2 /
    (normaliser * moyal.pdf(
コード例 #6
0
from scipy.stats import moyal
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, 1)

# Calculate a few first moments:

mean, var, skew, kurt = moyal.stats(moments='mvsk')

# Display the probability density function (``pdf``):

x = np.linspace(moyal.ppf(0.01), moyal.ppf(0.99), 100)
ax.plot(x, moyal.pdf(x), 'r-', lw=5, alpha=0.6, label='moyal 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 = moyal()
ax.plot(x, rv.pdf(x), 'k-', lw=2, label='frozen pdf')

# Check accuracy of ``cdf`` and ``ppf``:

vals = moyal.ppf([0.001, 0.5, 0.999])
np.allclose([0.001, 0.5, 0.999], moyal.cdf(vals))
# True

# Generate random numbers:

r = moyal.rvs(size=1000)
コード例 #7
0
import numpy as np
from scipy.stats import moyal, norm
import matplotlib.pyplot as plt

fig, ax = plt.subplots(1, 1)

# plot moyal pdf
loc, scale = 0.004, 0.006
x = np.linspace(moyal.ppf(0.01, loc=loc, scale=scale),
                moyal.ppf(0.99, loc=loc, scale=scale), 100)
ax.plot(x,
        moyal.pdf(x, loc=loc, scale=scale),
        'r',
        alpha=0.6,
        label='moyal pdf')

# plot moyal samples
s_moyal = moyal.rvs(loc, scale, size=1000)
ax.hist(s_moyal, 40, alpha=0.6, density=True, label='moyal histogram')

# plot normal pdf
mu, sigma = 0, 0.014  # mean and standard deviation
x = np.linspace(norm.ppf(0.01, loc=mu, scale=sigma),
                norm.ppf(0.99, loc=mu, scale=sigma), 100)
ax.plot(x,
        norm.pdf(x, loc=mu, scale=sigma),
        'b',
        alpha=0.6,
        label='normal pdf')

# plot normal samples