Skip to content

Commit

Permalink
Add default Jupyter notebook example using MXNet backend
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewfeickert committed Feb 12, 2018
1 parent 9fd4d01 commit e6326dd
Showing 1 changed file with 96 additions and 0 deletions.
96 changes: 96 additions & 0 deletions examples/notebooks/example-mxnet.ipynb
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
}

0 comments on commit e6326dd

Please sign in to comment.