curve-fitting

lmfit model fitting and then prediction

你。 提交于 2021-02-10 21:52:12
问题 I was adopting lmfit to do a curve fitting and use that fitted model to do prediction. However, the following code did not achieve what I want. Could you please help? Thanks. import numpy as np from lmfit import Model def linearModel(x, a0, a1): return a0+a1*x #main code begin here X=[1,2,4] # data for fitting y=[2,4,6] # data for fitting gmodel = Model(linearModel) #select model params = gmodel.make_params(a0=1, a1=1) # initial params result = gmodel.fit(y, params, x=X) # curve fitting x1=[1

Python- scipy ODR going crazy

。_饼干妹妹 提交于 2021-02-10 06:09:37
问题 I would like to use scipy's ODR to fit a curve to a set of variables with variances. In this case, I am fitting a linear function with a set Y axis crossing point (e.g. a*x+100 ). Due to my inability to find an estimator (I asked about that here), I am using scipy.optimize curve_fit to estimate the initial a value. Now, the function works perfectly without standard deviation, but when I add it, the output makes completely no sense (the curve is far above all of the points). What could be the

Curve fitting with broken power law in Python

一笑奈何 提交于 2021-02-08 12:12:13
问题 Im trying to follow and re-use a piece of code (with my own data) suggested by someone named @ThePredator (I couldn't comment on that thread since I don't currently have the required reputation of 50). The full code is as follows: import numpy as np # This is the Numpy module from scipy.optimize import curve_fit # The module that contains the curve_fit routine import matplotlib.pyplot as plt # This is the matplotlib module which we use for plotting the result """ Below is the function that

How to fit non-linear data's in python

↘锁芯ラ 提交于 2021-02-08 07:38:35
问题 How to fit a non linear data's using scipy.optimize import curve_fit in Python using following 3 methods: Gaussian. Lorentz fit. Langmuir fit. I am just able to link and plot from my data file. from matplotlib import pyplot as plt from matplotlib import style import numpy as np import pylab from scipy.optimize import curve_fit style.use('ggplot') data = np.genfromtxt('D:\csvtrail3.csv', delimiter=',', skiprows=1) x=data[:,0] y=data[:,1] data.fit_lorentzians() plt.plot(x, y) plt.title('Epic

Matlab Image Baseline (Offset Removal) Correction

笑着哭i 提交于 2021-02-08 07:32:09
问题 I have this plot: and want to flatten its baseline/reduce offset using Matlab. Basically like a baseline correction for a spectrum but here I've got a mesh and can't get my head around it how to flatten its baseline when dealing with a matrix? Basically the dot should stay but the surrounding is actually zero. The noise can stay, though. Here is the image: I am wondering if something like this works: for x=1:1201 for y=1:1201 Ibasetest = polyfit(x,y,1); end end Simply put do a baseline for

Matlab Image Baseline (Offset Removal) Correction

有些话、适合烂在心里 提交于 2021-02-08 07:31:31
问题 I have this plot: and want to flatten its baseline/reduce offset using Matlab. Basically like a baseline correction for a spectrum but here I've got a mesh and can't get my head around it how to flatten its baseline when dealing with a matrix? Basically the dot should stay but the surrounding is actually zero. The noise can stay, though. Here is the image: I am wondering if something like this works: for x=1:1201 for y=1:1201 Ibasetest = polyfit(x,y,1); end end Simply put do a baseline for

Gaussian fit returning negative sigma

狂风中的少年 提交于 2021-02-07 20:20:39
问题 One of my algorithms performs automatic peak detection based on a Gaussian function, and then later determines the the edges based either on a multiplier (user setting) of the sigma or the 'full width at half maximum'. In the scenario where a user specified that he/she wants the peak limited at 2 Sigma, the algorithm takes -/+ 2*sigma from the peak center (mu). However, I noticed that the sigma returned by curve_fit can be negative, which is something that has been noticed before as can be

Curve fit an exponential decay function in Python using given data points

℡╲_俬逩灬. 提交于 2021-02-07 19:19:26
问题 With the curve_fit function in SciPy I'm able to determine the coefficients that represent the curve shown in the plot below. def func2(t, tau): return np.exp(-t / tau) t2 = np.linspace(0, 4, 50) y2 = func2(t2, 1.2) y2_noise = 0.2 * np.random.normal(size=t2.size) y2_curve_noise = y2 + y2_noise popt2, pcov2 = curve_fit(func2, t2, y2_curve_noise) tau2, = popt2 y2_fit = func2(t2, tau2) I would like to use a similar function to represent some data points. However, I'm unable to use this approach

Curve fit an exponential decay function in Python using given data points

我的未来我决定 提交于 2021-02-07 19:17:56
问题 With the curve_fit function in SciPy I'm able to determine the coefficients that represent the curve shown in the plot below. def func2(t, tau): return np.exp(-t / tau) t2 = np.linspace(0, 4, 50) y2 = func2(t2, 1.2) y2_noise = 0.2 * np.random.normal(size=t2.size) y2_curve_noise = y2 + y2_noise popt2, pcov2 = curve_fit(func2, t2, y2_curve_noise) tau2, = popt2 y2_fit = func2(t2, tau2) I would like to use a similar function to represent some data points. However, I'm unable to use this approach

Fit maximum convex hull to interior of a set of points

守給你的承諾、 提交于 2021-02-07 09:46:51
问题 I'd like to find the largest convex hull which fits in the interior of a set of points. I have a set of points which are roughly circular, with a large number of outlier points outside of the circle I'd like to fit. Imagine a circle with "solar flares"... I want to fit the circle and completely ignore the flares. I've tried various fit and culling strategies, but they aren't working well. I've searched quite a bit and not found a solution. Thanks in advance. 回答1: The notion you need may be