Skip to content

Commit

Permalink
Better ruff settings and adjustments, improvements to README (#871)
Browse files Browse the repository at this point in the history
- Use ruff to enforce pydocstyle
- Switch to standard line length of 88, adjust files 
- Improvements to README
  • Loading branch information
HDembinski authored Apr 25, 2023
1 parent 67ecf53 commit a0970dc
Show file tree
Hide file tree
Showing 14 changed files with 365 additions and 333 deletions.
17 changes: 14 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
.. image:: https://mybinder.org/badge_logo.svg
:target: https://mybinder.org/v2/gh/scikit-hep/iminuit/develop?filepath=doc%2Ftutorial

*iminuit* is a Jupyter-friendly Python interface for the *Minuit2* C++ library maintained by CERN's ROOT team.
``iminuit`` is a Jupyter-friendly Python interface for the ``Minuit2`` C++ library maintained by CERN's ROOT team.

Minuit was designed to minimise statistical cost functions, for likelihood and least-squares fits of parametric models to data. It provides the best-fit parameters and error estimates from likelihood profile analysis.

Expand All @@ -39,12 +39,22 @@ The iminuit package comes with additional features:
- Builtin cost functions for statistical fits

- Binned and unbinned maximum-likelihood
- Template fits with error propagation [H. Dembinski, A. Abldemotteleb, Eur.Phys.J.C 82 (2022) 11, 1043](https://doi.org/10.1140/epjc/s10052-022-11019-z)
- Non-linear regression with (optionally robust) weighted least-squares
- Gaussian penalty terms
- Cost functions can be combined by adding them: ``total_cost = cost_1 + cost_2``
- Support for SciPy minimisers as alternatives to Minuit's Migrad algorithm (optional)
- Support for Numba accelerated functions (optional)

Dependencies
------------

``iminuit`` is will always be a lean package which only depends on ``numpy``, but additional features are enabled if the following optional packages are installed
- ``matplotlib``: Visualization of fitted model for builtin cost functions
- ``ipywidgets``: Interactive fitting (also requires ``matplotlib``)
- ``scipy``: Compute Minos intervals for arbitrary confidence levels
- ``unicodeitplus``: Render names of model parameters in simple LaTeX as Unicode

Documentation
-------------

Expand Down Expand Up @@ -73,8 +83,9 @@ iminuit is intended to be used with a user-provided negative log-likelihood func
m.migrad() # run optimiser
m.hesse() # run covariance estimator
print(m.values) # x: 2, y: 3, z: 4
print(m.errors) # x: 1, y: 1, z: 1
.. image:: doc/_static/minuit_jupyter.png
:alt: Jupyter display of Minuit


Interactive fitting
-------------------
Expand Down
Binary file added doc/_static/minuit_jupyter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions doc/notebooks/basic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1067,10 +1067,11 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"The paramaters $a$ and $b$ are stronly anti-correlated, the numerical value of the correlation is shown in parentheses. The correlation is also highlighed by the blue color of the off-diagonal elements."
"The paramaters α and β are stronly anti-correlated, the numerical value of the correlation is shown in parentheses. The correlation is also highlighed by the blue color of the off-diagonal elements."
]
},
{
Expand Down Expand Up @@ -1562,7 +1563,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
"version": "3.9.16"
},
"nteract": {
"version": "0.12.3"
Expand Down
19 changes: 14 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ test = [
"tabulate",
"boost_histogram",
"resample",
"unicodeit"
"unicodeitplus"
]
doc = [
"sphinx~=5.3.0",
Expand All @@ -90,7 +90,19 @@ filterwarnings = [
]

[tool.ruff]
line-length = 90
select = ["E", "F", "D"]
extend-ignore = ["D203", "D212"]

[tool.ruff.pydocstyle]
convention = "numpy"

[tool.ruff.per-file-ignores]
"test_*.py" = ["B", "D"]
".ci/*.py" = ["D"]
"bench/*.py" = ["D"]
"doc/*.py" = ["D"]
"setup.py" = ["D"]
"cmake_ext.py" = ["D"]

[tool.mypy]
ignore_missing_imports = true
Expand All @@ -100,9 +112,6 @@ pretty = true
files = ["src"]
no_implicit_optional = false

[tool.pydocstyle]
convention = "numpy"

[tool.cibuildwheel]
# update skip when numpy wheels become available
skip = ["*-musllinux_*", "cp31?-win32", "cp31?-manylinux_i686"]
Expand Down
3 changes: 2 additions & 1 deletion src/iminuit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Jupyter-friendly Python interface for the Minuit2 library in C++.
"""
Jupyter-friendly Python interface for the Minuit2 library in C++.
Basic usage example::
Expand Down
30 changes: 3 additions & 27 deletions src/iminuit/_repr_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ def fmin(fm):
ff[2],
colspan=3,
style="text-align:center",
title="Total number of function and (optional) gradient evaluations",
title=(
"Total number of function and (optional) gradient evaluations"
),
),
),
tr(
Expand Down Expand Up @@ -316,29 +318,3 @@ def matrix(arr):
rows.append(tr(*cols))

return to_str(table(tr(td(), *[th(v) for v in names]), *rows))


# def _parse_latex(s):
# if s.startswith("$") and s.endswith("$"):
# with optional_module_for("displaying LaTeX"):
# from matplotlib.backends.backend_svg import RendererSVG
# from matplotlib.font_manager import FontProperties
# from io import StringIO

# fp = FontProperties(size=9)
# # get bounding box of rendered text
# r = RendererSVG(0, 0, StringIO())
# w, h, _ = r.get_text_width_height_descent(s, fp, ismath=True)

# with StringIO() as f:
# # render LaTeX as path
# r = RendererSVG(w, h, f)
# r.draw_text(r.new_gc(), 0, h, s, fp, angle=0, ismath=True)
# f.seek(0)
# svg = f.read()

# # strip preamble
# svg = svg[svg.index("<svg") + 4 :]
# return f'<svg role="img" style="fill:#f0f0f0" {svg}'

# return s
Loading

0 comments on commit a0970dc

Please sign in to comment.