curve-fitting

Fit of two different functions with boarder as fit parameter

纵然是瞬间 提交于 2021-01-27 15:42:27
问题 I have a question about a simple fit function in Python. I am trying to fit two different functions on a data set and the border between the two regimes should be also a fit parameter. Very naively I was trying something like this: def FitFunc(x, a, b, c, d, e, border): if x < border: return a * x + b if x > border: return c * x**2 + d * x + e But I got a ValueError: The truth value of a Series is ambiguous. Use a.empty(), a.bool(), a.item(), a.any() or a.all() I understand that you can not

Trying to fit a trig function to data with scipy

杀马特。学长 韩版系。学妹 提交于 2021-01-27 13:04:39
问题 I am trying to fit some data using scipy.optimize.curve_fit . I have read the documentation and also this StackOverflow post, but neither seem to answer my question. I have some data which is simple, 2D data which looks approximately like a trig function. I want to fit it with a general trig function using scipy . My approach is as follows: from __future__ import division import numpy as np from scipy.optimize import curve_fit #Load the data data = np.loadtxt('example_data.txt') t = data[:,0]

Trying to fit a trig function to data with scipy

人盡茶涼 提交于 2021-01-27 13:00:55
问题 I am trying to fit some data using scipy.optimize.curve_fit . I have read the documentation and also this StackOverflow post, but neither seem to answer my question. I have some data which is simple, 2D data which looks approximately like a trig function. I want to fit it with a general trig function using scipy . My approach is as follows: from __future__ import division import numpy as np from scipy.optimize import curve_fit #Load the data data = np.loadtxt('example_data.txt') t = data[:,0]

scipy curve_fit raises “OptimizeWarning: Covariance of the parameters could not be estimated”

孤街浪徒 提交于 2021-01-04 02:38:46
问题 I am trying to fit this function to some data: But when I use my code import numpy as np from scipy.optimize import curve_fit import matplotlib.pyplot as plt def f(x, start, end): res = np.empty_like(x) res[x < start] =-1 res[x > end] = 1 linear = np.all([[start <= x], [x <= end]], axis=0)[0] res[linear] = np.linspace(-1., 1., num=np.sum(linear)) return res if __name__ == '__main__': xdata = np.linspace(0., 1000., 1000) ydata = -np.ones(1000) ydata[500:1000] = 1. ydata = ydata + np.random

Scipy Optimize Curve fit not properly fitting with real data

为君一笑 提交于 2021-01-01 08:56:32
问题 I am trying to fit a decaying exponential function to real world data. I'm having a problem with aligning the function to the actual data. Here's my code: def test_func(x, a, b, c): return a*np.exp(-b*x)*np.sin(c*x) my_time = np.linspace(0,2.5e-6,25000) p0 = [60000, 700000, 2841842] params, params_covariance = curve_fit(test_func, my_time, my_amp,p0) My signal and fitted function My question: why doesn't the fitted function start where my data starts increasing in amplitude? 回答1: As I said in

How to get error estimates for fit parameters in scipy.stats.gamma.fit?

試著忘記壹切 提交于 2020-12-28 20:53:35
问题 I have some which I am fitting to the gamma distribution using scipy.stats. I am able to extract the shape, loc, and scale params and they look reasonable with the data ranges I expect. My question is: is there a way to also get the errors in the parameters? something like the output of curve_fit. NOTE: I don't use curve fit directly because it is not working properly and most of the time is not able to compute the parameters of the gamma distribution. On the other hand, scipy.stats.gamma.fit

How to fit a non linear function with python?

爷,独闯天下 提交于 2020-12-13 04:33:45
问题 I have the following code written in R to estimate three coefficients (a, b and c): y <- c(120, 125, 158, 300, 350, 390, 2800, 5900, 7790) t <- 1:9 fit <- nls(y ~ a * (((b + c)^2/b) * exp(-(b + c) * t))/(1 + (c/b) * exp(-(b + c) * t))^2, start = list(a = 17933, b = 0.01, c = 0.31)) and i get this result > summary(fit ) Formula: y ~ a * (((b + c)^2/b) * exp(-(b + c) * t))/(1 + (c/b) * exp(-(b + c) * t))^2 Parameters: Estimate Std. Error t value Pr(>|t|) a 2.501e+04 2.031e+03 12.312 1.75e-05 **

Starting values for 4 parameter NLS - Chapman Richards function

早过忘川 提交于 2020-12-06 16:51:25
问题 *Note - I have read several of the posts on how to find starting values for NLS - however, I have not found one with an equation of this form (i.e. 4 parameters, exponent raised to a power) I am struggling tremendously to find suitable starting values for the Chapman Richards equation, which is commonly used in forestry to model tree growth. y(t) = α * (1 - β * exp(-k * t)^{1/(1-m)}) I typically try to find initial values by plotting a line with set parameters, and then tweaking it to fit the