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
-
Artezaru artezaru.github@proton.me
-
Git Plateform: https://github.com/Artezaru/pysolve-gn.git
-
Online Documentation: https://Artezaru.github.io/pysolve-gn
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pysolve_gn-0.0.2-py3-none-any.whl.
File metadata
- Download URL: pysolve_gn-0.0.2-py3-none-any.whl
- Upload date:
- Size: 111.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
303207b8f478359e131402d024f59a5e28a9338c8218e2c68509fce7112994ec
|
|
| MD5 |
e98742c39fd4db8d71ecc7a2de02bc23
|
|
| BLAKE2b-256 |
dd05a86319180f8fcdeec86bd9ebd628eef77f98ab4cb514efa9a371687bb63c
|