curve-fitting

Scipy's Optimize Curve Fit Limits

三世轮回 提交于 2019-11-30 17:29:25
问题 Is there any way I can provide limits for the Scipy's Optimize Curve Fit? My example: def optimized_formula(x, m_1, m_2, y_1, y_2, ratio_2): return (log(x[0]) * m_1 + m_2)*((1 - x[1]/max_age)*(1-ratio_2)) + ((log(x[1]) * y_1 + y_2)*(x[1]/max_age)*ratio_2) popt, pcov = optimize.curve_fit(optimized_formula, usage_and_age, prices) x[0] is age and max_age is a constant. With that in mind, as x[0] approaches maximum, x[1]/max_age approaches 1. Is it possible to provide a constraint/limit whereby x

Using OpenCV fitEllipse() for circle fitting

a 夏天 提交于 2019-11-30 15:00:06
Is it valid to use OpenCV fitEllipse for circle fitting. fitEllipse() returns cv::RotatedRect how about averaging width and height to get fitted circle radius? I think that the "validity" of using cv::fitEllipse for fitting circles depends on the precision you require for the fitting. For example you can run your algorithm on a test set, fitting points with cv::fitEllipse and logging the length of the two axes of the ellipse, then have a look at the distributions of the ratio of two axes or at the difference between the major and the minor axis; you can find how much your supposed circles

Fitting lognormal distribution using Scipy vs Matlab

无人久伴 提交于 2019-11-30 14:23:51
问题 I am trying to fit a lognormal distribution using Scipy. I've already done it using Matlab before but because of the need to extend the application beyond statistical analysis, I am in the process of trying to reproduce the fitted values in Scipy. Below is the Matlab code I used to fit my data: % Read input data (one value per line) x = []; fid = fopen(file_path, 'r'); % reading is default action for fopen disp('Reading network degree data...'); if fid == -1 disp('[ERROR] Unable to open data

R smooth.spline(): smoothing spline is not smooth but overfitting my data

我们两清 提交于 2019-11-30 14:08:47
I have several data points which seem suitable for fitting a spline through them. When I do this, I get a rather bumpy fit, like overfitting, which is not what I understand as smoothing. Is there a special option / parameter for getting back the function of a really smooth spline like here . The usage of the penalty parameter for smooth.spline didn't have any visible effect. Maybe I did it wrong? Here are data and code: results <- structure( list( beta = c( 0.983790622281964, 0.645152464354322, 0.924104713597375, 0.657703886566088, 0.788138034115623, 0.801080207252363, 1, 0.858337365965949, 0

When to choose nls() over loess()?

99封情书 提交于 2019-11-30 13:18:26
问题 If I have some (x,y) data, I can easily draw straight-line through it, e.g. f=glm(y~x) plot(x,y) lines(x,f$fitted.values) But for curvy data I want a curvy line. It seems loess() can be used: f=loess(y~x) plot(x,y) lines(x,f$fitted) This question has evolved as I've typed and researched it. I started off with wanting to a simple function to fit curvy data (where I know nothing about the data), and wanting to understand how to use nls() or optim() to do that. That was what everyone seemed to

How can I calculate a trend line in PHP?

こ雲淡風輕ζ 提交于 2019-11-30 11:37:28
问题 So I've read the two related questions for calculating a trend line for a graph, but I'm still lost. I have an array of xy coordinates, and I want to come up with another array of xy coordinates (can be fewer coordinates) that represent a logarithmic trend line using PHP. I'm passing these arrays to javascript to plot graphs on the client side. 回答1: Logarithmic Least Squares Since we can convert a logarithmic function into a line by taking the log of the x values, we can perform a linear

fitting multivariate curve_fit in python

倾然丶 夕夏残阳落幕 提交于 2019-11-30 11:11:04
I'm trying to fit a simple function to two arrays of independent data in python. I understand that I need to bunch the data for my independent variables into one array, but something still seems to be wrong with the way I'm passing variables when I try to do the fit. (There are a couple previous posts related to this one, but they haven't been much help.) import numpy as np import matplotlib.pyplot as plt from scipy.optimize import curve_fit def fitFunc(x_3d, a, b, c, d): return a + b*x_3d[0,:] + c*x_3d[1,:] + d*x_3d[0,:]*x_3d[1,:] x_3d = np.array([[1,2,3],[4,5,6]]) p0 = [5.11, 3.9, 5.3, 2]

What's the error of numpy.polyfit?

荒凉一梦 提交于 2019-11-30 10:53:35
I want to use numpy.polyfit for physical calculations, therefore I need the magnitude of the error. If you specify full=True in your call to polyfit , it will include extra information: >>> x = np.arange(100) >>> y = x**2 + 3*x + 5 + np.random.rand(100) >>> np.polyfit(x, y, 2) array([ 0.99995888, 3.00221219, 5.56776641]) >>> np.polyfit(x, y, 2, full=True) (array([ 0.99995888, 3.00221219, 5.56776641]), # coefficients array([ 7.19260721]), # residuals 3, # rank array([ 11.87708199, 3.5299267 , 0.52876389]), # singular values 2.2204460492503131e-14) # conditioning threshold The residual value

Correct fitting with scipy curve_fit including errors in x?

£可爱£侵袭症+ 提交于 2019-11-30 10:50:23
问题 I'm trying to fit a histogram with some data in it using scipy.optimize.curve_fit . If I want to add an error in y , I can simply do so by applying a weight to the fit. But how to apply the error in x (i. e. the error due to binning in case of histograms)? My question also applies to errors in x when making a linear regression with curve_fit or polyfit ; I know how to add errors in y , but not in x . Here an example (partly from the matplotlib documentation): import numpy as np import pylab

Fitting lognormal distribution using Scipy vs Matlab

烂漫一生 提交于 2019-11-30 10:20:52
I am trying to fit a lognormal distribution using Scipy. I've already done it using Matlab before but because of the need to extend the application beyond statistical analysis, I am in the process of trying to reproduce the fitted values in Scipy. Below is the Matlab code I used to fit my data: % Read input data (one value per line) x = []; fid = fopen(file_path, 'r'); % reading is default action for fopen disp('Reading network degree data...'); if fid == -1 disp('[ERROR] Unable to open data file.') else while ~feof(fid) [x] = [x fscanf(fid, '%f', [1])]; end c = fclose(fid); if c == 0 disp(