PHPackages                             luminsports/levenberg-marquardt - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. luminsports/levenberg-marquardt

ActiveLibrary

luminsports/levenberg-marquardt
===============================

1.0.0(3y ago)111MITPHPPHP ^8.1CI passing

Since Aug 18Pushed 3y agoCompare

[ Source](https://github.com/luminsports/php-levenberg-marquardt)[ Packagist](https://packagist.org/packages/luminsports/levenberg-marquardt)[ RSS](/packages/luminsports-levenberg-marquardt/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (2)Used By (0)

Levenberg Marquardt Curve Fitting
=================================

[](#levenberg-marquardt-curve-fitting)

[![Code Style](https://github.com/luminsports/php-levenberg-marquardt/actions/workflows/php-cs-fixer.yml/badge.svg?branch=main)](https://github.com/luminsports/php-levenberg-marquardt/actions/workflows/php-cs-fixer.yml)[![Tests](https://github.com/luminsports/php-levenberg-marquardt/actions/workflows/run-tests.yml/badge.svg?branch=main)](https://github.com/luminsports/php-levenberg-marquardt/actions/workflows/run-tests.yml)

This algorithm is based on the article [Brown, Kenneth M., and J. E. Dennis. "Derivative free analogues of the Levenberg-Marquardt and Gauss algorithms for nonlinear least squares approximation." Numerische Mathematik 18.4 (1971): 289-297.](https://doi.org/10.1007/BF01404679) and

In order to get a general idea of the problem you could also check the [Wikipedia article](https://en.wikipedia.org/wiki/Levenberg%E2%80%93Marquardt_algorithm).

Credit
------

[](#credit)

This package is a PHP port of [mljs/levenberg-marquardt](https://github.com/mljs/levenberg-marquardt). As such, we have retained their MIT license.

Installation
------------

[](#installation)

`composer require luminsports/levenberg-marquardt`

Example
-------

[](#example)

```
use LuminSports\LevenbergMarquardt\LevenbergMarquardt;

// Set up the curve-fitting model
$model = (new LevenbergMarquardt)
    // the parameters and returns a function with the independent variable as a parameter
    ->setParameterizedFunction(function ($criticalPower, $pMax, $tau) {
        return fn (float $t) => ($pMax - $criticalPower) * exp(-$t / $tau) + $criticalPower;
    })

    // array of initial parameter values
    ->setInitialValues([
        'criticalPower' => $relative ? 4 : 300,
        'wPrime'        => $relative ? 285 : 20000,
        'tau'           => $relative ? 4 : 300,
    ])

    // minimum allowed values for parameters
    ->setMinValues([0, 0, 0])

    // maximum allowed values for parameters
    ->setMaxValues([1000, 600, 300])

    // Levenberg-Marquardt parameter, small values of the damping parameter λ result in a Gauss-Newton update and large values of λ result in a gradient descent update (default 1E-2)
    ->setDamping(1.5)

    // factor to reduce the damping (Levenberg-Marquardt parameter) when there is not an improvement when updating parameters (default: 9)
    ->setDampingStepDown(9)

    // factor to increase the damping (Levenberg-Marquardt parameter) when there is an improvement when updating parameters (default: 11)
    ->setDampingStepUp(11)

    // the threshold to define an improvement through an update of parameters (default: 1E-3)
    ->setImprovementThreshold(1E-3)

    // the step size to approximate the jacobian matrix (default: 10E-2)
    ->setGradientDifference(10E-2)

    // if true the jacobian matrix is approximated by central differences otherwise by forward differences (default: false)
    ->setCentralDifference(true)

    // maximum of allowed iterations (default: 100)
    ->setMaxIterations(1000)

    // minimum uncertainty allowed for each point (default: 10E-3)
    ->setErrorTolerance(10E-3);

$curve = $model->setXValues($knownXValues)
    ->setYValues($knownYValues)
    ->getCurve();

// outputs the parameters that formed the best fitting curve
$curve->getParameters();

// outputs the number of iterations it took to reach this solution
$curve->getIterations();

// the sum of the weighted squares of the errors (or weighted residuals) between the known y-coordinates and the curve-fit function.
$curve->getError();

// returns an array of points for the provided x-values, with the predicted y-values
$model->predict($xValuesToPredictFor);
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1365d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0e55216f06906e0bdee2b78e0b2c0c9d5009a4bbab212341d04e3584ba8d864c?d=identicon)[ryzr](/maintainers/ryzr)

---

Top Contributors

[![ryzr](https://avatars.githubusercontent.com/u/9389421?v=4)](https://github.com/ryzr "ryzr (7 commits)")

---

Tags

php

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/luminsports-levenberg-marquardt/health.svg)

```
[![Health](https://phpackages.com/badges/luminsports-levenberg-marquardt/health.svg)](https://phpackages.com/packages/luminsports-levenberg-marquardt)
```

###  Alternatives

[phpoffice/phpspreadsheet

PHPSpreadsheet - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine

13.9k293.5M1.3k](/packages/phpoffice-phpspreadsheet)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
