|
299 | 299 | "source": [
|
300 | 300 | "## Weighted uncertainties\n",
|
301 | 301 | "\n",
|
302 |
| - "A weighted likelihood is technically not a likelihood anymore and the errors are not calculated correctly. However, the hesse method\n", |
303 |
| - "can be corrected for weights, which is done automatically as soon as the dataset is weighted.\n", |
| 302 | + "A weighted likelihood is technically not a likelihood anymore, and the errors are not calculated correctly. However, the hesse method\n", |
| 303 | + "can be corrected for weights, which is done automatically as soon as the dataset is weighted. The method for corrections can be specified using the `weightcorr` argument.\n", |
| 304 | + "There are two methods to calculate the weighted uncertainties:\n", |
| 305 | + " - `\"asymptotic\"` (default): The method used is the `asymptotically correct` yet computationally expensive method described in [Parameter uncertainties in weighted unbinned maximum likelihood fits](https://link.springer.com/article/10.1140/epjc/s10052-022-10254-8).\n", |
| 306 | + " - `\"effsize\"`: The method used is the `effective size` method scaling the covariance matrix by the effective size of the dataset. This method is computationally significantly cheaper but can be less accurate.\n", |
304 | 307 | "\n",
|
305 |
| - "The method used is the `asymptotically correct` yet computationally expensive method described in [Parameter uncertainties in weighted unbinned maximum likelihood fits](https://link.springer.com/article/10.1140/epjc/s10052-022-10254-8).\n", |
| 308 | + "To disable the corrections, set `weightcorr=False`.\n", |
306 | 309 | "\n",
|
307 |
| - "The computation involves the jacobian of each event that can be expensive to compute. Again, zfit offers the possibility to use the\n", |
| 310 | + "The `\"asymptotic\"` correction involves the calculation of the jacobian with respect to each event, which can be expensive to compute. Again, zfit offers the possibility to use the\n", |
308 | 311 | "autograd or the numerical jacobian."
|
309 | 312 | ]
|
310 | 313 | },
|
|
342 | 345 | "outputs": [],
|
343 | 346 | "source": [
|
344 | 347 | "with zfit.run.set_autograd_mode(True):\n",
|
345 |
| - " weighted_result.hesse(name=\"hesse autograd\")\n", |
346 |
| - " weighted_result.hesse(name=\"hesse autograd np\", method=\"hesse_np\")" |
| 348 | + " weighted_result.hesse(name=\"hesse autograd asy\", weightcorr=\"asymptotic\")\n", |
| 349 | + " weighted_result.hesse(name=\"hesse autograd np asy\", method=\"hesse_np\", weightcorr=\"asymptotic\")" |
347 | 350 | ]
|
348 | 351 | },
|
349 | 352 | {
|
|
353 | 356 | "outputs": [],
|
354 | 357 | "source": [
|
355 | 358 | "with zfit.run.set_autograd_mode(False):\n",
|
356 |
| - " weighted_result.hesse(name=\"hesse numeric\")\n", |
357 |
| - " weighted_result.hesse(name=\"hesse numeric np\", method=\"hesse_np\")" |
| 359 | + " weighted_result.hesse(name=\"hesse numeric asy\") # weightcorr=\"asymptotic\" is default\n", |
| 360 | + " weighted_result.hesse(name=\"hesse numeric np asy\", method=\"hesse_np\")" |
358 | 361 | ]
|
359 | 362 | },
|
360 | 363 | {
|
|
370 | 373 | "cell_type": "markdown",
|
371 | 374 | "metadata": {},
|
372 | 375 | "source": [
|
373 |
| - "As we can see, the errors are underestimated for the nuisance parameters using the minos method while the hesse method is correct." |
| 376 | + "As we can see, the errors are underestimated for the nuisance parameters using the minos method while the hesse method is correct.\n", |
| 377 | + "\n", |
| 378 | + "The `hesse` method can also be used with the `\"effsize\"` correction, which is computationally much cheaper or without any correction." |
| 379 | + ] |
| 380 | + }, |
| 381 | + { |
| 382 | + "cell_type": "code", |
| 383 | + "execution_count": null, |
| 384 | + "metadata": {}, |
| 385 | + "outputs": [], |
| 386 | + "source": [ |
| 387 | + "weighted_result.hesse(name=\"hesse autograd effsize\", weightcorr=\"effsize\")\n", |
| 388 | + "weighted_result.hesse(name=\"hesse numeric no corr\", weightcorr=False)" |
| 389 | + ] |
| 390 | + }, |
| 391 | + { |
| 392 | + "cell_type": "code", |
| 393 | + "execution_count": null, |
| 394 | + "metadata": {}, |
| 395 | + "outputs": [], |
| 396 | + "source": [ |
| 397 | + "print(weighted_result)" |
374 | 398 | ]
|
375 | 399 | },
|
376 | 400 | {
|
|
0 commit comments