Skip to content

Commit

Permalink
enh: add disjoin pdf example in upgrade guide
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-eschle committed Apr 15, 2024
1 parent b16c580 commit 169ee40
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 44 deletions.
82 changes: 60 additions & 22 deletions _website/tutorials/introduction/upgrade_guide_020.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,11 @@
"cell_type": "code",
"execution_count": null,
"id": "19",
"metadata": {},
"metadata": {
"jupyter": {
"is_executing": true
}
},
"outputs": [],
"source": [
"# create a PDF\n",
Expand All @@ -259,7 +263,29 @@
"cell_type": "code",
"execution_count": null,
"id": "20",
"metadata": {},
"metadata": {
"jupyter": {
"is_executing": true
}
},
"outputs": [],
"source": [
"# a truncated PDF can also have multiple limits, replacing the MultiSpace concept\n",
"range1 = zfit.Space('obs1', -0.9, -0.1, label=\"lower range\") # an excellent use-case of a label\n",
"range2 = zfit.Space('obs1', 0.3, 0.5, label=\"upper range\")\n",
"pdf_disjoint = pdf.to_truncated(limits=(range1, range2))\n",
"pdf_disjoint.plot.plotpdf()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "21",
"metadata": {
"jupyter": {
"is_executing": true
}
},
"outputs": [],
"source": [
"# binned pdfs from space work like the data\n",
Expand All @@ -269,8 +295,12 @@
{
"cell_type": "code",
"execution_count": null,
"id": "21",
"metadata": {},
"id": "22",
"metadata": {
"jupyter": {
"is_executing": true
}
},
"outputs": [],
"source": [
"# as mentioned before, PDFs can be evaluated directly on numpy arrays or pandas DataFrames\n",
Expand All @@ -279,7 +309,7 @@
},
{
"cell_type": "markdown",
"id": "22",
"id": "23",
"metadata": {},
"source": [
"## Loss and minimizer\n",
Expand All @@ -299,8 +329,12 @@
{
"cell_type": "code",
"execution_count": null,
"id": "23",
"metadata": {},
"id": "24",
"metadata": {
"jupyter": {
"is_executing": true
}
},
"outputs": [],
"source": [
"loss = zfit.loss.ExtendedUnbinnedNLL(model=pdf, data=data2_obs1.to_pandas())\n",
Expand All @@ -312,8 +346,12 @@
{
"cell_type": "code",
"execution_count": null,
"id": "24",
"metadata": {},
"id": "25",
"metadata": {
"jupyter": {
"is_executing": true
}
},
"outputs": [],
"source": [
"result = minimizer.minimize(loss).update_params()\n",
Expand All @@ -322,7 +360,7 @@
},
{
"cell_type": "markdown",
"id": "25",
"id": "26",
"metadata": {},
"source": [
"## Result\n",
Expand All @@ -335,7 +373,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "26",
"id": "27",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -348,7 +386,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "27",
"id": "28",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -359,7 +397,7 @@
},
{
"cell_type": "markdown",
"id": "28",
"id": "29",
"metadata": {},
"source": [
"## Serialization\n",
Expand All @@ -375,7 +413,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "29",
"id": "30",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -386,7 +424,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "30",
"id": "31",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -398,7 +436,7 @@
},
{
"cell_type": "markdown",
"id": "31",
"id": "32",
"metadata": {},
"source": [
"## Parameters as arguments\n",
Expand All @@ -411,7 +449,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "32",
"id": "33",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -426,7 +464,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "33",
"id": "34",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -449,7 +487,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "34",
"id": "35",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -462,7 +500,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "35",
"id": "36",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -485,7 +523,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "36",
"id": "37",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -496,7 +534,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "37",
"id": "38",
"metadata": {},
"outputs": [],
"source": []
Expand Down
Loading

0 comments on commit 169ee40

Please sign in to comment.