{"id":13592738,"url":"https://github.com/lmfit/lmfit-py","last_synced_at":"2025-05-13T17:06:09.618Z","repository":{"id":37832869,"uuid":"2136524","full_name":"lmfit/lmfit-py","owner":"lmfit","description":"Non-Linear Least Squares Minimization, with flexible Parameter settings, based on scipy.optimize, and with many additional classes and methods for curve fitting. ","archived":false,"fork":false,"pushed_at":"2025-05-06T14:54:19.000Z","size":374998,"stargazers_count":1121,"open_issues_count":5,"forks_count":280,"subscribers_count":30,"default_branch":"master","last_synced_at":"2025-05-06T15:57:49.517Z","etag":null,"topics":["curve-fitting","least-squares","python","scipy"],"latest_commit_sha":null,"homepage":"https://lmfit.github.io/lmfit-py/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lmfit.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.txt","dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2011-08-01T12:13:19.000Z","updated_at":"2025-05-06T11:52:36.000Z","dependencies_parsed_at":"2022-08-02T15:15:42.031Z","dependency_job_id":"4831bdf8-5858-4ab3-9b55-d6ceee160632","html_url":"https://github.com/lmfit/lmfit-py","commit_stats":{"total_commits":2402,"total_committers":93,"mean_commits":"25.827956989247312","dds":"0.48459616985845133","last_synced_commit":"776e14d73028548f783288c37468b520e459050e"},"previous_names":[],"tags_count":65,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmfit%2Flmfit-py","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmfit%2Flmfit-py/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmfit%2Flmfit-py/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lmfit%2Flmfit-py/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lmfit","download_url":"https://codeload.github.com/lmfit/lmfit-py/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253990463,"owners_count":21995774,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["curve-fitting","least-squares","python","scipy"],"created_at":"2024-08-01T16:01:12.647Z","updated_at":"2025-05-13T17:06:09.555Z","avatar_url":"https://github.com/lmfit.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"LMfit-py\n========\n\n.. image:: https://dev.azure.com/lmfit/lmfit-py/_apis/build/status/lmfit.lmfit-py?branchName=master\n    :target: https://dev.azure.com/lmfit/lmfit-py/_build/latest?definitionId=1\u0026branchName=master\n\n.. image:: https://codecov.io/gh/lmfit/lmfit-py/branch/master/graph/badge.svg\n  :target: https://codecov.io/gh/lmfit/lmfit-py\n\n.. image:: https://img.shields.io/pypi/v/lmfit.svg\n   :target: https://pypi.org/project/lmfit\n\n.. image:: https://img.shields.io/pypi/dm/lmfit.svg\n   :target: https://pypi.org/project/lmfit\n\n.. image:: https://img.shields.io/badge/docs-read-brightgreen\n   :target: https://lmfit.github.io/lmfit-py/\n\n.. image:: https://zenodo.org/badge/4185/lmfit/lmfit-py.svg\n   :target: https://doi.org/10.5281/zenodo.598352\n\n.. _LMfit google mailing list: https://groups.google.com/group/lmfit-py\n.. _Github Discussions: https://github.com/lmfit/lmfit-py/discussions\n.. _Github Issues: https://github.com/lmfit/lmfit-py/issues\n\n\n..\n   Note: the Zenodo target should be\n   https://zenodo.org/badge/latestdoi/4185/lmfit/lmfit-py\n   but see https://github.com/lmfit/lmfit-py/discussions/862\n\n\nOverview\n---------\n\nThe lmfit Python library supports provides tools for non-linear least-squares\nminimization and curve fitting.  The goal is to make these optimization\nalgorithms more flexible, more comprehensible, and easier to use well, with the\nkey feature of casting variables in minimization and fitting routines as named\nparameters that can have many attributes beside just a current value.\n\nLMfit is a pure Python package, built on top of Scipy and Numpy, and so easy to\ninstall with ``pip install lmfit``.\n\nFor questions, comments, and suggestions, please use the `LMfit google mailing\nlist`_ or `Github discussions`_.  For software issues and bugs, use `Github\nIssues`_, but please read `Contributing.md \u003c.github/CONTRIBUTING.md\u003e`_ before\ncreating an Issue.\n\n\nParameters and Minimization\n------------------------------\n\nLMfit provides optimization routines similar to (and based on) those from\n``scipy.optimize``, but with a simple, flexible approach to parameterizing a\nmodel for fitting to data using named parameters. These named Parameters can be\nheld fixed or freely adjusted in the fit, or held between lower and upper\nbounds. Parameters can also be constrained as a simple mathematical expression\nof other Parameters.\n\nA Parameters object (which acts like a Python dictionary) contains named\nparameters, and can be built as with::\n\n    import lmfit\n    fit_params = lmfit.Parameters()\n    fit_params['amp'] = lmfit.Parameter(value=1.2)\n    fit_params['cen'] = lmfit.Parameter(value=40.0, vary=False)\n    fit_params['wid'] = lmfit.Parameter(value=4, min=0)\n    fit_params['fwhm'] = lmfit.Parameter(expr='wid*2.355')\n\nor using the equivalent::\n\n    fit_params = lmfit.create_params(amp=1.2,\n                                     cen={'value':40, 'vary':False},\n                                     wid={'value': 4, 'min':0},\n                                     fwhm={'expr': 'wid*2.355'})\n\n\n\nIn the general minimization case (see below for Curve-fitting), the user will\nalso write an objective function to be minimized (in the least-squares sense)\nwith its first argument being this Parameters object, and additional positional\nand keyword arguments as desired::\n\n    def myfunc(params, x, data, someflag=True):\n        amp = params['amp'].value\n        cen = params['cen'].value\n        wid = params['wid'].value\n        ...\n        return residual_array\n\nFor each call of this function, the values for the ``params`` may have changed,\nsubject to the bounds and constraint settings for each Parameter. The function\nshould return the residual (i.e., ``data-model``) array to be minimized.\n\nThe advantage here is that the function to be minimized does not have to be\nchanged if different bounds or constraints are placed on the fitting Parameters.\nThe fitting model (as described in myfunc) is instead written in terms of\nphysical parameters of the system, and remains remains independent of what is\nactually varied in the fit. In addition, which parameters are adjusted and which\nare fixed happens at run-time, so that changing what is varied and what\nconstraints are placed on the parameters can easily be modified by the user in\nreal-time data analysis.\n\nTo perform the fit, the user calls::\n\n    result = lmfit.minimize(myfunc, fit_params, args=(x, data), kws={'someflag':True}, ....)\n\nAfter the fit, a ``MinimizerResult`` class is returned that holds the results\nthe fit (e.g., fitting statistics and optimized parameters). The dictionary\n``result.params`` contains the best-fit values, estimated standard deviations,\nand correlations with other variables in the fit.\n\nBy default, the underlying fit algorithm is the Levenberg-Marquardt algorithm\nwith numerically-calculated derivatives from MINPACK's lmdif function, as used\nby ``scipy.optimize.leastsq``. Most other solvers that are present in ``scipy``\n(e.g., Nelder-Mead, differential_evolution, basin-hopping, and more) are also\nsupported.\n\n\nCurve-Fitting with lmfit.Model\n----------------------------------\n\nOne of the most common use of least-squares minimization is for curve fitting,\nwhere minimization of ``data-model``, or ``(data-model)*weights``.  Using\n``lmfit.minimize`` as above, the objective function would take ``data`` and\n``weights`` and effectively calculated the model and then return the value of\n``(data-model)*weights``.\n\nTo simplify this, and make curve-fitting more flexible, lmfit provides a Model\nclass that wraps a *model function* that represents the model (without the data\nor weights).  Parameters are then automatically found from the named arguments\nof the model function.  In addition, simple model functions can be readily\ncombined and reused, and several common model functions are included in lmfit.\n\nExploration of Confidence Intervals\n-------------------------------------\n\nLmfit tries to always estimate uncertainties in fitting parameters and\ncorrelations between them.  It does this even for those methods where the\ncorresponding ``scipy.optimize`` routines do not estimate uncertainties.  Lmfit\nalso provides methods to explicitly explore and evaluate the confidence\nintervals in fit results.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flmfit%2Flmfit-py","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flmfit%2Flmfit-py","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flmfit%2Flmfit-py/lists"}