Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request #96 from scikit-hep/eduardo-README
Browse files Browse the repository at this point in the history
README updated and matplotlib dependency made optional
  • Loading branch information
eduardo-rodrigues committed Nov 6, 2018
2 parents f569714 + 456cf9b commit ef9ccec
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ before_script:
install:
- pip install Cython
- pip install numpy
- pip install "matplotlib<=3.0.0"
- pip install matplotlib
- pip install iminuit
- pip install pytest pytest-cov pytest-mpl
- pip install flake8 pylint
Expand Down
48 changes: 35 additions & 13 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,19 +1,39 @@
.. -*- mode: rst -*-
.. image:: https://travis-ci.org/scikit-hep/probfit.png?branch=master
:target: https://travis-ci.org/scikit-hep/probfit
probfit
=======

.. image:: https://img.shields.io/pypi/v/probfit.svg
:target: https://pypi.python.org/pypi/probfit

probfit
-------
.. image:: https://zenodo.org/badge/DOI/10.5281/zenodo.1477853.svg
:target: https://doi.org/10.5281/zenodo.1477853

.. image:: https://travis-ci.org/scikit-hep/probfit.png?branch=master
:target: https://travis-ci.org/scikit-hep/probfit

*probfit* is a set of functions that helps you construct a complex fit. It's
intended to be used with `iminuit <http://iminuit.readthedocs.org/>`_. The
tool includes Binned/Unbinned Likelihood estimator, :math:`\chi^2` regression,
tool includes Binned/Unbinned Likelihood estimators, :math:`\chi^2` regression,
Binned :math:`\chi^2` estimator and Simultaneous fit estimator.
Various functors for manipulating PDF such as Normalization and
Convolution(with caching) and various builtin functions
normally used in B physics is also provided.
Various functors for manipulating PDFs such as Normalization and
Convolution (with caching) and various built-in functions
normally used in B physics are also provided.

Strict dependencies
-------------------

- `Python <http://docs.python-guide.org/en/latest/starting/installation/>`__ (2.7+, 3.4+)
- `Numpy <https://scipy.org/install.html>`__
- `iminuit <http://iminuit.readthedocs.org/>`_

Optional dependencies
---------------------

- `matplotlib <http://matplotlib.org/>`_ for the plotting functions

Getting started
---------------

.. code-block:: python
Expand All @@ -26,14 +46,16 @@ normally used in B physics is also provided.
minuit.migrad()
unbinned_likelihood.draw(minuit)
Documentation and Tutorial
--------------------------

* `MIT <http://opensource.org/licenses/MIT>`_ license (open source)
* `Documentation <http://probfit.readthedocs.org/>`_
* The tutorial is an IPython notebook that you can view online
`here <http://nbviewer.ipython.org/urls/raw.github.com/scikit-hep/probfit/master/tutorial/tutorial.ipynb>`_.
To run it locally: `cd tutorial; ipython notebook --pylab=inline tutorial.ipynb`.
* Dependencies:
- `iminuit <http://iminuit.readthedocs.org/>`_
- `numpy <http://www.numpy.org/>`_
- `matplotlib <http://matplotlib.org/>`_ (optional, for plotting)
* Developing probfit: see the `development page <http://probfit.readthedocs.io/en/latest/development.html>`_

License
-------

