Commit 964b64b718edf9157a6341efa1511098dcc2cbfe

Authored by Jürgen Knödlseder
1 parent f636ce90

Add error computation step after optimization as error computation has been drop…

…ped from optimization method.
inst/cta/test/benchmark_ml_fitting.py
... ... @@ -64,8 +64,9 @@ def unbinned_analysis(model, evtfile, irf, caldb):
64 64 opt = gammalib.GOptimizerLM(log)
65 65 opt.eps(5.0e-3)
66 66  
67   - # Optimize model parameters
  67 + # Optimize model parameters and compute errors
68 68 obs.optimize(opt)
  69 + obs.errors(opt)
69 70  
70 71 # Print optimizer results
71 72 print(opt)
... ... @@ -121,8 +122,9 @@ def binned_analysis(model, cntmap, irf, caldb):
121 122 opt = gammalib.GOptimizerLM(log)
122 123 opt.eps(5.0e-3)
123 124  
124   - # Optimize model parameters
  125 + # Optimize model parameters and compute errors
125 126 obs.optimize(opt)
  127 + obs.errors(opt)
126 128  
127 129 # Print optimizer results
128 130 print(opt)
... ... @@ -180,8 +182,9 @@ def stacked_analysis(model, cntmap, expcube, psfcube):
180 182 opt = gammalib.GOptimizerLM(log)
181 183 opt.eps(5.0e-3)
182 184  
183   - # Optimize model parameters
  185 + # Optimize model parameters and compute errors
184 186 obs.optimize(opt)
  187 + obs.errors(opt)
185 188  
186 189 # Print optimizer results
187 190 print(opt)
... ...
inst/cta/test/example_binned_ml_fit.py
... ... @@ -62,8 +62,9 @@ def binned_analysis(model, cntmap, irf, caldb):
62 62 # Allocate Levenberg-Marquardt optimizer
63 63 opt = gammalib.GOptimizerLM()
64 64  
65   - # Optimize model parameters
  65 + # Optimize model parameters and compute errors
66 66 obs.optimize(opt)
  67 + obs.errors(opt)
67 68  
68 69 # Get maximum likelihood value
69 70 logL = -(opt.value())
... ... @@ -111,21 +112,21 @@ def binned_analysis(model, cntmap, irf, caldb):
111 112 return models
112 113  
113 114  
114   -# ======================= #
115   -# CTA cube-style analysis #
116   -# ======================= #
117   -def cube_analysis(model, cntmap, expcube, psfcube):
  115 +# ==================== #
  116 +# CTA stacked analysis #
  117 +# ==================== #
  118 +def stacked_analysis(model, cntmap, expcube, psfcube):
118 119 """
119   - Perform cube-style maximum likelihood fitting of CTA data using GammaLib
  120 + Perform stacked maximum likelihood fitting of CTA data using GammaLib
120 121 classes. The function performs two fits, one with the full model and
121 122 one with the background model only, to evaluate the Test Statistics
122 123 value of the source component.
123 124 """
124 125 # Dump header
125 126 print("")
126   - print("+===================================================+")
127   - print("| Cube-style maximum likelihood fitting of CTA data |")
128   - print("+===================================================+")
  127 + print("+================================================+")
  128 + print("| Stacked maximum likelihood fitting of CTA data |")
  129 + print("+================================================+")
129 130  
130 131 # Get start CPU time
131 132 tstart = time.clock()
... ... @@ -153,8 +154,9 @@ def cube_analysis(model, cntmap, expcube, psfcube):
153 154 # Allocate Levenberg-Marquardt optimizer
154 155 opt = gammalib.GOptimizerLM()
155 156  
156   - # Optimize model parameters
  157 + # Optimize model parameters and compute errors
157 158 obs.optimize(opt)
  159 + obs.errors(opt)
158 160  
159 161 # Get maximum likelihood value
160 162 logL = -(opt.value())
... ... @@ -207,7 +209,7 @@ def cube_analysis(model, cntmap, expcube, psfcube):
207 209 #==========================#
208 210 if __name__ == '__main__':
209 211 """
210   - Example illustrating a binned data analysis.
  212 + Example illustrating binned data analyses.
211 213 """
212 214 # Dump header
213 215 print("")
... ... @@ -227,8 +229,8 @@ if __name__ == '__main__':
227 229 # Perform binned analysis
228 230 results_binned = binned_analysis(model, cntmap, irf, gammalib.GCaldb(caldb))
229 231  
230   - # Perform cube-style analysis
231   - results_cube = cube_analysis(model, cntmap, expcube, psfcube)
  232 + # Perform stacked analysis
  233 + results_cube = stacked_analysis(model, cntmap, expcube, psfcube)
232 234  
233 235 # Print model results
234 236 #print(result)
... ...
inst/cta/test/test_likelihood_profile.py
... ... @@ -100,8 +100,9 @@ def compute_likelihood_profile(obs, parname="Radius", scale=1.0e-5, steps=10):
100 100 opt = gammalib.GOptimizerLM(log)
101 101 opt.eps(5.0e-3)
102 102  
103   - # Optimize model parameters
  103 + # Optimize model parameters and compute errors
104 104 obs.optimize(opt)
  105 + obs.errors(opt)
105 106  
106 107 # Log optimizer into console
107 108 print(opt)
... ...