mdl.c1.thaw() mdl.c2 = 0 mdl.c2.freeze() dump("f.fit()") report("mdl") stat1 = f.calc_stat() print("Statistic: order 1 = {:.3f} order 2 = {:.3f}".format(stat1, stat2)) mplot2 = ModelPlot() mplot2.prepare(d, mdl) mplot.plot() mplot2.overplot() savefig("model_comparison.png") xgrid = np.linspace(0, 20, 21) y1 = mdl(xgrid) mdl.c0 = res.parvals[0] mdl.c1 = 0 mdl.c2 = res.parvals[1] y2 = mdl(xgrid) plt.clf() plt.plot(xgrid, y2, label='order=2') plt.plot(xgrid, y1, label='order=1') plt.legend(); plt.title("Manual evaluation of the models") savefig("model_comparison_manual.png")
report("mdl([-100])") report("mdl([234.56])") mdl.c1.thaw() mdl.c2 = 0 mdl.c2.freeze() dump("f.fit()") report("mdl") stat1 = f.calc_stat() print("Statistic: order 1 = {:.3f} order 2 = {:.3f}".format(stat1, stat2)) mplot2 = ModelPlot() mplot2.prepare(d, mdl) mplot.plot() mplot2.overplot() savefig("model_comparison.png") xgrid = np.linspace(0, 20, 21) y1 = mdl(xgrid) mdl.c0 = res.parvals[0] mdl.c1 = 0 mdl.c2 = res.parvals[1] y2 = mdl(xgrid) plt.clf() plt.plot(xgrid, y2, label='order=2') plt.plot(xgrid, y1, label='order=1') plt.legend() plt.title("Manual evaluation of the models") savefig("model_comparison_manual.png")
dplot.prepare(d) from sherpa.models.basic import Const1D, Exp plateau = Const1D('plateau') rise = Exp('rise') mdl = plateau / (1 + rise) report("mdl") rise.ampl.freeze() report("mdl") from sherpa.plot import ModelPlot mplot = ModelPlot() mplot.prepare(d, mdl) plt.subplot(2, 1, 1) mplot.plot(clearwindow=False) plt.subplot(2, 1, 2) dplot.plot(clearwindow=False) plt.title('') savefig("model_data_before_fit.png") from sherpa.stats import Chi2 from sherpa.fit import Fit f = Fit(d, mdl, stat=Chi2()) report("f") print("Starting statistic: {}".format(f.calc_stat())) fitres = f.fit() report("fitres.format()")