The package is licensed under the `MIT <http://opensource.org/licenses/MIT>`_ license (open source).
6 changes: 5 additions & 1 deletion probfit/costfunc.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ cimport cython
import numpy as np
cimport numpy as np
from libc.math cimport exp, pow, fabs, log, tgamma, lgamma, sqrt
from matplotlib import pyplot as plt
from . import plotting
from ._libstat cimport compute_nll, compute_chi2_f, compute_bin_chi2_f, \
csum, compute_bin_lh_f, integrate1d
Expand Down Expand Up @@ -101,6 +100,7 @@ cdef class SimultaneousFit:
:meth:`draw` for arguments.
"""
from matplotlib import pyplot as plt
ret = self.draw(m)
plt.show()
return ret
Expand Down Expand Up @@ -324,6 +324,7 @@ cdef class UnbinnedLH:
:meth:`draw` for arguments.
"""
from matplotlib import pyplot as plt
ret = self.draw(*arg, **kwd)
plt.show()
return ret
Expand Down Expand Up @@ -575,6 +576,7 @@ cdef class BinnedLH:
:meth:`draw` for arguments.
"""
from matplotlib import pyplot as plt
ret = self.draw(*arg, **kwd)
plt.show()
return ret
Expand Down Expand Up @@ -679,6 +681,7 @@ cdef class Chi2Regression:
:meth:`draw` for arguments.
"""
from matplotlib import pyplot as plt
ret = self.draw(*arg, **kwd)
plt.show()
return ret
Expand Down Expand Up @@ -827,6 +830,7 @@ cdef class BinnedChi2:
:meth:`draw` for arguments.
"""
from matplotlib import pyplot as plt
ret = self.draw(*arg, **kwd)
plt.show()
return ret
7 changes: 6 additions & 1 deletion probfit/oneshot.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import itertools as itt
import collections
import numpy as np
from matplotlib import pyplot as plt
from iminuit import Minuit
from .py23_compat import range
from .costfunc import UnbinnedLH, BinnedChi2, BinnedLH
Expand All @@ -24,6 +23,7 @@ def fit_uml(f, data, quiet=False, print_level=0, *arg, **kwd):
minuit.migrad()
if not minuit.migrad_ok() or not minuit.matrix_accurate():
if not quiet:
from matplotlib import pyplot as plt
plt.figure()
uml.show()
print(minuit.values)
Expand All @@ -49,6 +49,7 @@ def fit_binx2(f, data, bins=30, bound=None, print_level=0, quiet=False, *arg, **
minuit.migrad()
if not minuit.migrad_ok() or not minuit.matrix_accurate():
if not quiet:
from matplotlib import pyplot as plt
plt.figure()
uml.show()
print(minuit.values)
Expand Down Expand Up @@ -83,6 +84,7 @@ def fit_binlh(f, data, bins=30,
minuit.migrad()
if not minuit.migrad_ok() or not minuit.matrix_accurate():
if not quiet:
from matplotlib import pyplot as plt
plt.figure()
uml.show()
print(minuit.values)
Expand Down Expand Up @@ -114,6 +116,7 @@ def pprint_arg(vnames, value):


def try_uml(f, data, bins=40, fbins=1000, *arg, **kwd):
from matplotlib import pyplot as plt
fom = UnbinnedLH(f, data)
narg = f.func_code.co_argcount
vnames = f.func_code.co_varnames[1:narg]
Expand All @@ -139,6 +142,7 @@ def try_uml(f, data, bins=40, fbins=1000, *arg, **kwd):

def try_binlh(f, data, weights=None, bins=40, fbins=1000, show='both', extended=False,
bound=None, *arg, **kwd):
from matplotlib import pyplot as plt
if bound is None: bound = minmax(data)
fom = BinnedLH(f, data, extended=extended, bound=bound)
narg = f.func_code.co_argcount
Expand Down Expand Up @@ -171,6 +175,7 @@ def try_binlh(f, data, weights=None, bins=40, fbins=1000, show='both', extended=


def try_chi2(f, data, weights=None, bins=40, fbins=1000, show='both', *arg, **kwd):
from matplotlib import pyplot as plt
fom = BinnedChi2(f, data)
narg = f.func_code.co_argcount
vnames = f.func_code.co_varnames[1:narg]
Expand Down
24 changes: 23 additions & 1 deletion probfit/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
from math import sqrt, ceil, floor
from warnings import warn
import numpy as np
from matplotlib import pyplot as plt
from .nputil import mid, minmax, vector_apply
from .util import parse_arg, describe


def draw_simultaneous(self, minuit=None, args=None, errors=None, **kwds):
from matplotlib import pyplot as plt
numf = len(self.allf)
ret = []
numraw = sqrt(numf)
Expand Down Expand Up @@ -72,6 +72,8 @@ def draw_ulh(self, minuit=None, bins=100, ax=None, bound=None,
parmloc=(0.05, 0.95), nfbins=200, print_par=True, grid=True,
args=None, errors=None, parts=False, show_errbars='normal',
no_plot=False):
from matplotlib import pyplot as plt

data_ret = None
error_ret = None
total_ret = None
Expand Down Expand Up @@ -170,6 +172,8 @@ def draw_residual(x, y, yerr, xerr,
The matplotlib axis instance the plot was drawn on.
"""
from matplotlib import pyplot as plt

ax = plt.gca() if ax is None else ax

if show_errbars:
Expand All @@ -196,6 +200,8 @@ def draw_residual_ulh(self, minuit=None, bins=100, ax=None, bound=None,
parmloc=(0.05, 0.95), print_par=False,
args=None, errors=None, errbar_algo='normal', norm=False,
**kwargs):
from matplotlib import pyplot as plt

ax = plt.gca() if ax is None else ax

