curve-fitting

How to pass parameter to fit function when using scipy.optimize.curve_fit

南楼画角 提交于 2019-12-11 11:50:45
问题 I am trying to fit some data that I have using scipy.optimize.curve_fit. My fit function is: def fitfun(x, a): return np.exp(a*(x - b)) What i want is to define a as the fitting parameter, and b as a parameter that changes depending on the data I want to fit. This means that for one set of data I would want to fit the function: np.exp(a*(x - 10)) while for another set I would like to fit the function np.exp(a*(x - 20)) . In principle, I would like the parameter b to be passed in as any value.

scipy.curve_fit() returns multiple lines

天大地大妈咪最大 提交于 2019-12-11 10:11:35
问题 I am new to python and was trying to fit dataset distribution using the following code. The actual data is a list that contains two columns- predicted market price and actual market price. And I was trying to use scipy.curve_fit() but it gave me many lines plotted at the same place. Any help is appreciated. # import the necessary modules and define a func. from scipy.optimize import curve_fit def func(x, a, b, c): return a * x** b + c # my data pred_data = [3.0,1.0,1.0,7.0,6.0,1.0,7.0,4.0,9.0

VBA EXCEL Fitting Curve with freely chosen function

醉酒当歌 提交于 2019-12-11 10:04:04
问题 As start situation, I have an xy-chart with some values on it whose progression resemble an exponential function. I need to write a code that draws a fitting curve on the chart, but I have to use a particular function which is not exponential (because I need to get some coefficients from it). One of the functions i need to use is K(C-x)²/(1+x) whereby k and C are the parameters I need.(They are two and it makes it a lot more complicated) Obviously you can't find this kind of structure on the

Using fminsearch to perform distribution fitting

送分小仙女□ 提交于 2019-12-11 09:54:03
问题 Suppose I have a set of univariate data held in the array errors . I would like to fit a PDF to my observed data distribution. My PDF is defined in a function poissvmwalkpdf , whose definition line looks like this: function p = poissvmwalkpdf(theta, mu, kappa, xi) Here, theta is the error (the variable for which values in errors are instances), and mu , kappa , and xi are parameters of the PDF for which I want to find the best fit using maximum-likelihood estimation. This function returns the

How do I optimize and find the coefficients for two equations simultaneously in Python 2.7?

核能气质少年 提交于 2019-12-11 08:12:44
问题 I have data sets that I would like to fit to two equations: y1 = a1 + a2 * T / 2 + a3 * T^2 / 3 + a4 * T^3 / 4 + a5 * T^4 / 5 + a6 / T y2 = a1 * lnT + a2 * T + a3 * T^2 / 2 + a4 * T^3 / 3 + a5 * T^4 / 4 + a7 The two polynomials share some parameters (a1 through a5) so I would like to fit these two equations simultaneously. I tried to do it with scipy.optimize.curve_fit: import numpy as np from scipy.optimize import curve_fit def func(T, a1, a2, a3, a4, a5, a6, a7): y1 = a1 + a2 * T / 2 + a3 *

MATLAB fitting of data to a inverse quadratic equation

牧云@^-^@ 提交于 2019-12-11 08:08:21
问题 I have a bunch of data, and I want a fitting with a function that I want, for example, 1/(ax^2+bx+c) . My objective is to get a,b,c values. Is there any function of MATLAB that helps with this? I have been checking the fit() function, but I didn't reach a conclusion. Which is the best way? 回答1: The model you give can be solved using simple methods: % model function f = @(a,b,c,x) 1./(a*x.^2+b*x+c); % noise function noise = @(z) 0.005*randn(size(z)); % parameters to find a = +3; b = +4; c = -8

Scipy curve_fit for Two Dimensions Not Working - Object Too Deep?

纵然是瞬间 提交于 2019-12-11 07:53:38
问题 I have a 2400 by 2400 array of data which looks something like this: data = [[-2.302670298082603040e-01 -2.304885241061924717e-01 -2.305029774024092148e-01 -2.304807100897505734e-01 -2.303702531336284665e-01 -2.307144352067780346e-01... [-2.302670298082603040e-01 -2.304885241061924717e-01 -2.305029774024092148e-01 -2.304807100897505734e-01 -2.303702531336284665e-01 -2.307144352067780346e-01... ... and I am trying to fit the following 2D Gaussian function: def Gauss2D(x, mux, muy, sigmax,

Delete kinks and smooth curves

安稳与你 提交于 2019-12-11 07:18:27
问题 I have some data which when plotted looks like the one shown in left on the picture attached. It has some kinks which I wish to delete and smooth-en to get a nice curve [shown on right]. Presently I manually delete the kinks and interpolate the deleted part by polynomial of high order [say 9]. Then I repopulate the deleted fragment and re-draw the curve. This takes a long time and I have quite a number of files to process. Could you folks suggest an efficient way to do this ? [in MATLAB or

scipy.optimize curve_fit returns wrong value (depends on the machine)

冷暖自知 提交于 2019-12-11 06:35:54
问题 I wrote some code with scipy.optimize curve_fit. It works perfectly on my computer: Windows 7 Home Premium with Service Pack 1, 64bit Dell Studio 1558 Intel Core i3 cpu M330@2.13GHz 2.13GHz, 3.86 GB of RAM Python 2.7.3 (default, Apr 10 2012, 23:24:47)[MSC v.1500 64 bit (AMD64)] IPython 0.13.1 Then I moved the script to another machine (COMP2): Microsoft Windows XP Professional Version 2002 Service Pack 3, AMD Athlon(tm) II X4 620 Processor 2.61 GHz, 3.25 GB of RAM, Physical Address Extension

Global fitting example with symfit

元气小坏坏 提交于 2019-12-11 06:15:50
问题 I am trying to perform global fitting with symfit package, following symfit documentation. import numpy as np import symfit as sf import matplotlib.pyplot as plt %matplotlib inline # for ipynb # Generate example data t = np.arange(0.0, 600.1, 30) k = 0.005 C1_0, C2_0 = 1.0, 2.0 C1 = C1_0 * np.exp(-k*t) C2 = C2_0 * np.exp(-k*t) # Construct model x_1, x_2, y_1, y_2 = sf.variables('x_1, x_2, y_1, y_2') kg = sf.Parameter(value=0.01, min=0.0, max=0.1) a_1, a_2 = sf.parameters('a_1, a_2')