Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hello world example and check to tests #215

Merged
merged 3 commits into from
Aug 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
- sudo apt-get -qq install pandoc
- pip install -U -q -e .[develop,tensorflow,mxnet,torch]
script:
- python -m doctest README.md
- cd docs && make html && cd -
- touch docs/_build/html/.nojekyll
deploy:
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@
The HistFactory p.d.f. template [[CERN-OPEN-2012-016](https://cds.cern.ch/record/1456844)] is per-se independent of its implementation in ROOT and sometimes, it's useful to be able to run statistical analysis outside
of ROOT, RooFit, RooStats framework.

This repo is a pure-python implementation of that statistical model for multi-bin histogram-based analysis and its interval estimation is based on the asymptotic formulas of "Asymptotic formulae for likelihood-based tests of new physics" [[arxiv:1007.1727](https://arxiv.org/abs/1007.1727)]. The aim is also to support modern computational graph libraries such as PyTorch and Tensorflow in order to make use of features such as autodifferentiation and GPU acceleration.
This repo is a pure-python implementation of that statistical model for multi-bin histogram-based analysis and its interval estimation is based on the asymptotic formulas of "Asymptotic formulae for likelihood-based tests of new physics" [[arxiv:1007.1727](https://arxiv.org/abs/1007.1727)]. The aim is also to support modern computational graph libraries such as PyTorch and TensorFlow in order to make use of features such as autodifferentiation and GPU acceleration.

## Hello World

```python
>>> import pyhf
>>> import pyhf.simplemodels
>>> p = pyhf.simplemodels.hepdata_like(signal_data=[12.,11.], bkg_data=[50.,52.], bkg_uncerts=[3.,7.])
>>> *_, CLs_obs,CLs_exp = pyhf.runOnePoint(1.0, [51, 48] + p.config.auxdata, p)
>>> print('obs: {} exp: {}'.format(CLs_obs, CLs_exp[2]))
obs: [0.05290116] exp: [0.06445521]
>>> import pyhf.utils
>>> pdf = pyhf.simplemodels.hepdata_like(signal_data=[12.,11.], bkg_data=[50.,52.], bkg_uncerts=[3.,7.])
>>> *_, CLs_obs,CLs_exp = pyhf.utils.runOnePoint(1.0, [51, 48] + pdf.config.auxdata, pdf)
>>> print('Observed: {} Expected: {}'.format(CLs_obs, CLs_exp[2]))
Observed: [0.05290116] Expected: [0.06445521]

```

## What does it support
Expand Down
1 change: 1 addition & 0 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Notebooks:
.. toctree::
:maxdepth: 2

examples/notebooks/hello-world.ipynb
examples/notebooks/binderexample/StatisticalAnalysis.ipynb
examples/notebooks/Recast.ipynb
examples/notebooks/ShapeFactor.ipynb
Expand Down
73 changes: 73 additions & 0 deletions docs/examples/notebooks/hello-world.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Hello World, `pyhf` style"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pyhf\n",
"import pyhf.simplemodels\n",
"import pyhf.utils"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Observed: [0.05290116] Expected: [0.06445521]\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/mcf/Code/GitHub/pyhf/pyhf/tensor/numpy_backend.py:82: RuntimeWarning: divide by zero encountered in log\n",
" return np.log(tensor_in)\n",
"/home/mcf/Code/GitHub/pyhf/pyhf/tensor/numpy_backend.py:126: RuntimeWarning: divide by zero encountered in log\n",
" return np.exp(n*np.log(lam)-lam-gammaln(n+1.))\n"
]
}
],
"source": [
"pdf = pyhf.simplemodels.hepdata_like(signal_data=[12.,11.], bkg_data=[50.,52.], bkg_uncerts=[3.,7.])\n",
"# *_, CLs_obs,CLs_exp = pyhf.utils.runOnePoint(1.0, [51, 48] + pdf.config.auxdata, pdf) # Python3\n",
"_, _, _, _, CLs_obs,CLs_exp = pyhf.utils.runOnePoint(1.0, [51, 48] + pdf.config.auxdata, pdf)\n",
"print('Observed: {} Expected: {}'.format(CLs_obs, CLs_exp[2]))"
]
}
],
"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
}
3 changes: 3 additions & 0 deletions tests/test_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ def test_notebooks(tmpdir):
'kernel_name': 'python{}'.format(sys.version_info.major)
}

pm.execute_notebook(
'docs/examples/notebooks/hello-world.ipynb', **common_kwargs)

pm.execute_notebook(
'docs/examples/notebooks/ShapeFactor.ipynb', **common_kwargs)
pm.execute_notebook('docs/examples/notebooks/multichannel-coupled-histo.ipynb',
Expand Down