public LinearRegression(Matrix a,Matrix y,double[] w,double ridge){
  if (w.length != a.getRowDimension())   throw new IllegalArgumentException("Incorrect number of weights provided");
  Matrix weightedThis=new Matrix(a.getRowDimension(),a.getColumnDimension());
  Matrix weightedDep=new Matrix(a.getRowDimension(),1);
  for (int i=0; i < w.length; i++) {
    double sqrt_weight=Math.sqrt(w[i]);
    for (int j=0; j < a.getColumnDimension(); j++)     weightedThis.set(i,j,a.get(i,j) * sqrt_weight);
    weightedDep.set(i,0,y.get(i,0) * sqrt_weight);
  }
  calculate(weightedThis,weightedDep,ridge);
}

public LinearRegression ( Matrix a , Matrix y , double [ ] w , double ridge ) { if ( w . length != a . getRowDimension ( ) ) throw new IllegalArgumentException ( "Incorrect number of weights provided" ) ; Matrix weightedThis = new Matrix ( a . getRowDimension ( ) , a . getColumnDimension ( ) ) ; Matrix weightedDep = new Matrix ( a . getRowDimension ( ) , 1 ) ; for ( int i = 0 ; i < w . length ; i ++ ) { double sqrt_weight = Math . sqrt ( w [ i ] ) ; for ( int j = 0 ; j < a . getColumnDimension ( ) ; j ++ ) weightedThis . set ( i , j , a . get ( i , j ) * sqrt_weight ) ; weightedDep . set ( i , 0 , y . get ( i , 0 ) * sqrt_weight ) ; } calculate ( weightedThis , weightedDep , ridge ) ; }
performs a weighted ( ridged ) linear regression .
