问题
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