Exemple #1
0
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()
Exemple #2
0
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()
Exemple #3
0
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
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,
                        statsrange=[10, 10000],
                        trainingratio=0.8)
cb = gg.LossAndAccuracyCallback()
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])),
]

labels, dists = map(list, zip(*labeled_data))