Skip to main content

pysolve-gn

Description

Robust Gauss-Newton Least Squares Solver.

pysolve-gn is a Python package designed to solve the generalized nonlinear least squares problem using the Gauss-Newton method. The package provides efficient algorithms for solving nonlinear optimization problems, making it suitable for a wide range of applications in data fitting, machine learning, and scientific computing.

Examples

import numpy as np
import matplotlib.pyplot as plt
import pysolvegn

np.random.seed(0)


# Define the model function
def model(params, x):
    a, b = params
    return a * np.exp(b * x)


# Generate synthetic data points
x_data = np.linspace(0, 3, 100)
true_params = [2.5, 0.5]  # True parameters for the curve: y = a * exp(b * x)
y_true = model(true_params, x_data)
y_data = y_true + 0.5 * np.random.normal(size=y_true.shape)  # Add noise to the data


# Define the residual function
def residual_function(params, x, y):
    return model(params, x) - y


residual_func = lambda params: residual_function(params, x_data, y_data)


# Define the Jacobian function
def jacobian_function(params, x):
    a, b = params
    J = np.zeros((len(x), len(params)))
    J[:, 0] = np.exp(b * x)  # Derivative with respect to a
    J[:, 1] = a * x * np.exp(b * x)  # Derivative with respect to b
    return J


jacobian_func = lambda params: jacobian_function(params, x_data)

data_term = pysolvegn.Term.from_rJ(
    residual_func=residual_func, jacobian_func=jacobian_func, loss="linear", weight=1.0
)

initial_params = [2.0, 0.4]

fitted_params = pysolvegn.solve_gauss_newton(
    terms=data_term
    p0=initial_params,
    max_iteration=10,
    xtol=1e-6,
    ftol=1e-6,
    verbosity=2,
)

Authors

Installation

Install with pip

pip install pysolve-gn

Or :

pip install git+https://github.com/Artezaru/pysolve-gn.git

Then import the package with pysolvegn

License

pysolve-gn - Robust Gauss-Newton Least Squares Solver. Copyright (C) 2026 Artezaru, artezaru.github@proton.me

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.

Metadata

Release files for pysolve-gn 1.0.1

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

Built distribution (wheel)

Table of built distributions (wheels) for pysolve-gn 1.0.1
File Interpreter ABI Platform Actions
pysolve_gn-1.0.1-py3-none-any.whl Python 3 none any Details for pysolve_gn-1.0.1-py3-none-any.whl

Release files / pysolve_gn-1.0.1-py3-none-any.whl

Download URL pysolve_gn-1.0.1-py3-none-any.whl
Size 132.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0adfe7ae0a0a03c38d29d9d3267b70e7ced5f976bd5b3d1ca2bc863da567aa07
BLAKE2b-256 checksum
How to use checksums
d54ba69594a974a54e5eb8ee85c931d0f078490162059754478a0bac07a5c37a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.16

Security for pysolve-gn 1.0.1

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