我需要一个可以在参数空间内拟合曲线的python函数 [英] I need a python function that can fit a curve within a parameter space

查看:121
本文介绍了我需要一个可以在参数空间内拟合曲线的python函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用SciPy的 optimize.curve_fit()函数通过改变3个参数将曲线拟合到某些数据的项目,效果很好。

I've been working on a project that uses SciPy's optimize.curve_fit() function to fit a curve to some data by varying 3 parameters, which has been working well.

但是,我现在需要更改程序,以使其中一个参数具有另一个参数的函数范围(例如,当x = 10 ybounds = 1 + / -0.2,但x = 11 ybounds = 1.1 +/- 0.2)。到目前为止,我唯一的想法是在第一个函数中放置另一个 optimize.curve_fit()函数,但是事实证明这效率非常低(程序现在需要大约4个小时而不是5分钟)。

However, I now need to alter the program so that 1 of the parameters has bounds which are a function of another parameter (e.g. when x = 10 ybounds = 1 +/- 0.2 but when x = 11 ybounds = 1.1 +/- 0.2). The only idea I've had so far is to put another optimize.curve_fit() function inside the first one, but this has proved hugely inefficient (program now takes ~4 hours rather than 5 mins).

我还可以使用其他Python函数吗?

Are there any other Python functions I can use to accomplish this?

推荐答案

提供有关您要执行的操作的更多详细信息将很有帮助。您可能会找到lmfit( https://lmfit.github.io/lmfit-py )您正在尝试做什么。在其他功能中, lmfit 允许根据其他参数使用数学表达式来约束参数,而无需更改用于建模数据的函数的细节。

It would be helpful to provide more details of what you're trying to do. You might find lmfit (https://lmfit.github.io/lmfit-py) for what you are trying to do. Among other features, lmfit allows constraining parameters using mathematical expressions depending on other parameters without changing the details of the function used to model the data.

作为一个简单示例,您可以让一个名为 a 的参数自由变化,而另一个参数 b 定义为 1-sqrt(a)

As a simple example, you could have a parameter named a vary freely, and another parameter b defined to be 1-sqrt(a).

这篇关于我需要一个可以在参数空间内拟合曲线的python函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