示例#1
0
from   hep.cernlib.minuit import maximumLikelihoodFit
from   hep.test import compare
from   math import exp
from   random import random

#-----------------------------------------------------------------------
# test
#-----------------------------------------------------------------------

# The PDF for the test distribution.
def pdf(a, b, x, y):
    return a * b * exp(a * x + b * y) / ((exp(a) - 1) * (exp(b) - 1))


# Use acceptance-rejection to construct a sample from this PDF.
samples = []
pdf_max = pdf(3, 1, 1, 1)
while len(samples) < 1000:
    x = random()
    y = random()
    if (pdf_max * random() < pdf(3, 1, x, y)):
        samples.append({"x": x, "y": y})

result = maximumLikelihoodFit(pdf, (("a", 3), ("b", 1)), samples)
print result

compare(result.minuit_status, 3)
compare(result.values["a"], 3, precision=0.5)
compare(result.values["b"], 1, precision=0.5)
示例#2
0
#-----------------------------------------------------------------------
# imports
#-----------------------------------------------------------------------

from   hep.cernlib.minuit import maximumLikelihoodFit
import hep.table
from   hep.test import compare
import random

#-----------------------------------------------------------------------
# test
#-----------------------------------------------------------------------

schema = hep.table.Schema()
schema.addColumn("x", "float32")
table = hep.table.create("minuit-umlfit2.table", schema)
for i in xrange(100):
    table.append(x=random.normalvariate(3, 1))

result = maximumLikelihoodFit(
    "gaussian(mu, sigma, x)", (("mu", 0), ("sigma", 10, 0.1, 0, 1000)),
    table)
print result

compare(result.minuit_status, 3)
compare(result.values["mu"], 3, precision=0.3)
compare(result.values["sigma"], 1, precision=0.3)
示例#3
0
#-----------------------------------------------------------------------
# imports
#-----------------------------------------------------------------------

from   hep.cernlib.minuit import maximumLikelihoodFit
from   hep.test import compare
import random

#-----------------------------------------------------------------------
# test
#-----------------------------------------------------------------------

result = maximumLikelihoodFit(
    "gaussian(mu, sigma, x)", (("mu", 0), ("sigma", 10, 0.1, 0, 100)),
    [ {"x": random.normalvariate(3, 1)} for i in xrange(100) ])

compare(result.minuit_status, 3)
compare(result.values["mu"], 3, precision=0.3)
compare(result.values["sigma"], 1, precision=0.3)
示例#4
0
from   math import exp
from   random import random

#-----------------------------------------------------------------------
# test
#-----------------------------------------------------------------------

# The PDF for the test distribution; not normalized.
def pdf(a, b, x):
    return a + exp(b * x)


# Use acceptance-rejection to construct a sample from this PDF.
samples = []
pdf_max = pdf(1, 3, 1)
while len(samples) < 10000:
    x = random()
    if pdf_max * random() < pdf(1, 3, x):
        samples.append({ "x": x })

result = maximumLikelihoodFit(
    pdf,
    (("a", 2, 0.1, 0, 1000), ("b", 2, 0.1, 0, 10)),
    samples,
    normalization_range=(("x", 0, 1), ))
print result

compare(result.minuit_status, 3)
compare(result.values["a"], 1, precision=1.0)
compare(result.values["b"], 3, precision=1.0)