Skip to main content

Python port of nonlinear nonparametric statistics from R NNS

Project description

PyNNS

Nonlinear nonparametric statistics in Python.

PyNNS is an alpha Python port of the R NNS 12.0 package. It provides partial-moment statistics, nonlinear dependence, regression, classification, forecasting, bootstrap, and related tools in Python on top of NumPy, SciPy, and Polars.

  • PyPI package: nns-pm
  • Import name: pynns
  • Status: alpha, parity-focused
  • R required for normal use: no
  • License: GPL-3.0-only

Documentation

PyNNS aims to match installed R NNS public behavior where it is stable, documented, and useful. It does not try to reproduce every R internal helper, plotting side effect, data-frame quirk, or hidden runtime data fetch.

Installation

pip install nns-pm

Optional FRED nowcast provider:

pip install "nns-pm[fred]"

The optional FRED provider loads fredapi only when used. PyNNS does not auto-load .env files and does not fetch network data unless an explicit provider is passed.

R and the R NNS package are only needed by maintainers regenerating live parity fixtures. Normal Python users do not need R installed.

Minimal Examples

Partial Moments

import numpy as np
from pynns import lpm, upm

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

downside = lpm(2, 0.0, x)
upside = upm(2, 0.0, x)

Nonlinear Dependence

import numpy as np
from pynns import nns_dep

x = np.linspace(-2.0, 2.0, 50)
y = x**2

result = nns_dep(x, y)
print(result["Dependence"], result["Correlation"])

Regression

import numpy as np
from pynns import nns_reg

x = np.linspace(-3.0, 3.0, 80)
y = np.sin(x) + 0.2 * x

fit = nns_reg(x, y, point_est=np.array([-1.0, 0.0, 1.0]))
print(fit["Point.est"])

User-Supplied Nowcast Panel

from collections import OrderedDict
from pynns import nns_nowcast_panel

panel = OrderedDict(
    {
        "series_a": [1.0, 1.2, 1.4, 1.5, 1.7],
        "series_b": [2.0, 1.9, 2.1, 2.3, 2.4],
    }
)

forecast = nns_nowcast_panel(panel, h=2, tau=1)

Default live nns_nowcast() fetching is intentionally not implemented. Use nns_nowcast_panel(...) for deterministic data, or nns_nowcast(fetch=True, provider_backend=...) with an explicit provider such as CsvNowcastProvider or optional FredApiNowcastProvider.

Main Features

  • Core partial moments: lpm, upm, ratios, co-moments, and partial-moment matrices.
  • Dependence, copula, causation, CDF, distance, and normalization helpers.
  • Regression, multivariate regression, classification, stack, and boost paths.
  • ARMA, VAR, seasonality, and deterministic user-panel nowcasting.
  • Monte Carlo and maximum-entropy bootstrap wrappers.
  • Stochastic dominance, stochastic superiority, and SD clustering.
  • R parity and Python-native invariant tests for public behavior.

Current Limitations

PyNNS is not full R parity yet. The main mathematical gap is dy_d:

  • Scalar dy_d(eval_points="last"), "obs", and "apd" have known parity gaps and are kept as xfail tests.
  • Vectorized non-mean dy_d and vectorized mixed=True modes are guarded.
  • Default hidden live nns_nowcast() provider fetching is guarded by design.
  • Direct raw-factor nns_m_reg(..., factor_2_dummy=True) is guarded; use the public nns_reg factor-expansion path instead.

See the API status table for the full status table.

Testing

PyNNS tests public behavior against installed R NNS where useful. Tests compare public keys, shapes, labels, signs, selected variables, and numerical values within documented tolerances.

Exact random-stream parity is not expected for stochastic paths because PyNNS uses NumPy RNG while R NNS uses R's RNG. Those paths are tested structurally and statistically.

Development

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

Offline parity-cache run:

PYNNS_OFFLINE=1 uv run pytest -q -m "not benchmark and not stochastic"

Attribution

NNS was created by Fred Viole as the companion R package to Viole, F. and Nawrocki, D. (2013), Nonlinear Nonparametric Statistics: Using Partial Moments.

Upstream: 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

nns_pm-0.1.1.tar.gz (119.3 kB view details)

Uploaded Source

Built Distribution

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

nns_pm-0.1.1-py3-none-any.whl (112.2 kB view details)

Uploaded Python 3

File details

Details for the file nns_pm-0.1.1.tar.gz.

File metadata

  • Download URL: nns_pm-0.1.1.tar.gz
  • Upload date:
  • Size: 119.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for nns_pm-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ede451fa642e18842dce7597a1634301b4246ac9733bb7b3a8df80501da97d12
MD5 e084a2f20e9e498f710768e3b19e50db
BLAKE2b-256 acae60c9e5ad96c4c2a8d7b429762d2d368fbb1fb696b243683f4f3ce3459de0

See more details on using hashes here.

File details

Details for the file nns_pm-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: nns_pm-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 112.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for nns_pm-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e6f8adebc35111ba499ca00dbdb2086e77ff2dec01dd856edaf98e3f6ec4a12d
MD5 4fd780876781b892dfa29d39aa8264a1
BLAKE2b-256 8edb8336fa5d7478336305c43f7d987a727781f0c0dce3ad063fbee934b43499

See more details on using hashes here.

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