evermore
Differentiable (binned) likelihoods in JAX.
Installation
python -m pip install evermore
From source:
git clone https://github.com/pfackeldey/evermore
cd evermore
python -m pip install .
Example - Model and Loss Definition
See more in examples/
evermore in a nutshell:
from typing import NamedTuple, TypeAlias
from flax import nnx
import jax
import jax.numpy as jnp
from jaxtyping import Array, Float, PyTree, Scalar
import evermore as evm
jax.config.update("jax_enable_x64", True)
# type defs
Hist1D: TypeAlias = Float[Array, "..."]
Hists1D: TypeAlias = dict[str, Hist1D]
Args: TypeAlias = tuple[
nnx.GraphDef,
nnx.State,
Hists1D,
Hist1D,
]
# define a simple model with two processes and two parameters
def model(params: PyTree, hists: Hists1D) -> Array:
mu_modifier = params.mu.scale()
syst_modifier = params.syst.scale_log_asymmetric(up=1.1, down=0.9)
return mu_modifier(hists["signal"]) + syst_modifier(hists["bkg"])
def loss(
dynamic: nnx.State,
args: Args,
) -> Float[Scalar, ""]:
graphdef, static, hists, observation = args
params = nnx.merge(graphdef, dynamic, static)
expectation = model(params, hists)
# Poisson NLL of the expectation and observation
log_likelihood = (
evm.pdf.PoissonContinuous(lamb=expectation).log_prob(observation).sum()
)
# Add parameter constraints from logpdfs
constraints = evm.loss.get_log_probs(params)
log_likelihood += evm.util.sum_over_leaves(constraints)
return -jnp.sum(log_likelihood)
# setup data
hists: Hists1D = {"signal": jnp.array([3.0]), "bkg": jnp.array([10.0])}
observation: Hist1D = jnp.array([15.0])
# define parameters, can be any PyTree of evm.Parameters
class Params(NamedTuple):
mu: evm.Parameter[Float[Scalar, ""]]
syst: evm.NormalParameter[Float[Scalar, ""]]
params = Params(mu=evm.Parameter(1.0), syst=evm.NormalParameter(0.0))
# split tree of parameters in a differentiable part and a static part
graphdef, dynamic, static = nnx.split(params, evm.filter.is_dynamic_parameter, ...)
args = (graphdef, static, hists, observation)
# Calculate negative log-likelihood/loss
loss_val = loss(dynamic, args)
# gradients of negative log-likelihood w.r.t. dynamic parameters
grads = nnx.grad(loss)(dynamic, args)
nnx.display(nnx.as_pure(grads))
# State({
# 'mu': Array(-0.46153846, dtype=float64, weak_type=True),
# 'syst': Array(-0.15436207, dtype=float64, weak_type=True)
# })
Contributing
See CONTRIBUTING.md for instructions on how to contribute.
License
Distributed under the terms of the BSD license.
Metadata
Release files for evermore 0.4.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| evermore-0.4.2.tar.gz | 152.1 kB | Without provenance | Details for evermore-0.4.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| evermore-0.4.2-py3-none-any.whl | Python 3 | none | any | Details for evermore-0.4.2-py3-none-any.whl |
Total release size: 178.0 kB
Release files / evermore-0.4.2.tar.gz
| Download URL | evermore-0.4.2.tar.gz |
|---|---|
| Size | 152.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ac8bda871a92e4f6291c30e498de3e75d8f7caeac11904c2889bf8b81c3d4e2f
|
|
BLAKE2b-256 checksum How to use checksums |
7c4dc656874017d8e7498873a82d83328887014411ca490634eb3af0b9396355
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / evermore-0.4.2-py3-none-any.whl
| Download URL | evermore-0.4.2-py3-none-any.whl |
|---|---|
| Size | 25.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4a6eed6dc0d964cf642e8c43b9135c27d245631b38b76c088bc981372c40f420
|
|
BLAKE2b-256 checksum How to use checksums |
93285e557643f7789aeb2aaf353cf5b900abe56b46d600449795294992b17557
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for evermore 0.4.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.