curve-fitting

Difference between Levenberg-Marquardt-Algorithm and ODR

醉酒当歌 提交于 2020-01-12 10:38:12
问题 I was able to fit curves to a x/y dataset using peak-o-mat, as shown below. Thats a linear background and 10 lorentzian curves. Since I need to fit many similar curves I wrote a scripted fitting routine, using mpfit.py, which is a Levenberg-Marquardt-Algorithm. However the fit takes longer and, in my opinion, is less accurate than the peak-o-mat result: Starting values Fit result with fixed linear background (values for linear background taken from the peak-o-mat result) Fit result with all

Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000

你说的曾经没有我的故事 提交于 2020-01-12 06:37:07
问题 I want to make an logharitmic fit. But I keep getting the a runtime error: Optimal parameters not found: Number of calls to function has reached maxfev = 1000 I use the following script. Can anyone tell me where I go wrong? I use Spyder an am still a beginner. import math import matplotlib as mpl from scipy.optimize import curve_fit import numpy as np #data F1=[735.0,696.0,690.0,683.0,680.0,678.0,679.0,675.0,671.0,669.0,668.0,664.0,664.0] t1=[1,90000.0,178200.0,421200.0,505800.0,592200.0

How can fit curve on this log data?

青春壹個敷衍的年華 提交于 2020-01-11 13:08:55
问题 I have a problem with a fit curve on this data: On x axes we have a data about wind intensity (m/s), on y axes we have log data (fish catch). I fitted a curve (nls model, Gaussian curve) only on data without logaritm, but when i tried on log data, R tell me: Error in nls(mean.w ~ k * exp(-1/2 * (x.wind - mu)^2/sigma^2), : singolar gradient The model is: mean.w ~ k * exp(-1/2 * (x.wind - mu)^2/sigma^2) , where k,mu and sigma are the parameters to estimate, and mean.w # is y axes (log fish

Implementing a Broken Power Law as a fitting function in Origin

巧了我就是萌 提交于 2020-01-11 11:38:08
问题 Good day, I'm trying to use the function builder in origin (OriginLab) to create a new function to fit with, the broken power law (http://en.wikipedia.org/wiki/Power_law#Broken_power_law) So, I think I got the actual function part down. For this I used if(x<xc) y =x^a1; if(x>xc) y = x^(a1-a2)*x^a2; if(x==xc) y = 0; Where xc, a1 and a2 are the parameters. However, I then get to the point where you have to choose a bunch of stuff (parameter ranges, script you run to guess initial values, etc)

Curve fitting this data in R?

浪子不回头ぞ 提交于 2020-01-10 05:27:06
问题 For a few days I've been working on this problem and I'm stuck ... I have performed a number of Monte Carlo simulations in R which gives an output y for each input x and there is clearly some simple relationship between x and y, so I want to identify the formula and its parameters. But I can't seem to get a good overall fit for both the 'Low x' and 'High x' series, e.g. using a logarithm like this: dat = data.frame(x=x, y=y) fit = nls(y~a*log10(x)+b, data=dat, start=list(a=-0.8,b=-2), trace

Scipy curve_fit does not seem to change the initial parameters

一笑奈何 提交于 2020-01-06 02:30:33
问题 I know that there are several similar questions such as Use of curve_fit to fit data but the answer there (specific float type) does not seem to work for me. I am wondering if anyone is able to explain to me why the following code (which is an adaptation from an answer -> https://stackoverflow.com/a/11507723/1093485) does not work. sample code: #! /usr/bin/env python import numpy from scipy.optimize import curve_fit import matplotlib.pyplot as plt def gaussFunction(x, A, mu, sigma): return A

scipy.optimize.curve_fit setting a “fixed” parameter

江枫思渺然 提交于 2020-01-05 13:42:23
问题 I'm using scipy.optimize.curve_fit to approximate peaks in my data with Gaussian functions. This works well for strong peaks, but it is more difficult with weaker peaks. However, I think fixing a parameter (say, width of the Gaussian) would help with this. I know I can set initial "estimates" but is there a way that I can easily define a single parameter without changing the function I'm fitting to? 回答1: If you want to "fix" a parameter of your fit function, you can just define a new fit

scipy.optimize.curve_fit setting a “fixed” parameter

南楼画角 提交于 2020-01-05 13:41:03
问题 I'm using scipy.optimize.curve_fit to approximate peaks in my data with Gaussian functions. This works well for strong peaks, but it is more difficult with weaker peaks. However, I think fixing a parameter (say, width of the Gaussian) would help with this. I know I can set initial "estimates" but is there a way that I can easily define a single parameter without changing the function I'm fitting to? 回答1: If you want to "fix" a parameter of your fit function, you can just define a new fit

Not sure what distribution to use to model my data

ぐ巨炮叔叔 提交于 2020-01-04 09:08:07
问题 I have a set of astronomical data, to which I'm trying to fit a curve: My fitting code is param = stats.norm.fit(df['delta z'].dropna()) # Fit a normal distribution to the data pdf_fitted = stats.norm.pdf(df['delta z'], *param) x = np.linspace(*df['delta z'].agg([min, max]), 1000) # x-values binwidth = np.diff(edges).mean() ax.plot(x, stats.norm.pdf(x, *param)*h.sum()*binwidth, color = 'r') which produces Now, I'm clearly doing this in the wrong way, because the curve doesn't fit the data at

How to fit a circle to a set of points with a constrained radius?

一曲冷凌霜 提交于 2020-01-04 05:20:43
问题 I have a set of points that represent a small arc of a circle. The current code fits a circle to these points using linear least-squares: void fit_circle(const std::vector<cv::Point2d> &pnts,cv::Point2d &centre, double &radius) { int cols = 3; cv::Mat X( static_cast<int>(pnts.size()), cols, CV_64F ); cv::Mat Y( static_cast<int>(pnts.size()), 1, CV_64F ); cv::Mat C; if (int(pnts.size()) >= 3 ) { for (size_t i = 0; i < pnts.size(); i++) { X.at<double>(static_cast<int>(i),0) = 2 * pnts[i].x; X