curve-fitting

How can I fit a gaussian curve in python?

左心房为你撑大大i 提交于 2019-12-03 02:24:36
I'm given an array and when I plot it I get a gaussian shape with some noise. I want to fit the gaussian. This is what I already have but when I plot this I do not get a fitted gaussian, instead I just get a straight line. I've tried this many different ways and I just can't figure it out. random_sample=norm.rvs(h) parameters = norm.fit(h) fitted_pdf = norm.pdf(f, loc = parameters[0], scale = parameters[1]) normal_pdf = norm.pdf(f) plt.plot(f,fitted_pdf,"green") plt.plot(f, normal_pdf, "red") plt.plot(f,h) plt.show() You can use fit from scipy.stats.norm as follows: import numpy as np from

Find bezier control-points for curve passing through N points

一个人想着一个人 提交于 2019-12-03 02:09:29
Considering the following nice solution for finding cubic Bézier control points for a curve passing through 4 points: How to find control points for a BezierSegment given Start, End, and 2 Intersection Pts in C# - AKA Cubic Bezier 4-point Interpolation I wonder, if there is a straightforward extension to this for making the Bézier curve pass through N points, for N > 2 and maybe N ≤ 20? This is a really old question, but I'm leaving this here for people who have the same question in the future. @divanov has mentioned that there's no Bezier curve passing through N arbitrary points for N >4. I

Curve Fitting 3D data set

隐身守侯 提交于 2019-12-03 01:38:47
The curve-fitting problem for 2D data is well known (LOWESS, etc.) but given a set of 3D data points, how do I fit a 3D curve (eg. a smoothing/regression spline) to this data? MORE: I'm trying to find a curve, fitting the data provided by vectors X,Y,Z which have no known relation. Essentially, I have a 3D point cloud, and need to find a 3D trendline. MORE: I apologize for the ambiguity. I tried several approaches (I still haven't tried modifying the linear fit) and a random NN seems to work out best. I.e., I randomly pick a point from the point cloud, find the centroid of it's neighbors

On the issue of automatic time series fitting using R

↘锁芯ラ 提交于 2019-12-02 19:50:01
we have to fit about 2000 or odd time series every month, they have very idiosyncratic behavior in particular, some are arma/arima, some are ewma, some are arch/garch with or without seasonality and/or trend (only thing in common is the time series aspect). one can in theory build ensemble model with aic or bic criterion to choose the best fit model but is the community aware of any library which attempts to solve this problem? Google made me aware of the below one by Rob J Hyndman link but are they any other alternatives? Rob Hyndman There are two automatic methods in the forecast package :

trying to display original and fitted data (nls + dnorm) with ggplot2's geom_smooth()

僤鯓⒐⒋嵵緔 提交于 2019-12-02 18:29:19
I am exploring some data, so the first thing I wanted to do was try to fit a normal (Gaussian) distribution to it. This is my first time trying this in R, so I'm taking it one step at a time. First I pre-binned my data: myhist = data.frame(size = 10:27, counts = c(1L, 3L, 5L, 6L, 9L, 14L, 13L, 23L, 31L, 40L, 42L, 22L, 14L, 7L, 4L, 2L, 2L, 1L) ) qplot(x=size, y=counts, data=myhist) Since I want counts, I need to add a normalization factor (N) to scale up the density: fit = nls(counts ~ N * dnorm(size, m, s), data=myhist, start=c(m=20, s=5, N=sum(myhist$counts)) ) Then I create the fitted data

Specify clamped knot vector in bs-call

随声附和 提交于 2019-12-02 17:26:29
问题 I intend to fit a clamped b-spline to a set of control points in R, but have trouble understanding the use of the knots parameter in bs. Given a set of control points: path <- data.frame( x = c(3, 3.5, 4.6875, 9.625, 5.5625, 19.62109375, 33.6796875, 40.546875, 36.59375, 34.5, 33.5, 33), y = c(0, 1, 4, 5, 6, 8, 7, 6, 5, 2, 1, 0) ) I fit x and y independently against the distance along the path: path$distance <- c(0, cumsum(sqrt(diff(path[,1])^2 + diff(path[,2])^2))) path$distance ## [1] 0

Plot vs ggplot2 in R and how to extract fit parameters

那年仲夏 提交于 2019-12-02 17:19:42
问题 I have the following data in a data.frame called t DayNum MeanVolume StdDev StdErr 1 13 207.0500 41.00045 5.125057 2 15 142.7625 27.87236 3.484045 3 18 77.5500 19.43928 2.429910 4 21 66.3750 20.56403 2.570504 5 26 67.0500 29.01576 3.626970 6 29 66.4750 25.94537 3.243171 7 33 76.9625 25.31374 3.164218 8 36 91.2875 37.01719 4.627149 9 40 102.0500 29.39898 3.674872 10 43 100.8250 24.22830 3.028538 11 47 120.5125 28.80592 3.600740 12 50 147.8875 35.82894 4.478617 13 54 126.7875 45.43204 5.679004

How can I perform a least-squares fitting over multiple data sets fast?

喜夏-厌秋 提交于 2019-12-02 16:25:55
I am trying to make a gaussian fit over many data points. E.g. I have a 256 x 262144 array of data. Where the 256 points need to be fitted to a gaussian distribution, and I need 262144 of them. Sometimes the peak of the gaussian distribution is outside the data-range, so to get an accurate mean result curve-fitting is the best approach. Even if the peak is inside the range, curve-fitting gives a better sigma because other data is not in the range. I have this working for one data point, using code from http://www.scipy.org/Cookbook/FittingData . I have tried to just repeat this algorithm, but

filtering/removing noise

烈酒焚心 提交于 2019-12-02 14:44:57
问题 The question is simple. How do I go about removing noise from data? I have made up some x and y values along with some noise that is a gross simplification of the data I am dealing with (apart from the random noise I cannot make that the same as the noise I have to deal with). I don't really know if I need to filter or smooth. My file contains two sets of data that need to be plotted and there is experimental noise in this data, what is the best way to remove it? smoothing or filtering? I

How to Fit to The Outer Shell of a Function

十年热恋 提交于 2019-12-02 13:55:26
问题 I am trying to make a gaussian fit on a function that is messy. I want to only fit the exterior outer shell (these are not just the max values at each x, because some of the max values will be too low too, because the sample size is low). from scipy.optimize import curve_fit def Gauss(x, a, x0, sigma, offset): return a * np.exp(-np.power(x - x0,2) / (2 * np.power(sigma,2))) + offset def fitNormal(x, y): popt, pcov = curve_fit(Gauss, x, y, p0=[np.max(y), np.median(x), np.std(x), np.min(y)])