Skip to main content

W4

PyPI version shields.io

PyPI license

This package provides the W4 method for nonlinear root finding, inspired by the R implementation.

Install

create a virtual environment, activate it and upgrade pip:

python3 -m venv .venv
source .venv/bin/activate
pip install -U pip

install from pypi:

pip install w4

or from github repo:

pip install git+https://github.com/gmagno/w4

Usage

import numpy as np
from w4.w4 import w4
from w4.xy import Decomposition

x0: np.ndarray = np.array([0.5, 5.0])

def f(x: np.ndarray) -> np.ndarray:
    return np.array([x[0] ** 2 + x[1] ** 2 - 4, x[0] ** 2 * x[1] - 1])

def fa(x: np.ndarray) -> np.ndarray:
    return np.array(
        [abs(x[0] ** 2) + abs(x[1] ** 2) + abs(-4), abs(x[0] ** 2 * x[1]) + abs(-1)]
    )

def jac(x: np.ndarray) -> np.ndarray:
    return np.array([[2 * x[0], 2 * x[1]], [2 * x[0] * x[1], x[0] ** 2]])

solution: np.ndarray = w4(
    x0=x0, f=f, fa=fa, jac=jac, decomposition=Decomposition.LU, trace=True
)

print(solution)

Output:

[( 0, 7.26495726e-01, 0.5       , 5.        )
 ( 1, 7.26495726e-01, 0.51413317, 4.46733668)
 ( 2, 6.69713968e-01, 0.52954179, 3.8709697 )
 ( 3, 5.84735305e-01, 0.54795009, 3.34463474)
 ( 4, 4.83432079e-01, 0.57024824, 2.91997823)
 ( 5, 3.77502437e-01, 0.5956425 , 2.59451865)
 ( 6, 2.78389751e-01, 0.6222772 , 2.3546681 )
 ( 7, 1.94497674e-01, 0.64795729, 2.18404118)
 ( 8, 1.29477634e-01, 0.67078251, 2.06671229)
 ( 9, 8.27001827e-02, 0.68957129, 1.98864688)
 (10, 5.10336293e-02, 0.70398283, 1.93831422)
 (11, 3.06148582e-02, 0.7143608 , 1.90680022)
 (12, 1.79468274e-02, 0.7214358 , 1.88758697)
 (13, 1.03240723e-02, 0.7260406 , 1.87614544)
 (14, 5.84768757e-03, 0.72892454, 1.86946918)
 (15, 3.35778195e-03, 0.73067466, 1.8656404 )
 (16, 1.98478537e-03, 0.7317098 , 1.86347648)
 (17, 1.14937826e-03, 0.73230941, 1.86226842)
 (18, 6.54505913e-04, 0.73265086, 1.86160094)
 (19, 3.67583154e-04, 0.73284262, 1.86123535)
 (20, 2.04087865e-04, 0.73294908, 1.86103659)
 (21, 1.12232060e-04, 0.73300761, 1.86092922)
 (22, 6.12220725e-05, 0.73303954, 1.86087154)]

Tests

clone repo:

git clone https://github.com/gmagno/w4
cd w4

create virtual environment and install dependencies

python3 -m venv .venv
source .venv/bin/activate
pip install -U pip
pip install -r requirements_dev.txt

run tests:

make test

Metadata

Release files for w4 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for w4 0.1.2
File Size Uploaded Provenance Actions
w4-0.1.2.tar.gz 6.7 kB Without provenance Details for w4-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for w4 0.1.2
File Interpreter ABI Platform Actions
w4-0.1.2-py2.py3-none-any.whl Python 3, Python 2 none any Details for w4-0.1.2-py2.py3-none-any.whl

Total release size: 11.6 kB

Release files / w4-0.1.2.tar.gz

Download URL w4-0.1.2.tar.gz
Size 6.7 kB
Tags Source
SHA-256 checksum
How to use checksums
36a867a29155fc15edd3543ec55fd6d4a8210d086dbf83be7eb00626b47127b1
BLAKE2b-256 checksum
How to use checksums
cf3ac88ca1edf394104807e81b070ac6bc57977639fcff474404af5909cbb694
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / w4-0.1.2-py2.py3-none-any.whl

Download URL w4-0.1.2-py2.py3-none-any.whl
Size 5.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
a046f114526ebe18d48c297efb5bfa8d44192c586200e75480e57cb40557e5a4
BLAKE2b-256 checksum
How to use checksums
4556aa9564a5b9a60366b5bb9a80bc702a839ddf883c3781f08ca1885feacccf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Security for w4 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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