Skip to main content

Robust Gauss-Newton Least Squares Solver.

Project description

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
from pysolvegn import solve_gauss_newton

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)

# Perform curve fitting using Gauss-Newton method
initial_params = [2.0, 0.4]

fitted_params = solve_gauss_newton(
    residual_func,
    jacobian_func,
    initial_params,
    max_iterations=10,
    xtol=1e-6,
    ftol=1e-6,
    verbosity=2,
    loss="linear",
)

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/.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

pysolve_gn-0.0.3-py3-none-any.whl (111.3 kB view details)

Uploaded Python 3

File details

Details for the file pysolve_gn-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: pysolve_gn-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 111.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for pysolve_gn-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e4348220ebea41c58dd5fa4b2cb1eb0927e8a643af18137224e09932d29a8027
MD5 8c1b3eed0a0d5647ba57ac04414db222
BLAKE2b-256 86aeec5c4deb852bb7fedd5860064a1ac57ca387170eaa7bba3e6a60b5b53918

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