-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add default Jupyter notebook example using MXNet backend
- Loading branch information
1 parent
9fd4d01
commit e6326dd
Showing
1 changed file
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Populating the interactive namespace from numpy and matplotlib\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"%pylab inline" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import pyhf\n", | ||
"from pyhf import hfpdf\n", | ||
"from pyhf.simplemodels import hepdata_like\n", | ||
"import mxnet as mx" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"--------\n", | ||
"as MXNet\n", | ||
"--------\n", | ||
"<class 'mxnet.ndarray.ndarray.NDArray'> \n", | ||
"[-22.87784958]\n", | ||
"<NDArray 1 @cpu(0)>\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"source = {\n", | ||
" \"binning\": [2,-0.5,1.5],\n", | ||
" \"bindata\": {\n", | ||
" \"data\": [120.0, 180.0],\n", | ||
" \"bkg\": [100.0, 150.0],\n", | ||
" \"bkgerr\": [10.0, 10.0],\n", | ||
" \"sig\": [30.0, 95.0]\n", | ||
" }\n", | ||
"}\n", | ||
"\n", | ||
"pdf = hepdata_like(source['bindata']['sig'], source['bindata']['bkg'], source['bindata']['bkgerr'])\n", | ||
"data = source['bindata']['data'] + pdf.config.auxdata\n", | ||
"\n", | ||
"init_pars = pdf.config.suggested_init()\n", | ||
"par_bounds = pdf.config.suggested_bounds()\n", | ||
"\n", | ||
"\n", | ||
"print('--------\\nas MXNet\\n--------')\n", | ||
"pyhf.tensorlib = pyhf.mxnet_backend()\n", | ||
"v = pdf.logpdf(init_pars, data)\n", | ||
"print(type(v),v)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.6.4" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |