From 964b64b718edf9157a6341efa1511098dcc2cbfe Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Thu, 30 Oct 2014 10:07:32 +0100 Subject: [PATCH] Add error computation step after optimization as error computation has been dropped from optimization method. --- inst/cta/test/benchmark_ml_fitting.py | 9 ++++++--- inst/cta/test/example_binned_ml_fit.py | 28 +++++++++++++++------------- inst/cta/test/test_likelihood_profile.py | 3 ++- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/inst/cta/test/benchmark_ml_fitting.py b/inst/cta/test/benchmark_ml_fitting.py index cb6049a..e3199c6 100755 --- a/inst/cta/test/benchmark_ml_fitting.py +++ b/inst/cta/test/benchmark_ml_fitting.py @@ -64,8 +64,9 @@ def unbinned_analysis(model, evtfile, irf, caldb): opt = gammalib.GOptimizerLM(log) opt.eps(5.0e-3) - # Optimize model parameters + # Optimize model parameters and compute errors obs.optimize(opt) + obs.errors(opt) # Print optimizer results print(opt) @@ -121,8 +122,9 @@ def binned_analysis(model, cntmap, irf, caldb): opt = gammalib.GOptimizerLM(log) opt.eps(5.0e-3) - # Optimize model parameters + # Optimize model parameters and compute errors obs.optimize(opt) + obs.errors(opt) # Print optimizer results print(opt) @@ -180,8 +182,9 @@ def stacked_analysis(model, cntmap, expcube, psfcube): opt = gammalib.GOptimizerLM(log) opt.eps(5.0e-3) - # Optimize model parameters + # Optimize model parameters and compute errors obs.optimize(opt) + obs.errors(opt) # Print optimizer results print(opt) diff --git a/inst/cta/test/example_binned_ml_fit.py b/inst/cta/test/example_binned_ml_fit.py index 3eb4008..c4266d7 100755 --- a/inst/cta/test/example_binned_ml_fit.py +++ b/inst/cta/test/example_binned_ml_fit.py @@ -62,8 +62,9 @@ def binned_analysis(model, cntmap, irf, caldb): # Allocate Levenberg-Marquardt optimizer opt = gammalib.GOptimizerLM() - # Optimize model parameters + # Optimize model parameters and compute errors obs.optimize(opt) + obs.errors(opt) # Get maximum likelihood value logL = -(opt.value()) @@ -111,21 +112,21 @@ def binned_analysis(model, cntmap, irf, caldb): return models -# ======================= # -# CTA cube-style analysis # -# ======================= # -def cube_analysis(model, cntmap, expcube, psfcube): +# ==================== # +# CTA stacked analysis # +# ==================== # +def stacked_analysis(model, cntmap, expcube, psfcube): """ - Perform cube-style maximum likelihood fitting of CTA data using GammaLib + Perform stacked maximum likelihood fitting of CTA data using GammaLib classes. The function performs two fits, one with the full model and one with the background model only, to evaluate the Test Statistics value of the source component. """ # Dump header print("") - print("+===================================================+") - print("| Cube-style maximum likelihood fitting of CTA data |") - print("+===================================================+") + print("+================================================+") + print("| Stacked maximum likelihood fitting of CTA data |") + print("+================================================+") # Get start CPU time tstart = time.clock() @@ -153,8 +154,9 @@ def cube_analysis(model, cntmap, expcube, psfcube): # Allocate Levenberg-Marquardt optimizer opt = gammalib.GOptimizerLM() - # Optimize model parameters + # Optimize model parameters and compute errors obs.optimize(opt) + obs.errors(opt) # Get maximum likelihood value logL = -(opt.value()) @@ -207,7 +209,7 @@ def cube_analysis(model, cntmap, expcube, psfcube): #==========================# if __name__ == '__main__': """ - Example illustrating a binned data analysis. + Example illustrating binned data analyses. """ # Dump header print("") @@ -227,8 +229,8 @@ if __name__ == '__main__': # Perform binned analysis results_binned = binned_analysis(model, cntmap, irf, gammalib.GCaldb(caldb)) - # Perform cube-style analysis - results_cube = cube_analysis(model, cntmap, expcube, psfcube) + # Perform stacked analysis + results_cube = stacked_analysis(model, cntmap, expcube, psfcube) # Print model results #print(result) diff --git a/inst/cta/test/test_likelihood_profile.py b/inst/cta/test/test_likelihood_profile.py index 363a7b9..224c972 100755 --- a/inst/cta/test/test_likelihood_profile.py +++ b/inst/cta/test/test_likelihood_profile.py @@ -100,8 +100,9 @@ def compute_likelihood_profile(obs, parname="Radius", scale=1.0e-5, steps=10): opt = gammalib.GOptimizerLM(log) opt.eps(5.0e-3) - # Optimize model parameters + # Optimize model parameters and compute errors obs.optimize(opt) + obs.errors(opt) # Log optimizer into console print(opt) -- libgit2 0.21.4