curve-fitting

Surface Curvature Matlab equivalent in Python

别等时光非礼了梦想. 提交于 2019-11-30 21:57:19
I was trying to calculate the curvature of a surface given by array of points (x,y,z). Initially I was trying to fit a polynomial equation z=a + bx + cx^2 + dy + exy + fy^2) and then calculate the gaussian curvature $ K = \frac{F_{xx}\cdot F_{yy}-{F_{xy}}^2}{(1+{F_x}^2+{F_y}^2)^2} $ However the problem is fitting if the surface is complex. I found this Matlab code to numerically calculate curvature. I wonder how to do the same in Python. function [K,H,Pmax,Pmin] = surfature(X,Y,Z), % SURFATURE - COMPUTE GAUSSIAN AND MEAN CURVATURES OF A SURFACE % [K,H] = SURFATURE(X,Y,Z), WHERE X,Y,Z ARE 2D

Interactive BSpline fitting in Python

只愿长相守 提交于 2019-11-30 21:26:04
Using the following function, one can fit a cubic spline on input points P: def plotCurve(P): pts = np.vstack([P, P[0]]) x, y = pts.T i = np.arange(len(pts)) interp_i = np.linspace(0, i.max(), 100000 * i.max()) xi = interp1d(i, x, kind='cubic')(interp_i) yi = interp1d(i, y, kind='cubic')(interp_i) fig, ax = plt.subplots() fig,ax=plt.subplots() ax.plot(xi, yi) ax.plot(x, y, 'ko') #plt.show() return xi,yi The input points P can be of the following form: P=[(921,1181),(951,1230),(993,1243),(1035,1230), (1065,1181),(1045,1130),(993,1130),(945,1130)] Now, I wish to make these points of P draggable,

Create scipy curve fitting definitions for fourier series dynamically

荒凉一梦 提交于 2019-11-30 21:03:39
I'd like to achieve a fourier series development for a x-y-dataset using numpy and scipy . At first I want to fit my data with the first 8 cosines and plot additionally only the first harmonic . So I wrote the following two function defintions: # fourier series defintions tau = 0.045 def fourier8(x, a1, a2, a3, a4, a5, a6, a7, a8): return a1 * np.cos(1 * np.pi / tau * x) + \ a2 * np.cos(2 * np.pi / tau * x) + \ a3 * np.cos(3 * np.pi / tau * x) + \ a4 * np.cos(4 * np.pi / tau * x) + \ a5 * np.cos(5 * np.pi / tau * x) + \ a6 * np.cos(6 * np.pi / tau * x) + \ a7 * np.cos(7 * np.pi / tau * x) + \

Python / Scipy - implementing optimize.curve_fit 's sigma into optimize.leastsq

断了今生、忘了曾经 提交于 2019-11-30 20:37:11
I am fitting data points using a logistic model. As I sometimes have data with a ydata error, I first used curve_fit and its sigma argument to include my individual standard deviations in the fit. Now I switched to leastsq, because I needed also some Goodness of Fit estimation that curve_fit could not provide. Everything works well, but now I miss the possibility to weigh the least sqares as "sigma" does with curve_fit. Has someone some code example as to how I could weight the least squares also in leastsq? Thanks, Woodpicker I just found that it is possible to combine the best of both worlds

Curve fitting in R using nls

青春壹個敷衍的年華 提交于 2019-11-30 20:14:38
I'm trying to fit a curve over (the tail of) the following data: [1] 1 1 1 1 1 1 2 1 2 2 3 2 1 1 4 3 2 11 6 2 16 7 17 36 [25] 27 39 41 33 42 66 92 138 189 249 665 224 309 247 641 777 671 532 749 506 315 292 281 130 [49] 137 91 40 27 34 19 1 I'm using the following function in R to accomplish this: nls(y~a x exp(-b*x^2),start=list(a=1,b=1),trace=TRUE) However, I'm getting the following error: 3650202 : 1 1 Error in numericDeriv(form[[3L]], names(ind), env) : Missing value or an infinity produced when evaluating the model When using the following, artificial values for x and y, everything works

Curve fitting in Scipy with 3d data and parameters

喜你入骨 提交于 2019-11-30 20:02:07
问题 I am working on fitting a 3d distribution function in scipy. I have a numpy array with counts in x- and y-bins, and I am trying to fit that to a rather complicated 3-d distribution function. The data is fit to 26 (!) parameters, which describe the shape of its two constituent populations. I learned here that I have to pass my x- and y-coordinates as 'args' when I call leastsq. The code presented by unutbu works as written for me, but when I try to apply it to my specific case, I am given the

Dose Response - Global curve fitting using R

萝らか妹 提交于 2019-11-30 19:44:40
问题 I have the following dose response data and wish to plot dose response model and global fit curve. [xdata = drug concentration; ydata(0-5) = response values at different concentrations of the drug]. I plotted the Std Curve without an issue. Std Curve Data fit: df <- data.frame(xdata = c(1000.00,300.00,100.00,30.00,10.00,3.00,1.00,0.30, 0.10,0.03,0.01,0.00), ydata = c(91.8,95.3,100,123,203,620,1210,1520,1510,1520,1590, 1620)) nls.fit <- nls(ydata ~ (ymax*xdata / (ec50 + xdata)) + Ns*xdata +

Curve fit fails with exponential but zunzun gets it right

久未见 提交于 2019-11-30 19:25:38
问题 I'm trying to compute the best fit of two forms of an exponential to some x, y data (the data file can be downloaded from here) Here's the code: from scipy.optimize import curve_fit import numpy as np # Get x,y data data = np.loadtxt('data.txt', unpack=True) xdata, ydata = data[0], data[1] # Define first exponential function def func(x, a, b, c): return a * np.exp(b * x) + c # Get parameters estimate popt, pcov = curve_fit(func, xdata, ydata) print popt # Define second exponential function

Playing perfect Tetris: how to align and scale two curves using scaling and translation?

天大地大妈咪最大 提交于 2019-11-30 18:56:54
Given parameters of scaling on the y axis (s) and translation on the x axis (t), how to scale and align two curves that do not coincide when the purpose is to maximize curve superposition (not minimize distance)? As indicated by @DWin, this could be rebranded "How to play Tetris perfectly with R", though it does have applications far beyond winning a Tetris game. A variation of this question could involve any number of rigid body transformations (rotation, translation and scaling). Given curve 1 curve1<-data.frame(x=c(1,1,2,2,3), y=c(9,6,6,3,3)) with(curve1, plot(x=x, y=y, type="l", xlim=c(0

Surface Curvature Matlab equivalent in Python

吃可爱长大的小学妹 提交于 2019-11-30 18:10:46
问题 I was trying to calculate the curvature of a surface given by array of points (x,y,z). Initially I was trying to fit a polynomial equation z=a + bx + cx^2 + dy + exy + fy^2) and then calculate the gaussian curvature $ K = \frac{F_{xx}\cdot F_{yy}-{F_{xy}}^2}{(1+{F_x}^2+{F_y}^2)^2} $ However the problem is fitting if the surface is complex. I found this Matlab code to numerically calculate curvature. I wonder how to do the same in Python. function [K,H,Pmax,Pmin] = surfature(X,Y,Z), %