weighted least squares error

35 views
Skip to first unread message

Walter Whitlock

unread,
Nov 19, 2016, 7:32:18 PM11/19/16
to efficient-java-matrix-library-discuss
I am able to use the LinearSolverFactory.leastSquares() solver to solve my problem.  So far so good. 

But my data vary over several orders of magnitude so I want to weight the fit error by 1/(error in data). 
Is there an easy way to incorporate using error weight terms into the Linear Solvers? 

Walt

Walter Whitlock

unread,
Nov 25, 2016, 9:20:14 AM11/25/16
to efficient-java-matrix-library-discuss
I think I've answered my own question. I found a reference for turning a weighted least squares problem into an ordinary least squares problem. See section 1.2.4 WLS as OLS
in "Least Squares Adjustment: Linear and Nonlinear Weighted Regression Analysis" by Allan Aasbjerg Nielsen available at www2.imm.dtu.dk/pubdb/views/edoc_download.php/2804/pdf/imm2804.pdf. The notation is slightly different, but in ejml terms, to solve a WLS problem, create an mxm diagonal matrix P where the diagonal contains sqrt(weight) and then pre-multiply both the A and y terms by P and then solve the new problem as an OLS. 

P = CommonOps.diag(double ... weight[]), I use weight[i] = sqrt(1/(error in y[i]))
C = CommonOps.mult(P, A, C)
z = CommonOps.mult(P, y, z)
and then use a linear solver to solve C * x = z for x. 

Walt


On Saturday, November 19, 2016 at 7:32:18 PM UTC-5, Walter Whitlock wrote:
I am able to use the LinearSolverFactory.leastSquares() solver to solve my problem. So far so good.

But my data vary over several orders of magnitude so I wantto weight the fit error by 1/(error in data). 

Peter A

unread,
Dec 4, 2016, 2:24:41 PM12/4/16
to efficient-java-mat...@googlegroups.com
That looks correct.  Thanks for sharing!  This would probably make for a good example.  I'll add it to the TODO list.

- Peter

--
You received this message because you are subscribed to the Google Groups "efficient-java-matrix-library-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to efficient-java-matrix-library-discuss+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
"Now, now my good man, this is no time for making enemies."    — Voltaire (1694-1778), on his deathbed in response to a priest asking that he renounce Satan.
Reply all
Reply to author
Forward
0 new messages