Skip to main content

Python bindings for the Ensmallen library.

Project description

pyensmallen: python bindings for the ensmallen library for numerical optimization

Lightweight python bindings for ensmallen library. Currently supports

  • L-BFGS, with intended use for optimisation of smooth objectives for m-estimation
  • ADAM (and variants with different step-size routines) - makes use of ensmallen's templatization.
  • Frank-Wolfe, with intended use for constrained optimization of smooth losses
    • constraints are either lp-ball (lasso, ridge, elastic-net) or simplex
  • (Generalized) Method of Moments estimation with ensmallen optimizers.
    • this uses ensmallen for optimization [and relies on jax for automatic differentiation to get gradients and jacobians]. This is the main use case for pyensmallen and is the reason for the bindings.
  • Estimator classes for linear, logistic, and Poisson regression with classical and robust inference for unregularized fits

See ensmallen docs for details. The notebooks/ directory walks through several statistical examples.

speed

pyensmallen is very fast. A comprehensive set of benchmarks is available in the benchmarks directory. The benchmarks are run on an intel 12th gen framework laptop. Benchmarks vary data size (sample size and number of covariates) and parametric family (linear, logistic, poisson) and compare pyensmallen with scipy and statsmodels (I initially also tried to keep cvxpy in the comparison set but it was far too slow to be in the running). At large data sizes, pyensmallen is roughly an order of magnitude faster than scipy, which in turn is an order of magnitude faster than statsmodels. So, a single statsmodels run takes around as long as a pyensmallen run that naively uses the nonparametric bootstrap for inference. This makes the bootstrap a viable option for inference in large data settings.

Installation:

Make sure your system has blas installed. On macos, this can be done via brew. Linux systems should have it installed by default. If you are using conda, you can install blas via conda-forge.

Then,

from pypi

uv pip install pyensmallen

from source

  1. Install armadillo and ensmallen for your system (build from source, or via conda-forge; I went with the latter)
  2. git clone this repository
  3. If you are using uv:
    • uv pip install --python .venv/bin/python meson meson-python ninja pybind11
    • uv pip install --python .venv/bin/python --no-build-isolation -e .
  4. If you are using vanilla pip in an activated environment:
    • python -m pip install meson meson-python ninja pybind11
    • python -m pip install --no-build-isolation -e .
  5. Profit? Or at least minimize loss?

full development environment

To install everything required to run tests and notebooks:

uv pip install --python .venv/bin/python meson meson-python ninja pybind11
uv pip install --python .venv/bin/python --no-build-isolation -e ".[full]"

Vanilla pip equivalent:

python -m pip install meson meson-python ninja pybind11
python -m pip install --no-build-isolation -e ".[full]"

The full extra includes the Python dependencies used by:

  • the test suite
  • GMM and autodiff examples
  • benchmark notebooks
  • plotting and notebook tooling

documentation

doc-generation

