least-squares

Python: two-curve gaussian fitting with non-linear least-squares

↘锁芯ラ 提交于 2019-11-28 17:18:27
My knowledge of maths is limited which is why I am probably stuck. I have a spectra to which I am trying to fit two Gaussian peaks. I can fit to the largest peak, but I cannot fit to the smallest peak. I understand that I need to sum the Gaussian function for the two peaks but I do not know where I have gone wrong. An image of my current output is shown: The blue line is my data and the green line is my current fit. There is a shoulder to the left of the main peak in my data which I am currently trying to fit, using the following code: import matplotlib.pyplot as pt import numpy as np from

Use of curve_fit to fit data

自古美人都是妖i 提交于 2019-11-28 11:10:54
I'm new to scipy and matplotlib, and I've been trying to fit functions to data. The first example in the Scipy Cookbook works fantastically, but when I am trying it with points read from a file, the initial coefficients I give (p0 below) never seem to actually change, and the covariance matrix is always INF. I've tried to fit even data following a line, to no avail. Is it a problem with the way I am importing the data? If so, is there a better way to do it? import matplotlib.pyplot as plt from scipy.optimize import curve_fit import scipy as sy with open('data.dat') as f: noms = f.readline()

How to use least squares method in Matlab?

大兔子大兔子 提交于 2019-11-28 09:10:11
问题 I have 37 linear equations and 36 variables in the form of a matrix equation; A*X=B . The equations don't have an exact answer. I want to use Matlab least square method to find the answers with the least error. I am new to Matlab so any comments will help. Thank you 回答1: If A is of full rank, i.e. the columns of A are linearly independent, the least-squares solution of an overdetermined system of linear equations A * x = b can be found by inverting the normal equations (see Linear Least

Weighted trendline

别来无恙 提交于 2019-11-27 16:24:21
问题 Excel produces scatter diagrams for sets of pair values. It also gives the option of producing a best fit trendline and formula for the trendline. It also produces bubble diagrams which take into consideration a weight provided with each value. However, the weight has no influence on the trendline or formula. Here is an example set of values, with their mappings and weights. Value Map Weight 0 1 10 1 2 10 2 5 10 3 5 20 4 6 20 5 1 1 With Excel's trendline, the mapping for value 5 has too much

How to calculate variance of least squares estimator using QR decomposition in R?

坚强是说给别人听的谎言 提交于 2019-11-27 15:20:28
问题 I'm trying to learn QR decomposition, but can't figure out how to get the variance of beta_hat without resorting to traditional matrix calculations. I'm practising with the iris data set, and here's what I have so far: y<-(iris$Sepal.Length) x<-(iris$Sepal.Width) X<-cbind(1,x) n<-nrow(X) p<-ncol(X) qr.X<-qr(X) b<-(t(qr.Q(qr.X)) %*% y)[1:p] R<-qr.R(qr.X) beta<-as.vector(backsolve(R,b)) res<-as.vector(y-X %*% beta) Thanks for your help! 回答1: setup (copying in your code) y <- iris$Sepal.Length x

confidence interval with leastsq fit in scipy python

。_饼干妹妹 提交于 2019-11-27 14:14:03
问题 How to calculate confidence interval for the least square fit (scipy.optimize.leastsq) in python? 回答1: I would use bootstrapping method. See here: http://phe.rockefeller.edu/LogletLab/whitepaper/node17.html Simple example for noisy gaussian: x = arange(-10, 10, 0.01) # model function def f(p): mu, s = p return exp(-(x-mu)**2/(2*s**2)) # create error function for dataset def fff(d): def ff(p): return d-f(p) return ff # create noisy dataset from model def noisy_data(p): return f(p)+normal(0,0.1

Finding translation and scale on two sets of points to get least square error in their distance?

ぐ巨炮叔叔 提交于 2019-11-27 10:11:06
问题 I have two sets of 3D points (original and reconstructed) and correspondence information about pairs - which point from one set represents the second one. I need to find 3D translation and scaling factor which transforms reconstruct set so the sum of square distances would be least (rotation would be nice too, but points are rotated similarly, so this is not main priority and might be omitted in sake of simplicity and speed). And so my question is - is this solved and available somewhere on

Use of curve_fit to fit data

筅森魡賤 提交于 2019-11-27 05:59:01
问题 I'm new to scipy and matplotlib, and I've been trying to fit functions to data. The first example in the Scipy Cookbook works fantastically, but when I am trying it with points read from a file, the initial coefficients I give (p0 below) never seem to actually change, and the covariance matrix is always INF. I've tried to fit even data following a line, to no avail. Is it a problem with the way I am importing the data? If so, is there a better way to do it? import matplotlib.pyplot as plt