Skip to main content

Python port of nonlinear nonparametric statistics from R NNS

Project description

NNS Python

PyPI package Python License

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.1
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 Stable, 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
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

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.

Authors and contributors

  • Fred Viole — author and maintainer
  • Roberto Spadim — contributor
  • Rasheed Khoshnaw — contributor

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.2.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.2-cp313-cp313-win_amd64.whl (228.1 kB view details)

Uploaded CPython 3.13Windows x86-64

ovvo_nns-1.0.2-cp313-cp313-musllinux_1_2_x86_64.whl (725.8 kB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

ovvo_nns-1.0.2-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (266.2 kB view details)

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

ovvo_nns-1.0.2-cp313-cp313-macosx_11_0_arm64.whl (242.9 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

ovvo_nns-1.0.2-cp313-cp313-macosx_10_14_x86_64.whl (265.8 kB view details)

Uploaded CPython 3.13macOS 10.14+ x86-64

ovvo_nns-1.0.2-cp312-cp312-win_amd64.whl (228.1 kB view details)

Uploaded CPython 3.12Windows x86-64

ovvo_nns-1.0.2-cp312-cp312-musllinux_1_2_x86_64.whl (725.7 kB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

ovvo_nns-1.0.2-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (266.2 kB view details)

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

ovvo_nns-1.0.2-cp312-cp312-macosx_11_0_arm64.whl (242.9 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

ovvo_nns-1.0.2-cp312-cp312-macosx_10_14_x86_64.whl (265.8 kB view details)

Uploaded CPython 3.12macOS 10.14+ x86-64

ovvo_nns-1.0.2-cp311-cp311-win_amd64.whl (228.9 kB view details)

Uploaded CPython 3.11Windows x86-64

ovvo_nns-1.0.2-cp311-cp311-musllinux_1_2_x86_64.whl (726.1 kB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

ovvo_nns-1.0.2-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (266.5 kB view details)

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

ovvo_nns-1.0.2-cp311-cp311-macosx_11_0_arm64.whl (243.3 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

ovvo_nns-1.0.2-cp311-cp311-macosx_10_14_x86_64.whl (266.1 kB view details)

Uploaded CPython 3.11macOS 10.14+ x86-64

File details

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

File metadata

  • Download URL: ovvo_nns-1.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 80b59290f7d936eb22b855c3028c92cfa39cd0ebd92e749a5f28615670a400ac
MD5 f788cd78ef2ab4747490596bc447367b
BLAKE2b-256 e74f68572650bcd49f19751c7d9c1d749d4d165767fc4a4791df3e0c857c58eb

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.2.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.2-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: ovvo_nns-1.0.2-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 228.1 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.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 125b331dea93272544bce7f25e0eb99002f7e9e69c0880925800a97f06ea524d
MD5 2df427aaea00706ba52c6a8fb3c8c97f
BLAKE2b-256 58debf7dbef586343528fa35ad52d354b87fdda855703480ff1d284c8f48d8ee

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.2-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.2-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for ovvo_nns-1.0.2-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 a9493cfd478b41ba7b1fdd12980d1b0081192823873b70a973a1fdbbfc289076
MD5 67a354d16aeb3df7810b99c39f7159cb
BLAKE2b-256 7c2b6c85d33f38d19c6e1133e8e4fdff0edec741926bcba43d72bc5e9283798d

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.2-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.2-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for ovvo_nns-1.0.2-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 fcb96599046a7c5973cfa4f46ca5081221ec8ae5160e2f6a578da1ac7455c25b
MD5 1218a49d799c2392ecda87f9c880b002
BLAKE2b-256 91d5f2ec00b938d7ae137ad30b429f17b35fedcce18aaea14d6215f176958a2f

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.2-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.2-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ovvo_nns-1.0.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 13ba9b776c44fac93fb245a47967732736d7bb0ba8bed243c48bd1c83355c681
MD5 1efc1be8150075925b1a6840b74dd505
BLAKE2b-256 9e0d0760eaa41be71ad25be8a0657ff2c44890c250d5b8796590da048d0ab65a

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.2-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.2-cp313-cp313-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for ovvo_nns-1.0.2-cp313-cp313-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 4ef52ffe65893c6b5cac14aaab407b88725c6bd136befe0d836cb608743a4793
MD5 c67b758c2cd964bc2b1ace150789cc75
BLAKE2b-256 34eca7d647d98b707a06c84d5be4cd6a1d05b3c7ef1ecee3b883c09c7c72c2d9

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.2-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.2-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: ovvo_nns-1.0.2-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 228.1 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.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 21e0862a0d2de6f28d93f95f9abfe08c97761dd63501bf0028b3b971d8c50048
MD5 61fa3f0aec55b446f47d5d8336448a93
BLAKE2b-256 4f38ef5c385fc380e0e97b1fbd5faca6b1869a268c6bef31fe3844777f9e57da

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.2-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.2-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for ovvo_nns-1.0.2-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5c9bb58b938902102c36e27c70829b130f8033fe2d24d264c813b3cddab7e12b
MD5 7d59c8689e452cb9be2de2463891532b
BLAKE2b-256 9b8b87e3d361e9c1528ada7318c8b5a004a6d09944b2b25589f816d746f94ee9

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.2-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.2-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for ovvo_nns-1.0.2-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e2d3d85153f4f94a4b583b2cabd9af73e916e411d4eb1f5aa475a784159b7cde
MD5 7b579f51358540a8844cc9d58a1145c4
BLAKE2b-256 af8eb98a4ebad2cc4d289a5a97c7a546e6a2948b06ff4de432049f6edddc5abc

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.2-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.2-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ovvo_nns-1.0.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e588311336a6ec1df480ba07b64582ae57674c580ca39b59bbe9eb038b7ef3ed
MD5 7d72186c65f595ec1ad1ff488202822d
BLAKE2b-256 4454540cf2141bc33d87f75822151c46c5d29f9a99d42e563b60a227735355fd

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.2-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.2-cp312-cp312-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for ovvo_nns-1.0.2-cp312-cp312-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 b97b50e12e09bb6da4bc4fa734977dadd27b5d227b62030250b303417a093d4b
MD5 504cbedaa1ea472c741ae5e265f87242
BLAKE2b-256 199e82984792bbfe4876036115040b147a14209332113312bc4ce841993a8f70

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.2-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.2-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: ovvo_nns-1.0.2-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 228.9 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.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 124f3ec90a2262ba90bbc204d43e482ae2619e28eaf08614fe41cbee74ca718e
MD5 62c7e19b75867130a5a73d374ed3f489
BLAKE2b-256 e62017124233c14c8382760d414ec707e231d85b645d9f83fec2d8ac985ff08c

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.2-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.2-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for ovvo_nns-1.0.2-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 aa59945f5b395d1b3a9923ded78f97f6eb9d26feddc6d255a28356e11d513120
MD5 a4eb5445498975c16a4536a113e514c4
BLAKE2b-256 88ebca556c0b570a84260538136d1f4293372399c4531d95af6ded718f4fa5f7

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.2-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.2-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for ovvo_nns-1.0.2-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d33e22e92dae75c05ca44aa0ce80211341229259d2cec56e2c275e67f12711d2
MD5 d1f062b755a046d60315223a10f953e5
BLAKE2b-256 cd6c490aac16062f07cfddd81bb4f85c715cc564846aecfe73b8d3b64b9c31a5

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.2-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.2-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ovvo_nns-1.0.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 729e1188cab477c69773ca5ff9d812b67d63a71378fdb0593701f88c3d6c1c7f
MD5 71b673272baf9c182982898ed79d8237
BLAKE2b-256 f7d365caeb33858300a73cd7e81b18b536c8d71e981f18addd9473527d83a4a3

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.2-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.2-cp311-cp311-macosx_10_14_x86_64.whl.

File metadata

File hashes

Hashes for ovvo_nns-1.0.2-cp311-cp311-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 960cb2a1d7dde83bf25b6c69f14999f73214b5b574b510017e1ed689d609719e
MD5 5d1c73171e0d76cd67b72570755add0e
BLAKE2b-256 506215e2b3ce86c882ec2d704f07baba655c7c110878bab1643786385ab1d9b0

See more details on using hashes here.

Provenance

The following attestation bundles were made for ovvo_nns-1.0.2-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