def animate(i): gen = gg.GaussDistribution((2*i) + 1, sigma=sigma).sample(nentries=stats) x, y = plotter.getplotxy(gen) line.set_xdata(x) # update the data line.set_ydata(y) # update the data return line,
import gaussguess as gg import gaussguess.plotter as plotter NBINS = 21 sigma = 0.15 fig, ax = plt.subplots() classes = ["gauss", "uniform", "triangular", "laplace", "poisson"] iclasses = range(len(classes)) classifier = gg.DistributionMultiLabelClassifier(NBINS, nlabels=len(classes)) classifier.loadmodel("{}bins_model_multilabel.h5".format(NBINS)) normop = lambda x: x / max(x) if max(x) > 0 else 0 dist = gg.GaussDistribution(NBINS, sigma=sigma, xlim=[0, 1]) gen = dist.sample(nentries=1).normalise() prediction = classifier.predict(gen) x, y = plotter.getplotxy(gen.normalise(op=normop)) lims = gen.limits line, = ax.plot(x, y, 'k', alpha=0.6) stat_label = ax.text(0.01, 0.99, "{} entries".format(1)) texts = [] startX = 0.7 startY = 0.95 for i, c in enumerate(classes): texts.append( ax.text(startX, startY, "{} = {:.2f}%".format(c, prediction[i] * 100))) startY -= 0.05
import matplotlib.pyplot as plt import matplotlib.animation as animation import numpy as np import gaussguess as gg import gaussguess.plotter as plotter stats = 100000 sigma = 0.05 fig, ax = plt.subplots() gen = gg.GaussDistribution(3, sigma=sigma).sample(nentries=stats) x, y = plotter.getplotxy(gen) lims = gen.limits line, = ax.plot(x, y, 'k', alpha=0.6) def animate(i): gen = gg.GaussDistribution((2*i) + 1, sigma=sigma).sample(nentries=stats) x, y = plotter.getplotxy(gen) line.set_xdata(x) # update the data line.set_ydata(y) # update the data return line, ani = animation.FuncAnimation(fig, animate, np.arange(0, 100), interval=50, blit=False) plt.xlim(lims) plt.ylabel("count / {:.3e}".format(gen.binwidth)) plt.title("Increasing number of bins")
import gaussguess as gg nbins = 9 stats = 100 sn_ratio = 100 signal = gg.GaussDistribution(nbins, sigma=0.1).sample(nentries=stats) noise = gg.UniformDistribution(nbins).sample(nentries=100) measured = signal + (stats / sn_ratio) * noise # print(gen.values) gg.histplot(signal).show() gg.histplot(noise).show() gg.histplot(measured).show()
import gaussguess as gg import gaussguess.plotter as plotter nbins = 11 stats = 1000 dists = [ gg.GaussDistribution(nbins, sigma=0.1), gg.GaussDistribution(nbins, sigma=1.0), gg.GaussDistribution(nbins, sigma=2.0, xlim=[0, 10]), gg.LaplaceDistribution(nbins, lam=0.1), gg.LaplaceDistribution(nbins, lam=1.2), gg.UniformDistribution(nbins), gg.UniformDistribution(3), gg.TriangularDistribution(nbins), gg.TriangularDistribution(nbins, center=0.4), gg.TriangularDistribution(47), gg.PoissonDistribution(nbins), gg.PoissonDistribution(nbins, lam=6, xlim=[0, 10]), ] for d in dists: result = d.sample(nentries=stats) plotter.histplot(result).show()
import gaussguess as gg NBINS = 21 signaldists = [ gg.GaussDistribution(NBINS, sigma=0.05), gg.GaussDistribution(NBINS, sigma=0.1), gg.GaussDistribution(NBINS, sigma=0.15), gg.GaussDistribution(NBINS, sigma=0.2), gg.GaussDistribution(NBINS, sigma=0.25), gg.GaussDistribution(NBINS, sigma=0.3), gg.GaussDistribution(NBINS, sigma=0.4), gg.GaussDistribution(NBINS, sigma=2.0, xlim=[0, 10]), ] backgrounddists = [ gg.LaplaceDistribution(NBINS, lam=0.1), gg.LaplaceDistribution(NBINS, lam=1.2), gg.UniformDistribution(NBINS), gg.TriangularDistribution(NBINS), gg.TriangularDistribution(NBINS, center=0.4), gg.TriangularDistribution(NBINS, center=0.3), gg.TriangularDistribution(NBINS, center=0.8), gg.PoissonDistribution(NBINS), gg.PoissonDistribution(NBINS, lam=6, xlim=[0, 10]), ] classifier = gg.DistributionBinaryClassifier(NBINS) classifier.generatedata(signaldists, backgrounddists, nloops=50000,
import gaussguess as gg NTRUE = 100000 NFALSE = 100000 NBINS = 5 SIGMA = 1.0 STATS = 100 counter = 0 with open('samples_size{}.csv'.format(NBINS), 'wt') as csv: csv.write("index,sigma,stats,isgauss,{}\n".format(",".join( ["bin{}".format(i) for i in range(NBINS)]))) for _ in range(NTRUE): signal = gg.GaussDistribution(NBINS, sigma=SIGMA).sample(nentries=STATS) csv.write("{},{},{},{}".format(counter, SIGMA, STATS, 1)) for v in signal.values: csv.write(",{:.15e}".format(v)) csv.write("\n") counter += 1 for _ in range(NTRUE): background = gg.UniformDistribution(NBINS).sample(nentries=STATS) csv.write("{},{},{},{}".format(counter, SIGMA, STATS, 0)) for v in background.values: csv.write(",{:.15e}".format(v)) csv.write("\n") counter += 1
import gaussguess as gg NBINS = 111 classes = ["gauss", "uniform", "triangular", "laplace", "poisson"] iclasses = range(len(classes)) getlabel = lambda name: iclasses[classes.index(name)] labeled_data = [ (getlabel("gauss"), gg.GaussDistribution(NBINS, sigma=0.05)), (getlabel("gauss"), gg.GaussDistribution(NBINS, sigma=0.10)), (getlabel("gauss"), gg.GaussDistribution(NBINS, sigma=0.15)), (getlabel("gauss"), gg.GaussDistribution(NBINS, sigma=0.75)), (getlabel("gauss"), gg.GaussDistribution(NBINS, sigma=0.20)), (getlabel("gauss"), gg.GaussDistribution(NBINS, sigma=0.20)), (getlabel("laplace"), gg.LaplaceDistribution(NBINS, lam=0.1)), (getlabel("laplace"), gg.LaplaceDistribution(NBINS, lam=0.12)), (getlabel("laplace"), gg.LaplaceDistribution(NBINS, lam=0.052)), (getlabel("uniform"), gg.UniformDistribution(NBINS)), (getlabel("uniform"), gg.UniformDistribution(NBINS)), (getlabel("uniform"), gg.UniformDistribution(NBINS)), (getlabel("uniform"), gg.UniformDistribution(NBINS)), (getlabel("triangular"), gg.TriangularDistribution(NBINS, center=0.1)), (getlabel("triangular"), gg.TriangularDistribution(NBINS, center=0.2)), (getlabel("triangular"), gg.TriangularDistribution(NBINS, center=0.5)), (getlabel("triangular"), gg.TriangularDistribution(NBINS, center=0.6)), (getlabel("triangular"), gg.TriangularDistribution(NBINS, center=0.99)), (getlabel("triangular"), gg.TriangularDistribution(NBINS, center=0.4)), (getlabel("poisson"), gg.PoissonDistribution(NBINS, lam=6, xlim=[0, 10])), (getlabel("poisson"), gg.PoissonDistribution(NBINS, lam=2, xlim=[0, 10])), (getlabel("poisson"), gg.PoissonDistribution(NBINS, lam=3, xlim=[0, 10])),