I need a python function that can fit a curve within a parameter space

試著忘記壹切 提交于 2019-12-13 03:24:01

问题


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.

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).

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


回答1:


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.

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



来源:https://stackoverflow.com/questions/49359762/i-need-a-python-function-that-can-fit-a-curve-within-a-parameter-space

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!