Skip to main content

What is stressPy?

When a model disagrees with experimental data, conventional goodness-of-fit measures quantify the size of the discrepancy but do not reveal its geometric character. In particular, they do not distinguish between discrepancies aligned with the model’s available parameter-response directions and discrepancies lying outside those directions.

StressPy applies the Geometric Stress Criterion (GSC) to separate a model–data discrepancy into two components:

Tangent stress

— locally parameter-accessible discrepancy: The part aligned with changes the model can produce, to first order, by varying its existing parameters near the current parameter point. This component may be reducible through parameter adjustment, although local accessibility does not guarantee a practical finite repair.

Normal stress

— locally inaccessible discrepancy: The part orthogonal to the model’s local parameter-response directions in the selected observation metric. It cannot be removed by an infinitesimal parameter adjustment at the current point and can therefore provide evidence that the model structure, observation mapping, or represented mechanisms require reconsideration.

StressPy complements conventional goodness-of-fit measures such as RMSE and chi-squared error, as well as model-selection criteria such as AIC and BIC. These established methods quantify overall fit or balance fit against model complexity. StressPy addresses a different question: how much of the observed discrepancy is aligned with the model’s locally accessible parameter-response directions?

By distinguishing these components, stresspy helps scientists, engineers and model developers assess whether further parameter optimisation is promising or whether the model itself should be investigated. The result is a local geometric diagnostic whose interpretation depends on the chosen parameter point, observational weighting and numerical-rank threshold.

StressPy

Core numerical routines for the Geometric Stress Criterion (GSC).

stresspy decomposes a model--data discrepancy into a component aligned with the model's local parameter-accessible tangent space and a component normal to that space. It also reports numerical rank, singular values, the normal fraction, conditioning and a minimum-norm local repair vector.

StressPy is an early reference implementation. It performs deterministic local geometry and can construct a Jacobian from a Python model function. It does not fit models, solve ODEs on the user's behalf or perform bootstrap calibration.

Installation

pip install stresspy

Quick start

import numpy as np
from stresspy import evaluate_gsc

def model(parameters, x):
    intercept, slope = parameters
    return intercept + slope * x

x = np.array([-1.0, 0.0, 1.0, 2.0])
parameters = np.array([1.0, 0.5])
observed = np.array([0.45, 1.10, 1.70, 2.35])
sigma = np.full(observed.size, 0.10)

result = evaluate_gsc(
    model_func=model,
    parameters=parameters,
    observed=observed,
    model_args=(x,),
    sigma=sigma,
)

print("Predictions:", result.predicted)
print("Jacobian:\n", result.jacobian)
print("Tangent stress:", result.tangent_stress)
print("Normal stress:", result.normal_stress)
print("Normal fraction (%):", result.normal_fraction_pct)
print("Numerical rank:", result.rank)
print("Repair vector:", result.repair_vector)

evaluate_gsc evaluates the model, constructs its Jacobian and performs the decomposition in one call. Its default Jacobian method is dependency-free forward finite differencing.

Jacobian construction

The model function must accept the parameter vector as its first argument and return one finite prediction per observation. Additional inputs can be supplied through model_args and model_kwargs.

Forward finite differences are the default:

result = evaluate_gsc(
    model,
    parameters,
    observed,
    model_args=(x,),
    jacobian_method="forward",
)

Central finite differences require twice as many perturbed model evaluations but commonly improve derivative accuracy:

result = evaluate_gsc(
    model,
    parameters,
    observed,
    model_args=(x,),
    jacobian_method="central",
)

StressPy chooses parameter-scaled finite-difference steps from machine precision. A positive scalar or one step per parameter can instead be supplied with step.

Finite differences assume that model outputs are deterministic and locally smooth at the supplied parameter point. Discontinuities, solver failures, stochastic simulations and poorly scaled parameters can make a numerical Jacobian unreliable. Important analyses should be repeated with alternative step sizes or central differences as a sensitivity check.

The Jacobian and repair vector use exactly the coordinates supplied in parameters. To work in log-parameter coordinates, pass log parameters to a model wrapper that exponentiates them before evaluating the underlying model.

The adapters can also be used independently:

from stresspy import finite_difference_jacobian

jacobian = finite_difference_jacobian(
    model,
    parameters,
    method="central",
    model_args=(x,),
)

Optional JAX automatic differentiation

Install the optional dependency with:

pip install "stresspy[jax]"

Then use a JAX-traceable model written with jax.numpy operations:

result = evaluate_gsc(
    jax_model,
    parameters,
    observed,
    jacobian_method="jax",
)

StressPy never silently substitutes finite differences when JAX is explicitly requested. An informative error is raised if JAX is unavailable or the model cannot be differentiated by JAX.

Analysis from a precomputed residual and Jacobian

When predictions and the Jacobian have already been calculated, use analyze:

from stresspy import analyze

residual = observed - predicted
result = analyze(residual, jacobian, sigma=sigma)

