예제 #1
0
def test_errresults_limits_interval():
    """Missing an error limit"""
    d = Data1D('dx', [1, 2, 3], [4, 2, 2], [1.2, 0.9, 0.9])
    m = Const1D()
    m.c0 = 3
    f = fit.Fit(d, m, stat=Chi2())
    er = f.est_errors()

    # perhaps should just fake this instead?
    assert len(er.parmaxes) == 1
    er.parmaxes = ([0.1, 0.2], )

    r = er._repr_html_()

    assert r is not None

    print(r)

    assert '<summary>covariance 1&#963; (68.2689%) bounds</summary>' in r
    assert '<summary>Summary (2)' in r
    assert '<td>const1d.c0</td>' in r
    assert '<div class="dataname">Fitting Method</div><div class="dataval">levmar</div>' in r
    assert '<div class="dataname">Statistic</div><div class="dataval">chi2</div>' in r

    assert '<tr><td>const1d.c0</td><td>           3</td><td>   -0.562226</td><td>(1.000000e-01, 2.000000e-01)</td></tr>' in r
예제 #2
0
def test_fitresults_multi(method):
    """Fit multiple datasets"""

    d1 = Data1D('dx', [1, 2, 3], [4, 2, 2])
    d2 = Data1D('dx', [4, 5, 6, 10], [4, 4, 2, 4])
    d = DataSimulFit('combined', (d1, d2))

    m1 = Const1D()
    m1.c0 = 3
    m = SimulFitModel('silly', (m1, m1))

    fr = fit.Fit(d, m, method=method(), stat=LeastSq()).fit()
    fr.datasets = ['ddx', 'ddy']
    r = fr._repr_html_()

    assert r is not None

    assert '<summary>Summary (9)</summary>' in r
    assert '<td>const1d.c0</td>' in r

    assert '<div class="dataname">Datasets</div><div class="dataval">ddx,ddy</div>' in r
    assert '<div class="dataname">Method</div><div class="dataval">{}</div>'.format(fr.methodname) in r
    assert '<div class="dataname">Statistic</div><div class="dataval">leastsq</div>' in r

    assert '<div class="dataname">&#916; statistic</div><div class="dataval">0.142857</div>' in r
    assert '<div class="dataname">Number of data points</div><div class="dataval">7</div>' in r
    assert '<div class="dataname">Degrees of freedom</div><div class="dataval">6</div>' in r
예제 #3
0
def test_errresults():
    d = Data1D('dx', [1, 2, 3], [4, 2, 2], [1.2, 0.9, 0.9])
    m = Const1D()
    m.c0 = 3
    f = fit.Fit(d, m, stat=Chi2())
    er = f.est_errors()
    r = er._repr_html_()

    assert r is not None

    assert '<summary>covariance 1&#963; (68.2689%) bounds</summary>' in r
    assert '<summary>Summary (2)' in r
    assert '<td>const1d.c0</td>' in r
    assert '<div class="dataname">Fitting Method</div><div class="dataval">levmar</div>' in r
    assert '<div class="dataname">Statistic</div><div class="dataval">chi2</div>' in r

    assert '<tr><td>const1d.c0</td><td>           3</td><td>   -0.562226</td><td>    0.562226</td></tr>' in r
예제 #4
0
def test_fitresults(method):
    d = Data1D('dx', [1, 2, 3], [4, 2, 2])
    m = Const1D()
    m.c0 = 3
    fr = fit.Fit(d, m, method=method(), stat=LeastSq()).fit()
    r = fr._repr_html_()

    assert r is not None

    assert '<summary>Fit parameters</summary>' in r
    assert '<summary>Summary (8)' in r
    assert '<td>const1d.c0</td>' in r

    assert '<div class="dataname">Method</div><div class="dataval">{}</div>'.format(fr.methodname) in r
    assert '<div class="dataname">Statistic</div><div class="dataval">leastsq</div>' in r

    assert '<div class="dataname">&#916; statistic</div><div class="dataval">0.333333</div>' in r
    assert '<div class="dataname">Number of data points</div><div class="dataval">3</div>' in r
    assert '<div class="dataname">Degrees of freedom</div><div class="dataval">2</div>' in r
예제 #5
0
def test_fitresults_chisq():
    d = Data1D('dx', [1, 2, 3], [4, 2, 2], [1.2, 1.4, 1.4])
    m = Const1D()
    m.c0 = 3
    fr = fit.Fit(d, m, method=LevMar(), stat=Chi2()).fit()
    r = fr._repr_html_()

    assert r is not None

    assert '<summary>Fit parameters</summary>' in r
    assert '<summary>Summary (10)</summary>' in r
    assert '<td>const1d.c0</td>' in r

    assert '<div class="dataname">Method</div><div class="dataval">{}</div>'.format(fr.methodname) in r
    assert '<div class="dataname">Final statistic</div><div class="dataval">1.65289</div>' in r

    assert '<div class="dataname">Reduced statistic</div><div class="dataval">0.826446</div>' in r
    assert '<div class="dataname">Probability (Q-value)</div><div class="dataval">0.437602</div>' in r

    assert '<div class="dataname">Number of data points</div><div class="dataval">3</div>' in r
    assert '<div class="dataname">Degrees of freedom</div><div class="dataval">2</div>' in r
예제 #6
0
def test_errresults_multi():
    d1 = Data1D('dx', [1, 2, 3], [4, 2, 2], [1.2, 0.9, 0.9])
    d2 = Data1D('dx', [10, 11, 12, 13], [4, 4, 2, 4], [0.8, 1.1, 1.1, 0.9])
    d = DataSimulFit('combined', (d1, d2))

    m1 = Const1D()
    m1.c0 = 3
    m = SimulFitModel('silly', (m1, m1))

    f = fit.Fit(d, m, stat=Chi2())
    er = f.est_errors()
    r = er._repr_html_()

    assert r is not None

    assert '<summary>covariance 1&#963; (68.2689%) bounds</summary>' in r
    assert '<summary>Summary (2)' in r
    assert '<td>const1d.c0</td>' in r
    assert '<div class="dataname">Fitting Method</div><div class="dataval">levmar</div>' in r
    assert '<div class="dataname">Statistic</div><div class="dataval">chi2</div>' in r

    assert '<tr><td>const1d.c0</td><td>           3</td><td>   -0.362415</td><td>    0.362415</td></tr>' in r
예제 #7
0
파일: combine.py 프로젝트: wsf1990/sherpa
g2.pos = g1.pos + 0.5
g1.fwhm = 0.1
g2.fwhm = 0.1

print(mdl)

ystart = mdl(x)

mplot = plot.ModelPlot()
mplot.prepare(d, mdl)

print(">>> dplot.plot()")
print(">>> mplot.plot(overplot=True)")
print(">>> save to _static/models/combine/model_combine_start.png")

f = fit.Fit(d, mdl, stats.LeastSq())
res = f.fit()
print(res.succeeded)

fplot = plot.FitPlot()
mplot.prepare(d, mdl)
fplot.prepare(dplot, mplot)
print(">>> fplot.plot()")
print(">>> plt.plot(x, ystart, label='Start')")
print(">>> plt.legend(loc=2)")
print(">>> save as docs/_static/models/combine/model_combine.png")

print(mdl)

for p in mdl.pars:
    if p.link is None: