Skip to main content

Python port of nonlinear nonparametric statistics from R NNS

Project description

NNS Python

PyPI package Python License Status

ovvo-nns brings Nonlinear Nonparametric Statistics to Python as the nns import package. It is a parity-focused port of the R NNS 13.0 package, designed for real-world data that violate symmetry, linearity, or distributional assumptions.

NNS is built around partial moments, the lower and upper components of variance, and uses them across nonlinear dependence, correlation, causation, regression, classification, forecasting, stochastic dominance, stochastic superiority, Monte Carlo simulation, and numerical differentiation workflows.

NNS was created by Fred Viole as the companion R package to Viole, F. and Nawrocki, D. (2013), Nonlinear Nonparametric Statistics: Using Partial Moments. Book (2nd Edition): https://ovvo-financial.github.io/NNS/book/

Implementation: For a direct quantitative finance implementation of NNS, see OVVO Labs

Package at a glance

Item Value
Distribution package ovvo-nns
Import package nns
Current version 1.0.0a0
Python >=3.11
Required runtime dependencies NumPy, SciPy
R required at runtime No
Native acceleration Private, optional nns._nnscore kernels where available
Public API status Alpha, parity-focused
License GPL-3.0-only

The public package is Python-native and does not call R at runtime. Some core kernels can use the private _nnscore extension when it is present, while public functions keep Python implementations and explicit fallback behavior.

Install

pip install ovvo-nns

This includes the matplotlib plotting API (nns.plotting); matplotlib is a regular dependency and is imported lazily, so import nns stays light. See docs/plot_parity_policy.md.

Use the package as nns:

import nns

print(nns.__version__)

Source builds use scikit-build-core and nanobind for the optional native extension. Published wheels should be preferred when available.

Quick start

import numpy as np
from nns import lpm, nns_dep, nns_reg, upm

x = np.array([-2.0, -1.0, 0.5, 3.0], dtype=np.float64)

lower = lpm(degree=2, target=0.0, x=x)
upper = upm(degree=2, target=0.0, x=x)

print("lower partial moment:", lower)
print("upper partial moment:", upper)

Measure nonlinear dependence:

import numpy as np
from nns import nns_cor, nns_dep

grid = np.linspace(-2.0, 2.0, 80, dtype=np.float64)
y = grid**2

print("NNS dependence:", nns_dep(grid, y))
print("NNS correlation:", nns_cor(grid, y))

Fit a nonlinear regression and estimate new points:

import numpy as np
from nns import nns_reg

x = np.linspace(-3.0, 3.0, 80, dtype=np.float64)
y = np.sin(x) + 0.2 * x
points = np.array([-1.5, 0.0, 1.5], dtype=np.float64)

fit = nns_reg(x, y, point_est=points, confidence_interval=None)

print("R2:", fit["R2"])
print(np.column_stack((points, fit["Point.est"])))

Forecast a univariate series:

import numpy as np
from nns import nns_arma, nns_seas

t = np.arange(1, 60, dtype=np.float64)
series = 10.0 + np.sin(t / 3.0) + 0.05 * t

seasonality = nns_seas(series, modulo=[3, 4, 6], mod_only=True)
forecast = nns_arma(series, h=3, seasonal_factor=4, method="lin")

print("best seasonal period:", seasonality["best.period"])
print("forecast:", forecast)

Main API areas

Area Representative functions
Partial moments lpm, upm, lpm_ratio, upm_ratio, pm_matrix
Classical moment helpers mean_pm, var_pm, skew_pm, kurt_pm, nns_moments
Dependence, correlation, copula nns_dep, nns_cor, nns_copula
Causation nns_causation, causal_matrix
Regression and classification nns_reg, nns_m_reg, nns_stack, nns_boost
Forecasting nns_seas, nns_arma, nns_arma_optim, nns_var
Nowcast panels nns_nowcast_panel, CsvNowcastProvider
Distribution tools nns_cdf, nns_anova, nns_norm
Stochastic dominance fsd, ssd, tsd, nns_sd_cluster, sd_efficient_set
Stochastic superiority and simulation nns_ss, nns_mc, nns_meboot
Differentiation nns_diff, dy_dx, dy_d
Categorical helpers encode_factor_codes, factor_2_dummy, factor_2_dummy_fr, prepare_factor_predictors

See API status for implemented, partial, guarded, and known-gap paths.

Design boundaries

NNS Python prioritizes stable public behavior from installed R NNS 13.0, not private helper parity. The package returns NumPy arrays and plain dictionaries rather than R data.table objects, uses explicit Python errors for several unsafe R coercions, and generally ignores plotting side effects.

Important boundaries:

  • R is used only for parity tests and local cache regeneration, not normal runtime use.
  • Stochastic exact stream parity is not expected because Python paths use NumPy random generation.
  • Factor and class ordering should be passed explicitly when ordering matters.
  • Direct raw-factor nns_m_reg(..., factor_2_dummy=True) is intentionally guarded. Use prepare_factor_predictors(...) before nns_m_reg(...).
  • Compute functions still return values, not figures; passing plot=True (where R has it) additionally renders a Matplotlib figure as a side effect via the nns.plotting layer, which is color/element-faithful to R but not pixel-diffed. The plot functions can also be called directly on a computed result.

See behavior conventions for detailed compatibility notes.

Examples and notebooks

Runnable examples live in docs/examples:

Topic Script
Partial moments partial_moments.py
Dependence dependence.py
Distributions and ANOVA distributions_anova.py
Regression regression.py
Classification classification.py
Forecasting forecasting.py
Nowcast panel nowcast_panel.py

Run one example:

uv run python docs/examples/partial_moments.py

Run all script examples:

for example in docs/examples/*.py; do uv run python "$example"; done

Notebook workflows are also available under docs/examples/notebooks.

Documentation

Development

uv sync --group dev
uv run pytest
uv run ruff check .
uv run mypy

Run benchmark tests explicitly:

uv run pytest -n0 -m benchmark --benchmark-enable tests/benchmarks/

The default parity suite is cache-backed and does not require Rscript. Rscript and the R NNS package are needed only when regenerating parity caches or running live R comparison scripts.

Benchmarks

Benchmarks compare selected Python paths with installed R NNS 13.0 baselines. Many core operations are faster in Python, while some large stochastic-dominance workloads remain faster in R because the R package uses compiled kernels for those paths. See benchmarks for current measurements and commands.

Attribution

Upstream R package and reference implementation: OVVO-Financial/NNS

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

ovvo_nns-1.0.0.tar.gz (8.3 MB view details)

Uploaded Source

Built Distributions

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

ovvo_nns-1.0.0-cp313-cp313-win_amd64.whl (232.3 kB view details)

Uploaded CPython 3.13Windows x86-64

ovvo_nns-1.0.0-cp313-cp313-musllinux_1_2_x86_64.whl (730.0 kB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

ovvo_nns-1.0.0-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (270.4 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

ovvo_nns-1.0.0-cp313-cp313-macosx_11_0_arm64.whl (247.1 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

ovvo_nns-1.0.0-cp313-cp313-macosx_10_14_x86_64.whl (270.0 kB view details)

Uploaded CPython 3.13macOS 10.14+ x86-64

ovvo_nns-1.0.0-cp312-cp312-win_amd64.whl (232.3 kB view details)

Uploaded CPython 3.12Windows x86-64

ovvo_nns-1.0.0-cp312-cp312-musllinux_1_2_x86_64.whl (730.0 kB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

ovvo_nns-1.0.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (270.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

ovvo_nns-1.0.0-cp312-cp312-macosx_11_0_arm64.whl (247.2 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

ovvo_nns-1.0.0-cp312-cp312-macosx_10_14_x86_64.whl (270.0 kB view details)

Uploaded CPython 3.12macOS 10.14+ x86-64

ovvo_nns-1.0.0-cp311-cp311-win_amd64.whl (233.0 kB view details)

Uploaded CPython 3.11Windows x86-64

ovvo_nns-1.0.0-cp311-cp311-musllinux_1_2_x86_64.whl (730.4 kB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

ovvo_nns-1.0.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (270.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

ovvo_nns-1.0.0-cp311-cp311-macosx_11_0_arm64.whl (247.5 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

ovvo_nns-1.0.0-cp311-cp311-macosx_10_14_x86_64.whl (270.4 kB view details)

Uploaded CPython 3.11macOS 10.14+ x86-64

File details

Details for the file ovvo_nns-1.0.0.tar.gz.

File metadata

  • Download URL: ovvo_nns-1.0.0.tar.gz
  • Upload date:
  • Size: 8.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ovvo_nns-1.0.0.tar.gz
Algorithm Hash digest
SHA256 91e4a90e9da91b4422be5421fe84ab77d3e343bd39f3e84d7eb49869d05643c9
MD5 0290382ba411cc99893dfeb42e89b37c
BLAKE2b-256 dd99fe6725fe2a2ec05bcf3f6dfce5d194299866664f085362ccd9cca2814b75

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.0.tar.gz:

Publisher: release.yml on OVVO-Financial/NNS-python

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

File details

Details for the file ovvo_nns-1.0.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: ovvo_nns-1.0.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 232.3 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ovvo_nns-1.0.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 74b990037a840f0da45e0a1a1c0bab5a2ecdbf3a4fecc6613f14306e14b7bb06
MD5 becff1fc4a8291f030f49182e82a5171
BLAKE2b-256 7a68c95d48cb4d86f981f7eabb2f41b2c4495c9d170079da527bd9766f314e63

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.0-cp313-cp313-win_amd64.whl:

Publisher: release.yml on OVVO-Financial/NNS-python

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

File details

Details for the file ovvo_nns-1.0.0-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for ovvo_nns-1.0.0-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c30a227768f6e17c173da2d0fdbf10be74543ae80085dd084c72b05a0d15e10f
MD5 68226b287ed243928a83a36983ff7abb
BLAKE2b-256 af2713f659d9e31d339ec235d940e6424d1c2c6106d109e9dec5ea9ef3fa772d

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.0-cp313-cp313-musllinux_1_2_x86_64.whl:

Publisher: release.yml on OVVO-Financial/NNS-python

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

File details

Details for the file ovvo_nns-1.0.0-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for ovvo_nns-1.0.0-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 15b9c211de49937aab2a51d25f0bdf3bf694e4aa452b23c333832fb29039153c
MD5 b2dd56b83964ace56168500fbbded167
BLAKE2b-256 6e1357b51620b941271cf6c6a37b02f0e45310de1c4db806e2c55bc94b442da2

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.0-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on OVVO-Financial/NNS-python

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

File details

Details for the file ovvo_nns-1.0.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ovvo_nns-1.0.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a9dd3022804e2234c297e3bde9410ff44662dd34b84473a681810e05c659e97b
MD5 28faa05bd077b1e29a7954b4405fbbdc
BLAKE2b-256 209b935a9fc56798e9368645c76d984edeb0c6ad094d85dac9e47494b3dbabac

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.0-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: release.yml on OVVO-Financial/NNS-python

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

File details

Details for the file ovvo_nns-1.0.0-cp313-cp313-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for ovvo_nns-1.0.0-cp313-cp313-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 e5fb8e6c6c4a2a3f501544701de223bce49b38cfeaeb824df199d00576f2c5e9
MD5 2b0d90ba16864a25fe1ac985969c6af4
BLAKE2b-256 91b629d1664fdf6dd3739baf2805dbd175fd4fa49572f676091a6b447ee2ee94

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.0-cp313-cp313-macosx_10_14_x86_64.whl:

Publisher: release.yml on OVVO-Financial/NNS-python

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

File details

Details for the file ovvo_nns-1.0.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: ovvo_nns-1.0.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 232.3 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ovvo_nns-1.0.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 2ead953321f7194d7837a8cca40e1c7ace7623e668969d9d60047794d36a9d03
MD5 ed0fbbfff5465e0895b4e3e0e3c491aa
BLAKE2b-256 afb9ebb087ccdadcd66638fbfeec2f95f1f97fe789f77047115dba561fffb697

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.0-cp312-cp312-win_amd64.whl:

Publisher: release.yml on OVVO-Financial/NNS-python

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

File details

Details for the file ovvo_nns-1.0.0-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for ovvo_nns-1.0.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 a73419767f25c46292bcf52c82545f4c08cef712ca60d5a623246759a739af04
MD5 6bb2e5d53150d11de7b8f5a0a50e494a
BLAKE2b-256 2248726d95f3a2a7486d056a5ade2a707b93648857cf85f5a19cacfbd9a1ee67

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.0-cp312-cp312-musllinux_1_2_x86_64.whl:

Publisher: release.yml on OVVO-Financial/NNS-python

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

File details

Details for the file ovvo_nns-1.0.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for ovvo_nns-1.0.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a6f13d814aa868885831a8c9d50f6e65534ad77ee742b3698ab7996d5e4cbb81
MD5 45d9bc44f76f378632f48408f53cea82
BLAKE2b-256 fffe14e2f34b4c8d17c275d3e465774bd88da166a22a71feb91dc093b25cae3c

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on OVVO-Financial/NNS-python

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

File details

Details for the file ovvo_nns-1.0.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ovvo_nns-1.0.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 421378ec988b67282ba6cd528c96f4048ef27b2bc8cb54e0fea26b0a1abfef6a
MD5 10b813dca47be7ef9646dfac73adfae9
BLAKE2b-256 230aa02e98212b2b32758f59e781852ccc9258e253219f1cce634bd67ae58828

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: release.yml on OVVO-Financial/NNS-python

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

File details

Details for the file ovvo_nns-1.0.0-cp312-cp312-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for ovvo_nns-1.0.0-cp312-cp312-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 e2898e9074c97d42e9a33be20c5db3c103d6c2c62166861b7c34c5045c471a6b
MD5 fbeebf3f3e0c6a02c002db0a447d2086
BLAKE2b-256 65d4994ccef87ec028134405aac2dd2524fc87fb717e098bcafcda99ac88cb04

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.0-cp312-cp312-macosx_10_14_x86_64.whl:

Publisher: release.yml on OVVO-Financial/NNS-python

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

File details

Details for the file ovvo_nns-1.0.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: ovvo_nns-1.0.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 233.0 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ovvo_nns-1.0.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 7cf2bf8b2fe9a259d10166e91a3802586271e6da4f6809e9893d407c28ee04ba
MD5 a25dc1d08e8ef98ab23e37728cc998a7
BLAKE2b-256 72827b967250f5c4a61efb42ac2ae56b3f9c90dc510f58efc18cbcb9937eeb3f

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.0-cp311-cp311-win_amd64.whl:

Publisher: release.yml on OVVO-Financial/NNS-python

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

File details

Details for the file ovvo_nns-1.0.0-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for ovvo_nns-1.0.0-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 988df41fe2f3b7efab96a901999369ac14e3124d9435c4e97520cbacc0a6e6a0
MD5 ffdc333026bf123ddee9203b1b929fbe
BLAKE2b-256 e2e491ef092f8e26065d77a390fa44e909e682a181bf4bc9f5b7d9a7f2d52047

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.0-cp311-cp311-musllinux_1_2_x86_64.whl:

Publisher: release.yml on OVVO-Financial/NNS-python

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

File details

Details for the file ovvo_nns-1.0.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for ovvo_nns-1.0.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 787a2f81f7871f8a301ff51a4d3aa53646f3fe1e7b625bdcf73b40350e6a94b0
MD5 3352a8d4ffcbd5a325938347aea2d736
BLAKE2b-256 a5421d7655ceb6218d2ab86c932351efe211212e83e7e1e403b2a4ab2be6c61b

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.0-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: release.yml on OVVO-Financial/NNS-python

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

File details

Details for the file ovvo_nns-1.0.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ovvo_nns-1.0.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fa68c66796c3884c99d078f22afe6f7a0458ab49d75b4b13843e87dd68fd86d2
MD5 621f692aef5c2fe0f4247c6cf4d579a7
BLAKE2b-256 a96892ff2929b40c7cf95db727b50d7d61652ec6c52bf40f14aee2d1421ae88c

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.0-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: release.yml on OVVO-Financial/NNS-python

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

File details

Details for the file ovvo_nns-1.0.0-cp311-cp311-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for ovvo_nns-1.0.0-cp311-cp311-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 14196734a1ac6922c21d95a46073d537a05c26dc32feae3e87d58c01e874e747
MD5 1fbe50552d3c833d864813ee736f5294
BLAKE2b-256 7ce4f2a896c8ece9bf12b54abd6635fdfdc754560499e582f9519bdc75ef739a

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.0-cp311-cp311-macosx_10_14_x86_64.whl:

Publisher: release.yml on OVVO-Financial/NNS-python

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