curve-fitting

Fitting partial Gaussian

流过昼夜 提交于 2019-12-05 05:35:24
I'm trying to fit a sum of gaussians using scikit-learn because the scikit-learn GaussianMixture seems much more robust than using curve_fit. Problem : It doesn't do a great job in fitting a truncated part of even a single gaussian peak: from sklearn import mixture import matplotlib.pyplot import matplotlib.mlab import numpy as np clf = mixture.GaussianMixture(n_components=1, covariance_type='full') data = np.random.randn(10000) data = [[x] for x in data] clf.fit(data) data = [item for sublist in data for item in sublist] rangeMin = int(np.floor(np.min(data))) rangeMax = int(np.ceil(np.max

Gaussian fit to a histogram data in python: Trust Region v/s Levenberg Marquardt

纵然是瞬间 提交于 2019-12-05 05:17:12
问题 My histogram plot clearly shows two peaks. But while curve-fitting it with a double gaussian, it shows just one peak. Followed almost every answer shown in stackoverflow. But failed to get the correct result. It has previously been done by my teacher in Fortran and he got two peaks. I used leastsq of python's scipy.optimize in one trial. Should I give my data also? Here is my code. binss = (max(x) - min(x))/0.05 #0.05 is my bin width n, bins, patches = plt.hist(x, binss, color = 'grey')

Fitting an exponential modified gaussian curve to data with Python

隐身守侯 提交于 2019-12-05 03:33:10
问题 I have a data set and a kernel density estimate for those data. I believe the KDE should be reasonably well described by an exponentinally modified Gaussian, so I'm trying to sample from the KDE and fit those samples with a function of that type. However, when I try to fit using scipy.optimize.curve_fit, my fit doesn't match the data well at all. My code is import scipy.special as sse from scipy.optimize import curve_fit def fit_func(x, l, s, m): return 0.5*l*n.exp(0.5*l*(2*m+l*s*s-2*x))*sse

How to fit a polynomial with some of the coefficients constrained?

会有一股神秘感。 提交于 2019-12-05 02:40:43
问题 Using NumPy's polyfit (or something similar) is there an easy way to get a solution where one or more of the coefficients are constrained to a specific value? For example, we could find the ordinary polynomial fitting using: x = np.array([0.0, 1.0, 2.0, 3.0, 4.0, 5.0]) y = np.array([0.0, 0.8, 0.9, 0.1, -0.8, -1.0]) z = np.polyfit(x, y, 3) yielding array([ 0.08703704, -0.81349206, 1.69312169, -0.03968254]) But what if I wanted the best fit polynomial where the third coefficient (in the above

Vertical line fit using polyfit

半城伤御伤魂 提交于 2019-12-05 01:58:01
Its just a basic question. I am fitting lines to scatter points using polyfit . I have some cases where my scatter points have same X values and polyfit cant fit a line to it. There has to be something that can handle this situation. After all, its just a line fit. I can try swapping X and Y and then fir a line. Any easier method because I have lots of sets of scatter points and want a general method to check lines. Main goal is to find good-fit lines and drop non-linear features. Andrey Rubshtein First of all, this happens due to the method of fitting that you are using. When doing polyfit ,

Fit sine wave with a distorted time-base

落爺英雄遲暮 提交于 2019-12-04 23:13:57
问题 I want to know the best way to fit a sine-wave with a distorted time base, in Matlab. The distortion in time is given by a n-th order polynomial (n~10), of the form t_distort = P(t) . For example, consider the distortion t_distort = 8 + 12t + 6t^2 + t^3 (which is just the power series expansion of (t-2)^3 ). This will distort a sine-wave as follows: I want to be able to find the distortion given this distorted sine-wave. (i.e. I want to find the function t = G(t_distort) , but t_distort = P(t

centerline of a polygonal blob (binary image)

别等时光非礼了梦想. 提交于 2019-12-04 21:00:32
问题 I have a binary image of a worm (blob extraction which works well). I am interested in fitting a centerline on the blowb (worm). So far I came up with this: starting from a polygon (after outline extraction of blob in the image) I applied a voronoi computation and discarded all vertices which are outside of the polygon (blue) which gave me the black center line which I can further use to fit a smooth centerline. However, this computation is not at all robust (due removing voronoi vertices not

How can I fit my plots from measured data?

人盡茶涼 提交于 2019-12-04 19:02:49
How can I fit my plots? Up to now, I've got the following code, which plots a variety of graphs from an array (data from an experiment) as it is placed in a loop: import matplotlib as plt plt.figure(6) plt.semilogx(Tau_Array, Correlation_Array, '+-') plt.ylabel('Correlation') plt.xlabel('Tau') plt.title("APD" + str(detector) + "_Correlations_log_graph") plt.savefig(DataFolder + "/APD" + str(detector) + "_Correlations_log_graph.png") This works so far with a logarithmic plot, but I am wondering how the fitting process could work right here. In the end I would like to have some kind of a formula

How to quantitatively measure goodness of fit in SciPy?

荒凉一梦 提交于 2019-12-04 17:16:28
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, 53.9]) y = np.array([1, 50, 60, 70, 80, 90, 100]) y_residual = np.empty(shape=(1, len(y))) residual

Fitting data to a B-spline in MATLAB

好久不见. 提交于 2019-12-04 17:06:30
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 points, but I cannot set the control points, i.e. the elements of the row. Any help would be much