Weighting

An unweighted Euclidean analysis requires no additional argument:

result = analyze(residual, jacobian)

Independent observational standard deviations can be supplied with sigma:

result = analyze(residual, jacobian, sigma=sigma)

An optional absolute or quantile-based lower floor can prevent extremely small standard deviations from dominating the observation metric:

absolute_floor = analyze(
    residual,
    jacobian,
    sigma=sigma,
    sigma_floor=0.05,
)

quantile_floor = analyze(
    residual,
    jacobian,
    sigma=sigma,
    sigma_floor_quantile=0.10,
)

Positive diagonal precision weights may be supplied directly. They define the metric sum(weights * residual**2) and are equivalent to sigma = 1 / sqrt(weights):

weights = 1.0 / sigma**2
result = analyze(residual, jacobian, weights=weights)

For correlated observations, supply a positive-definite covariance matrix:

result = analyze(residual, jacobian, covariance=covariance)

Supply only one of sigma, weights, covariance or whitener. Weighting is part of the geometry: different defensible metrics can produce different tangent--normal decompositions and should be reported explicitly.

The discrepancy convention is

[ r = y - f(\hat{\theta}). ]

With observation-space whitening matrix (L), StressPy forms (r_W=Lr) and (J_W=LJ). If (U_r) contains the retained left singular vectors of (J_W), then

[ r_{\parallel,W}=U_rU_r^\top r_W, \qquad r_{\perp,W}=r_W-r_{\parallel,W}. ]

The squared norms give total, tangent and normal stress. The minimum-norm local repair is calculated in the parameter coordinates represented by the supplied Jacobian. Consequently, repair magnitude is coordinate-dependent, and local tangent accessibility does not guarantee a practical finite nonlinear repair.

Principal functions

  • evaluate_gsc: evaluate a Python model, construct its Jacobian and perform the complete GSC decomposition.
  • finite_difference_jacobian: dependency-free forward or central numerical differentiation.
  • jax_jacobian: optional forward-mode automatic differentiation using JAX.
  • analyze: recommended high-level analysis from a residual and Jacobian, including common weighting and uncertainty-floor options.
  • decompose: single tangent--normal decomposition with optional uncertainty or covariance weighting.
  • decompose_blocks: joint interrogation of multiple independent observation blocks sharing the same parameter coordinates.
  • floor_sigma: explicit uncertainty-floor preprocessing.
  • jacobian_to_log_coordinates: conversion of selected Jacobian columns to log-parameter coordinates.

analyze and decompose return an immutable GSCResult. evaluate_gsc returns its subclass GSCEvaluationResult, which adds the parameter vector, observations, predictions, constructed Jacobian, Jacobian method and numerical steps while preserving direct access to every geometric result field.

Interpretation

Normal stress measures discrepancy outside the retained local Jacobian column space in the selected observation metric. It is a local geometric diagnostic, not by itself a calibrated hypothesis test. Conclusions can depend on the chosen weighting, parameter point and singular-value threshold.

Licence and commercial use

StressPy is available under the PolyForm Noncommercial License 1.0.0. It may be used, studied, modified and redistributed for permitted non-commercial purposes under those terms. Commercial use requires separate written permission from the copyright holder.

Citation

If StressPy contributes to academic work, please cite the software and the associated GSC publication when available. Citation metadata is provided in CITATION.cff.

Suggested software citation:

James, D. (2026). StressPy: Core numerical routines for the Geometric Stress Criterion (Version 0.0.5) [Computer software]. https://pypi.org/project/stresspy/

Download files

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

Source Distribution

stresspy-0.0.6.tar.gz (22.0 kB view details)

Uploaded Source

Built Distribution

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

stresspy-0.0.6-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file stresspy-0.0.6.tar.gz.

File metadata

  • Download URL: stresspy-0.0.6.tar.gz
  • Upload date:
  • Size: 22.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.3

File hashes

Hashes for stresspy-0.0.6.tar.gz
Algorithm Hash digest
SHA256 9c3f623bdffb917e00c0bee2273a6cf35fc6402f4ff2d6b380715c1c095ebfb7
MD5 bd6a24723a8e5ed7bbb9bc6d6f3cb95e
BLAKE2b-256 2561d17516fe1438c0ab0e341f126f3f6317b3d5b595ef5aa5320e463fb8f8e8

See more details on using hashes here.

File details

Details for the file stresspy-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: stresspy-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.3

File hashes

Hashes for stresspy-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 14c6be2e99bbdf725c3e70f79a1c95917ff3e0577c3d79ad84db974b2d35d7f4
MD5 8857dbf78a03f457665a632c315aa919
BLAKE2b-256 dab5702607116dc201188a02871be2dae60a2e91a72f7ff913ec3fc36151eead

See more details on using hashes here.

Release history Release notifications | RSS feed

0.0.8

2 files

0.0.7

2 files

This release

0.0.6 This release

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page