least-squares

MATLAB curve fitting - least squares method - wrong “fit” using high degrees

喜你入骨 提交于 2019-12-01 10:27:38
Anyone here that could help me with the following problem? The following code calculates the best polynomial fit to a given data-set, that is; a polynomial of a specified degree. Unfortunately, whatever the data-set may be, usually at degree 6 or higher, MATLAB gets a totally wrong fit. Usually the fit curves totally away from the data in a sort of exponantial-looking-manner downwards. (see the example: degree = 8). x=[1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5] % experimental x-values y=[4.3 6.2 10.1 13.5 19.8 22.6 24.7 29.2] % experimental y-values degree=8; % specify the degree A = zeros(length(x)

fitting a linear surface with numpy least squares

余生长醉 提交于 2019-12-01 09:27:44
So I want to solve the equation z= a + b*y +c*x ,. getting a,b,c . ie: making a (plane) surface fit to a load of scatter points in 3D space. But I can't seem to find anything! I thought there would be a simple module for such a simple problem. I have tried, where x,y,z are arrays; ys=zip(x,y) (coeffs, residuals, rank, sing_vals) = np.linalg.lstsq(ys,z) am I right in thinking coeffs = b,c? Or am I going completely in the wrong direction. I just can't seem to find anything else that will work in 3d... I think you're on the right track. You could still try following the example of the scipy

fitting a linear surface with numpy least squares

拟墨画扇 提交于 2019-12-01 07:15:27
问题 So I want to solve the equation z= a + b*y +c*x ,. getting a,b,c . ie: making a (plane) surface fit to a load of scatter points in 3D space. But I can't seem to find anything! I thought there would be a simple module for such a simple problem. I have tried, where x,y,z are arrays; ys=zip(x,y) (coeffs, residuals, rank, sing_vals) = np.linalg.lstsq(ys,z) am I right in thinking coeffs = b,c? Or am I going completely in the wrong direction. I just can't seem to find anything else that will work

How to find the best straight line separating two regions having points with 2 different properties

久未见 提交于 2019-12-01 06:51:49
问题 I have a bunch of points in a 2D plot. The red points indicate when my experiment is stable, the black when it is unstable. The two region are clearly separated by a line in this log-log plot, and I would like to find the best "separating line", i.e. the line that gives the criterion to separate the 2 regions and has the minimum error on this criterion. I did a search on various books and online but I could not find any approach to solve this problem. Are you aware of any tool? First of all

linear regression using lm() - surprised by the result

半城伤御伤魂 提交于 2019-12-01 03:47:16
I used a linear regression on data I have, using the lm function. Everything works (no error message), but I'm somehow surprised by the result: I am under the impression R "misses" a group of points, i.e. the intercept and slope are not the best fit. For instance, I am referring to the group of points at coordinates x=15-25,y=0-20. My questions: is there a function to compare fit with "expected" coefficients and "lm-calculated" coefficients? have I made a silly mistake when coding, leading the lm to do that? Following some answers: additionnal information on x and y x and y are both visual

Constrained least-squares estimation in Python

浪尽此生 提交于 2019-12-01 03:32:57
I'm trying to perform a constrained least-squares estimation using Scipy such that all of the coefficients are in the range (0,1) and sum to 1 (this functionality is implemented in Matlab's LSQLIN function). Does anybody have tips for setting up this calculation using Python/Scipy. I believe I should be using scipy.optimize.fmin_slsqp() , but am not entirely sure what parameters I should be passing to it.[1] Many thanks for the help, Nick [1] The one example in the documentation for fmin_slsqp is a bit difficult for me to parse without the referenced text -- and I'm new to using Scipy. denis

how to solve many overdetermined systems of linear equations using vectorized codes?

丶灬走出姿态 提交于 2019-11-30 23:23:37
I need to solve a system of linear equations Lx=b, where x is always a vector (3x1 array), L is an Nx3 array, and b is an Nx1 vector. N usually ranges from 4 to something like 10. I have no problems solving this using scipy.linalg.lstsq(L,b) However, I need to do this many times (something like 200x200=40000 times) as x is actually something associated with each pixel in an image. So x is actually stored in an PxQx3 array where P and Q is something like 200-300, and the last number '3' refers to the vector x. Right now I just loop through each column and row and solve the equation one-by-one

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

Linear Least Squares Fit of Sphere to Points

痞子三分冷 提交于 2019-11-30 13:51:55
I'm looking for an algorithm to find the best fit between a cloud of points and a sphere. That is, I want to minimise where C is the centre of the sphere, r its radius, and each P a point in my set of n points. The variables are obviously Cx , Cy , Cz , and r . In my case, I can obtain a known r beforehand, leaving only the components of C as variables. I really don't want to have to use any kind of iterative minimisation (e.g. Newton's method, Levenberg-Marquardt, etc) - I'd prefer a set of linear equations or a solution explicitly using SVD. There are no matrix equations forthcoming. Your

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