arg, error = _get_args_and_errors(self, minuit, args, errors)
Expand Down Expand Up @@ -237,6 +243,8 @@ def draw_residual_ulh(self, minuit=None, bins=100, ax=None, bound=None,

def draw_x2(self, minuit=None, ax=None, parmloc=(0.05, 0.95), print_par=True,
args=None, errors=None, grid=True, parts=False, no_plot=False):
from matplotlib import pyplot as plt

data_ret = None
error_ret = None
total_ret = None
Expand Down Expand Up @@ -289,6 +297,8 @@ def draw_x2(self, minuit=None, ax=None, parmloc=(0.05, 0.95), print_par=True,

def draw_x2_residual(self, minuit=None, ax=None, args=None, errors=None, grid=True,
norm=False):
from matplotlib import pyplot as plt

ax = plt.gca() if ax is None else ax

arg, error = _get_args_and_errors(self, minuit, args, errors)
Expand Down Expand Up @@ -319,6 +329,8 @@ def draw_x2_residual(self, minuit=None, ax=None, args=None, errors=None, grid=Tr
def draw_bx2(self, minuit=None, parmloc=(0.05, 0.95), nfbins=500, ax=None,
print_par=True, args=None, errors=None, parts=False, grid=True,
no_plot=False):
from matplotlib import pyplot as plt

data_ret = None
error_ret = None
total_ret = None
Expand Down Expand Up @@ -379,6 +391,8 @@ def draw_bx2(self, minuit=None, parmloc=(0.05, 0.95), nfbins=500, ax=None,
def draw_blh(self, minuit=None, parmloc=(0.05, 0.95),
nfbins=1000, ax=None, print_par=True, grid=True,
args=None, errors=None, parts=False, no_plot=False):
from matplotlib import pyplot as plt

data_ret = None
error_ret = None
total_ret = None
Expand Down Expand Up @@ -436,6 +450,8 @@ def draw_blh(self, minuit=None, parmloc=(0.05, 0.95),
def draw_residual_blh(self, minuit=None, parmloc=(0.05, 0.95),
ax=None, print_par=False, args=None, errors=None,
norm=False, **kwargs):
from matplotlib import pyplot as plt

ax = plt.gca() if ax is None else ax

arg, error = _get_args_and_errors(self, minuit, args, errors)
Expand Down Expand Up @@ -473,6 +489,8 @@ def draw_compare(f, arg, edges, data, errors=None, ax=None, grid=True, normed=Fa
"""
TODO: this needs to be rewritten
"""
from matplotlib import pyplot as plt

# arg is either map or tuple
ax = plt.gca() if ax is None else ax
arg = parse_arg(f, arg, 1) if isinstance(arg, dict) else arg
Expand Down Expand Up @@ -557,6 +575,8 @@ def draw_pdf_with_edges(f, arg, edges, ax=None, scale=1.0, density=True,


def draw_pdf_with_midpoints(f, arg, x, ax=None, scale=1.0, normed_pdf=False, no_plot=False, **kwds):
from matplotlib import pyplot as plt

ax = plt.gca() if ax is None and not no_plot else ax
arg = parse_arg(f, arg, 1) if isinstance(arg, dict) else arg
yf = vector_apply(f, x, *arg)
Expand Down Expand Up @@ -601,6 +621,8 @@ def draw_compare_hist(f, arg, data, bins=100, bound=None, ax=None, weights=None,
- **parts** draw parts of pdf. (Works with AddPdf and Add2PdfNorm).
Default False.
"""
from matplotlib import pyplot as plt

ax = plt.gca() if ax is None else ax
bound = minmax(data) if bound is None else bound
h, e = np.histogram(data, bins=bins, range=bound, weights=weights)
Expand Down
2 changes: 1 addition & 1 deletion probfit/toy.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from warnings import warn
import numpy as np
import numpy.random as npr
from matplotlib import pyplot as plt
from ._libstat import compute_cdf, invert_cdf, _vector_apply
from .util import describe
from .probfit_warnings import SmallIntegralWarning
Expand Down Expand Up @@ -62,6 +61,7 @@ def gen_toy(f, nsample, bound, accuracy=10000, quiet=True, **kwd):

if not quiet:
# move this to plotting
from matplotlib import pyplot as plt
plt.figure()
plt.title('comparison')
numbin = 100
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ def get_version():
install_requires=[
'setuptools',
'numpy',
'iminuit',
'matplotlib'
'iminuit'
],
classifiers=[
"Programming Language :: Python",
Expand Down

0 comments on commit ef9ccec

Please sign in to comment.