The repository includes a Quarto documentation site in docs/. The docs are built from three sources:

  • hand-written Quarto pages in docs/*.qmd
  • generated API reference pages in docs/reference/*.qmd, built from Python and pybind11 docstrings with quartodoc
  • executed notebook pages in docs/notebooks/*.ipynb

Use the render script instead of calling quarto render directly:

scripts/render_docs.sh

The script does the following:

  • uses the repository .venv as the Quarto Python runtime
  • forces JAX onto CPU so notebook execution is stable during docs builds
  • copies the tracked notebooks from notebooks/ into docs/notebooks/
  • runs quartodoc to regenerate the API reference pages from docstrings
  • runs quarto render docs to execute the notebooks and build the site

If you need the full docs toolchain first:

uv pip install --python .venv/bin/python meson meson-python ninja pybind11
uv pip install --python .venv/bin/python --no-build-isolation -e ".[full]"

The rendered site lands in docs/_site/. The generated API source pages land in docs/reference/.

from wheel

  • download the appropriate .whl for your system from the more recent release listed in Releases and run uv pip install ./pyensmallen... OR
  • copy the download url and run uv pip install https://github.com/apoorvalal/pyensmallen/releases/download/<version>/pyensmallen-<version>-<pyversion>-linux_x86_64.whl

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

pyensmallen-0.4.1.tar.gz (4.6 MB view details)

Uploaded Source

Built Distributions

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

pyensmallen-0.4.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (17.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pyensmallen-0.4.1-cp312-cp312-macosx_11_0_arm64.whl (8.4 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyensmallen-0.4.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (17.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pyensmallen-0.4.1-cp311-cp311-macosx_11_0_arm64.whl (8.4 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyensmallen-0.4.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (17.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pyensmallen-0.4.1-cp310-cp310-macosx_11_0_arm64.whl (8.4 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file pyensmallen-0.4.1.tar.gz.

File metadata

  • Download URL: pyensmallen-0.4.1.tar.gz
  • Upload date:
  • Size: 4.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyensmallen-0.4.1.tar.gz
Algorithm Hash digest
SHA256 5b609c969cb9a92152a12c492b8204056d0b77b860c4b31aa8e6cbcb9e4ce3a5
MD5 a88d943e4a2fffb2fbcba82f9546e688
BLAKE2b-256 da2535b393415cee045d68c5f5ecf567999d5f8b722ac73a691a6b203377493c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyensmallen-0.4.1.tar.gz:

Publisher: build.yml on apoorvalal/pyensmallen

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

File details

Details for the file pyensmallen-0.4.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyensmallen-0.4.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 917e6d43d2c023bfbe93c0a48032e38cdad2a7de08897187a55eb85ef9749ccf
MD5 4f442658f663cd869ff5929c2221675c
BLAKE2b-256 9c8bfe907906f66eb4fbd756d04d104cd62f4148883207a04a365ab7c6e2e2c7

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyensmallen-0.4.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build.yml on apoorvalal/pyensmallen

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

File details

Details for the file pyensmallen-0.4.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyensmallen-0.4.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f44e7d8e275d8bbdf5aeb769a3645d2e8397a9c9f684c93dfbd134cae3acf2d5
MD5 1f3b0e492574121a5b27e50e28310581
BLAKE2b-256 51b02c3d89c8479ccc4552e3449026f7950edfeee721086a73a3d993b966ecad

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyensmallen-0.4.1-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: build.yml on apoorvalal/pyensmallen

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

File details

Details for the file pyensmallen-0.4.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyensmallen-0.4.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2928a2a489616404b39f391242cfc39d0c14db2b8d6465ca90332ae883df4e9d
MD5 68c4e1aad8b26569c16b97a7d9a14cf2
BLAKE2b-256 fc4ffbcccff550d83162cf04f7b025826bd134ddcf4f112ec8102689099f8605

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyensmallen-0.4.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build.yml on apoorvalal/pyensmallen

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

File details

Details for the file pyensmallen-0.4.1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyensmallen-0.4.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 72842f78c28ab9b7ff3757a86728397305d76ac2150ccd09b31058947497ef80
MD5 d4160a67f8563550d7761d2137f3fed9
BLAKE2b-256 57bffb2c4b0a9080f9f5be046caa0e445e27c1bd2c9635aaa4da482b374a6c38

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyensmallen-0.4.1-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: build.yml on apoorvalal/pyensmallen

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

File details

Details for the file pyensmallen-0.4.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyensmallen-0.4.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 aca4a227de2a65fa37e2407b9631f52281255a91cc0dc64c37c8413034f6be0b
MD5 98151992eac4c834b4337bd8d9220f94
BLAKE2b-256 41a62c22cda3adaf150535686673f9e42f1c917f49fc8894af8a21a5c95244b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyensmallen-0.4.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build.yml on apoorvalal/pyensmallen

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

File details

Details for the file pyensmallen-0.4.1-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyensmallen-0.4.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 824a3a18b20280b170cd16a433d0d87227cdfba8c272b05bd3143b2e7f26a9ae
MD5 aabc8cbdf15fcabfb0ae0114a971aca0
BLAKE2b-256 bc7df4a24144dadd360e67eda2845e78b3798e70460c235bba1bad5d1d7ff033

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyensmallen-0.4.1-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: build.yml on apoorvalal/pyensmallen

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