curve-fitting

Curve fitting in MATLAB: different result form toolbox vs command line?

最后都变了- 提交于 2019-12-06 11:10:28
This is the data I am using for Y data: 0.577032413537833 0.288198874369377 0.192282280031568 0.143824619265244 0.114952782524097 0.0960518606520442 0.0824041879978560 0.0719078360110914 0.0640919744028295 0.0572120310249072 0.0519630635470660 0.0479380073164273 0.0443712721513307 X is simply the integer value from 1 to 13 and I know that this is power function of form a*x^b+c from running GUI cftool on MATLAB with rather high R-square value (1) To perform the fit on command line, I used: >> g = fittype('a*x^b+c','coeff',{'a','b','c'}) >> x=1:13; >> [c3,gof3] = fit(x',B3(:,1),g) This results

How to quantitatively measure goodness of fit in SciPy?

早过忘川 提交于 2019-12-06 10:56:53
问题 I am tying to find out the best fit for data given. What I did is I loop through various values of n and calculate the residual at each p using the formula ((y_fit - y_actual) / y_actual) x 100. Then I calculate the average of this for each n and then find the minimum residual mean and the corresponding n value and fit using this value. A reproducible code included: import numpy as np import matplotlib.pyplot as plt from scipy import optimize x = np.array([12.4, 18.2, 20.3, 22.9, 27.7, 35.5,

Fitting data to a B-spline in MATLAB

南楼画角 提交于 2019-12-06 10:29:22
问题 I am trying to estimate missing values in time-series data which is in the form of a matrix. The columns represent the time points,i.e. Now, I want to fit each row of the matrix to a B-Spline, and use it to estimate the missing values. I could fit the data to a normal spline using MATLAB, but I am completely stuck at trying to figure out how to fit the data to create a B-Spline. Using the default bspline function in the Curve Fitting Toolbox lets me set the knot vector to the vector of time

how to calculate control points on a bezier curve?

断了今生、忘了曾经 提交于 2019-12-06 09:56:47
I do have a bezier curve, and at a certain point, I want a second bezier curve "branching off" the first curve in a smooth manner. Together with calculating the intersection point (with a percentage following the Bezier curve), I need also the control point (the tangent and weight). The intersection point is calculated with the following piece of javascript: getBezier = function getBez(percent,p1,cp1,cp2,p2) { function b1(t) { return t*t*t } function b2(t) { return 3*t*t*(1-t) } function b3(t) { return 3*t*(1-t)*(1-t) } function b4(t) { return (1-t)*(1-t)*(1-t) } var pos = {x:0,y:0}; pos.x =

Separating gaussian components of a curve using python

送分小仙女□ 提交于 2019-12-06 08:32:29
I am trying to deblend the emission lines of low resolution spectrum in order to get the gaussian components. This plot represents the kind of data I am using: After searching a bit, the only option I found was the application of the gauest function from the kmpfit package ( http://www.astro.rug.nl/software/kapteyn/kmpfittutorial.html#gauest ). I have copied their example but I cannot make it work. I wonder if anyone could please offer me any alternative to do this or how to correct my code: import numpy as np import matplotlib.pyplot as plt from scipy import optimize def CurveData(): x = np

Scipy sigmoid curve fitting

北战南征 提交于 2019-12-06 06:29:09
问题 I have some data points and would like to find a fitting function, I guess a cumulative Gaussian sigmoid function would fit, but I don't really know how to realize that. This is what I have right now: import numpy as np import pylab from scipy.optimize import curve_fit def sigmoid(x, a, b): y = 1 / (1 + np.exp(-b*(x-a))) return y xdata = np.array([400, 600, 800, 1000, 1200, 1400, 1600]) ydata = np.array([0, 0, 0.13, 0.35, 0.75, 0.89, 0.91]) popt, pcov = curve_fit(sigmoid, xdata, ydata) print

Curve fitting for each column in Pandas + extrapolate values

那年仲夏 提交于 2019-12-06 05:19:30
I have a data set with some 300 columns, each of them depth-dependent. The simplified version of the Pandas DataFrame would look something like this: import matplotlib.pyplot as plt import numpy as np import pandas as pd from scipy_optimize import curve_fit df1 = pd.DataFrame({'depth': [1.65, 2.15, 2.65, 3.15, 3.65, 4.15, 4.65, 5.15, 5.65, 6.15, 6.65, 7.15, 7.65, 8.15, 8.65], '400.0': [13.909261, 7.758734, 3.513627, 2.095409, 1.628918, 0.782643, 0.278548, 0.160153, -0.155895, -0.152373, -0.147820, -0.023997, 0.010729, 0.006050, 0.002356], '401.0': [14.581624, 8.173803, 3.757856, 2.223524, 1

Suggestions for fitting noisy exponentials with scipy curve_fit?

梦想与她 提交于 2019-12-06 04:47:18
问题 I'm trying to fit data that would be generally modeled by something along these lines: def fit_eq(x, a, b, c, d, e): return a*(1-np.exp(-x/b))*(c*np.exp(-x/d)) + e x = np.arange(0, 100, 0.001) y = fit_eq(x, 1, 1, -1, 10, 0) plt.plot(x, y, 'b') An example of an actual trace, though, is much noisier: If I fit the rising and decaying components separately, I can arrive at somewhat OK fits: def fit_decay(df, peak_ix): fit_sub = df.loc[peak_ix:] guess = np.array([-1, 1e-3, 0]) x_zeroed = fit_sub

scipy.optimize.curve_fit, TypeError: unsupported operand type

守給你的承諾、 提交于 2019-12-06 02:39:18
问题 I've done a search and the problem seems similar to Python scipy: unsupported operand type(s) for ** or pow(): 'list' and 'list' however the solution posted there did not work and I think it may actually be different. I am trying to fit a curve to data using scipy.curve_fit, when I leave all 3 parameters free everything works correctly and I get the expected result. def func(x,a,b,c): return a*np.exp(b*(x**c)) popt, pcov = curve_fit(func,x,y) However when I try to fix one of the values (c=2)

How to fit and plot exponential decay function using ggplot2 and linear approximation

被刻印的时光 ゝ 提交于 2019-12-06 01:31:15
I am trying to fit exponential decay functions on data which has only few time points. I would like to use the exponential decay equation y = y0*e^(-r*time) in order to compare r (or eventually half-life) between datasets and factors. I have understood that using a linear fit instead of nls is a better alternative for this particular function [ 1 , 2 ], if I want to estimate the confidence intervals (which I do). Copy this to get some example data: x <- structure(list(Factor = structure(c(3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 4L, 4L, 4L, 4L