least-squares

How can I perform a least-squares fitting over multiple data sets fast?

末鹿安然 提交于 2019-12-03 02:51:57
问题 I am trying to make a gaussian fit over many data points. E.g. I have a 256 x 262144 array of data. Where the 256 points need to be fitted to a gaussian distribution, and I need 262144 of them. Sometimes the peak of the gaussian distribution is outside the data-range, so to get an accurate mean result curve-fitting is the best approach. Even if the peak is inside the range, curve-fitting gives a better sigma because other data is not in the range. I have this working for one data point, using

function for weighted least squares estimates

风流意气都作罢 提交于 2019-12-03 01:32:32
Does R have a function for weighted least squares? Specifically, I am looking for something that computes intercept and slope. Data sets 1 3 5 7 9 11 14 17 19 25 29 17 31 19 27 31 62 58 35 29 21 18 102153 104123 96564 125565 132255 115454 114555 132255 129564 126455 124578 The dependent variable is dataset 3 and dataset 1 and 2 are the independent variables. Yes, of course, there is a weights= option to lm() , the basic linear model fitting function. Quick example: R> df <- data.frame(x=1:10) R> lm(x ~ 1, data=df) ## i.e. the same as mean(df$x) Call: lm(formula = x ~ 1, data = df) Coefficients

trying to display original and fitted data (nls + dnorm) with ggplot2's geom_smooth()

僤鯓⒐⒋嵵緔 提交于 2019-12-02 18:29:19
I am exploring some data, so the first thing I wanted to do was try to fit a normal (Gaussian) distribution to it. This is my first time trying this in R, so I'm taking it one step at a time. First I pre-binned my data: myhist = data.frame(size = 10:27, counts = c(1L, 3L, 5L, 6L, 9L, 14L, 13L, 23L, 31L, 40L, 42L, 22L, 14L, 7L, 4L, 2L, 2L, 1L) ) qplot(x=size, y=counts, data=myhist) Since I want counts, I need to add a normalization factor (N) to scale up the density: fit = nls(counts ~ N * dnorm(size, m, s), data=myhist, start=c(m=20, s=5, N=sum(myhist$counts)) ) Then I create the fitted data

How can I perform a least-squares fitting over multiple data sets fast?

喜夏-厌秋 提交于 2019-12-02 16:25:55
I am trying to make a gaussian fit over many data points. E.g. I have a 256 x 262144 array of data. Where the 256 points need to be fitted to a gaussian distribution, and I need 262144 of them. Sometimes the peak of the gaussian distribution is outside the data-range, so to get an accurate mean result curve-fitting is the best approach. Even if the peak is inside the range, curve-fitting gives a better sigma because other data is not in the range. I have this working for one data point, using code from http://www.scipy.org/Cookbook/FittingData . I have tried to just repeat this algorithm, but

Finding the centre of multiple lines using least squares approach in Python

痴心易碎 提交于 2019-12-02 14:03:16
问题 I have a series of lines which roughly (but not exactly) intersect at some point. I need to find the point which minimises the distance between each line in the centre. I have been trying to follow this methodology: Nearest point to intersecting lines in 2D When I create my script in Python to perform this function I get the incorrect answer: Here is my code, I was wondering if anyone could suggest what I am doing wrong? Or an easier way of going about this. Each line is defined by two points

Constrained linear least-squares for xA=b in matlab

家住魔仙堡 提交于 2019-12-02 11:49:32
I want to solve xA=b with constraint 0<=x for x . I found functions like lsqnonneg and lsqlin which solves for Ax=b . However, couldn't find a good way to solve for xA=b . How can I solve xA=b with non-negative x constraint? Chris Taylor As David commented, it is straightforward to show that so you can use standard methods to solve the problem with A' and b' and then transpose the answer. 来源: https://stackoverflow.com/questions/26600699/constrained-linear-least-squares-for-xa-b-in-matlab

python scipy leastsq fit with complex numbers

假如想象 提交于 2019-12-02 07:51:05
I have a data set of complex numbers, and I'd like to be able to find parameters that best fit the data. Can you fit data in complex numbers using leastsq as implemented by scipy in python? For example, my code is something like this: import cmath from scipy.optimize import leastsq def residuals(p,y,x): L,Rs,R1,C=p denominator=1+(x**2)*(C**2)*(R1**2) sim=complex(Rs+R1/denominator,x*L-(R1**2)*x*C/denominator) return(y-sim) z=<read in data, store as complex number> x0=np.array[1, 2, 3, 4] res = leastsq(residuals,x0, args=(z,x)) However, residuals doesn't like working with my complex number, I

Finding the centre of multiple lines using least squares approach in Python

£可爱£侵袭症+ 提交于 2019-12-02 07:01:34
I have a series of lines which roughly (but not exactly) intersect at some point. I need to find the point which minimises the distance between each line in the centre. I have been trying to follow this methodology: Nearest point to intersecting lines in 2D When I create my script in Python to perform this function I get the incorrect answer: Here is my code, I was wondering if anyone could suggest what I am doing wrong? Or an easier way of going about this. Each line is defined by two points x1 and x2. def directionalv(x1,x2): point1=np.array(x1) #point1 and point2 define my line point2=np

How do I use the least squares approximation in MATLAB?

流过昼夜 提交于 2019-12-01 18:04:14
问题 For a homework assignment in linear algebra, I have solved the following equation using MATLAB's \ operator (which is the recommended way of doing it): A = [0.2 0.25; 0.4 0.5; 0.4 0.25]; y = [0.9 1.7 1.2]'; x = A \ y which produces the following answer: x = 1.7000 2.0800 For the next part of assignment, I'm supposed to solve the same equation using the least squares approximation (and then compare it against the prior value to see how accurate the approximation is). How can I find a way of

How do I use the least squares approximation in MATLAB?

夙愿已清 提交于 2019-12-01 18:01:58
For a homework assignment in linear algebra, I have solved the following equation using MATLAB's \ operator (which is the recommended way of doing it): A = [0.2 0.25; 0.4 0.5; 0.4 0.25]; y = [0.9 1.7 1.2]'; x = A \ y which produces the following answer: x = 1.7000 2.0800 For the next part of assignment, I'm supposed to solve the same equation using the least squares approximation (and then compare it against the prior value to see how accurate the approximation is). How can I find a way of doing that in MATLAB? Prior work: I have found the function lsqlin , which seems to be able to solve