Skip to main content

pure-Python HS3 implementation with tensors and autodiff

Project description

GitHub Project GitHub Discussion

Docs from latest Docs from main

PyPI version Conda-forge version Supported Python versions PyPI platforms

Code Coverage CodeFactor pre-commit.ci status Code style: black

Documentation Status GitHub Actions Status GitHub Actions Status: CI GitHub Actions Status: Docs GitHub Actions Status: Publish

Hello World

This is how you use the pyhs3 Python API to build a statistical model and evaluate a model:

>>> import pyhs3
>>> import scipy
>>> import math
>>> workspace_data = {
...     "distributions": [
...         {
...             "name": "model",
...             "type": "gaussian_dist",
...             "x": "x",
...             "mean": "mu",
...             "sigma": "sigma",
...         }
...     ],
...     "parameter_points": [
...         {
...             "name": "default_values",
...             "parameters": [
...                 {"name": "x", "value": 0.0},
...                 {"name": "mu", "value": 0.0},
...                 {"name": "sigma", "value": 1.0},
...             ],
...         }
...     ],
...     "domains": [
...         {
...             "name": "default_domain",
...             "type": "product",
...             "axes": [
...                 {"name": "x", "min": -5.0, "max": 5.0},
...                 {"name": "mu", "min": -2.0, "max": 2.0},
...                 {"name": "sigma", "min": 0.1, "max": 3.0},
...             ],
...         }
...     ],
... }
>>> ws = pyhs3.Workspace(workspace_data)
>>> model = ws.model()
<BLANKLINE>
>>> print(model)
Model(
    mode: FAST_RUN
    parameters: 3 (x, mu, sigma)
    distributions: 1 (model)
    functions: 0 ()
)
>>> parameters = {par.name: par.value for par in model.parameterset}
>>> result = -2 * model.logpdf("model", **parameters)
>>> print(f"parameters: {parameters}")
parameters: {'x': 0.0, 'mu': 0.0, 'sigma': 1.0}
>>> print(f"nll: {result:.8f}")
nll: 1.83787707
>>> result_scipy = -2 * math.log(scipy.stats.norm.pdf(0, loc=0, scale=1))
>>> print(f"nll: {result_scipy:.8f}")
nll: 1.83787707

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyhs3-0.2.0.tar.gz (56.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyhs3-0.2.0-py3-none-any.whl (36.3 kB view details)

Uploaded Python 3

File details

Details for the file pyhs3-0.2.0.tar.gz.

File metadata

  • Download URL: pyhs3-0.2.0.tar.gz
  • Upload date:
  • Size: 56.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyhs3-0.2.0.tar.gz
Algorithm Hash digest
SHA256 43828becec7abb8feee07a2d2688fd9cb945cad5f8bb5f237d15a749a34f9846
MD5 5274f4578014fbe9bb31dd43ed5036bd
BLAKE2b-256 c5ccd759e361a1502874b23ea08ed6ae2b9ad41ec5eee7d45ec7e6eec5e89e72

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyhs3-0.2.0.tar.gz:

Publisher: cd.yml on scipp-atlas/pyhs3

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyhs3-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pyhs3-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 36.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyhs3-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 195fffed4488baf02d2a69d31a629576d0363abefd89f69b8d7dcc2c2869ea40
MD5 5c6e8cf339ccc3823f31059c44f51ebb
BLAKE2b-256 99a441b85f00f3776387d1b2ae2f7babc504bec88ab15f0fc82555018e34839f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyhs3-0.2.0-py3-none-any.whl:

Publisher: cd.yml on scipp-atlas/pyhs3

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page