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
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
    x0=initial_params,
    max_iteration=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.2.1-py3-none-any.whl (124.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pysolve_gn-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 124.4 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.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ac6a04dce626469062aece50fdfe0aef6f37741040bbb25396b051385a8ce650
MD5 9b76df90ca81daeb306a82441dd4569c
BLAKE2b-256 821bb19692b8ac93b944a171b6ee821d922c69b3e44379c73bf916f22542ebec

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