Exemplo n.º 1
0
  void QrRegSuf::refresh_qr(const std::vector<Ptr<RegressionData> > &raw_data) const {
    if(current) return;
    int n = raw_data.size();  // number of observations
    if(n==0){
      current=false;
      return;}

    Ptr<RegressionData> rdp = DAT(raw_data[0]);
    uint dim_beta = rdp->xdim();
    Matrix X(n, dim_beta);
    Vector y(n);
    sumsqy=0.0;
    for(int i = 0; i<n; ++i){
      rdp = DAT(raw_data[i]);
      y[i] = rdp->y();
      const Vector & x(rdp->x());
      X.set_row(i,x);
//       X(i,0)=1.0;    // this stuff is no longer needed b/c the intercept is explicit
//       int k=0;
//       for(int j=x.lo(); j<=x.hi(); ++j) X(i,++k) = x[j];
      sumsqy += y[i]*y[i];
    }
    qr.decompose(X);
    X = qr.getQ();
    Qty = y*X;
    current=true;
    x_column_sums_ = ColSums(X);
  }
Exemplo n.º 2
0
 //======================================================================
 QrRegSuf::QrRegSuf(const Mat&X, const Vector &y):
   qr(X),
   Qty(),
   sumsqy(0.0),
   current(true)
 {
   Matrix Q(qr.getQ());
   Qty = y*Q;
   sumsqy = y.dot(y);
   x_column_sums_ = ColSums(X);
 }
Exemplo n.º 3
0
 NeRegSuf::NeRegSuf(const Matrix &X, const Vector &y)
     : needs_to_reflect_(false),
       xtx_is_fixed_(false),
       sumsqy(y.normsq()),
       n_(nrow(X)),
       sumy_(y.sum()),
       x_column_sums_(ColSums(X))
 {
   xty_ =y*X;
   xtx_ = X.inner();
   sumsqy = y.dot(y);
 }
Exemplo n.º 4
0
	bool VerifyRotationMatrix(const vnl_double_3x3 &M)
	{
		//check row sums
		std::vector<double> RowSums(3);
		for(unsigned int i = 0; i < 3; i++)
		{
			vnl_double_3 r = M.get_row(i);
			double sum = 0;
			for(unsigned int j = 0; j < 3; j++)
				sum += pow(r[j], 2);
			
			RowSums[i] = sum;
			//cout << "Sum of row " << i << " = " << sum << endl;
		}
	
		//check col sums
		std::vector<double> ColSums(3);
		for(unsigned int i = 0; i < 3; i++)
		{
			vnl_double_3 c = M.get_column(i);
			double sum = 0;
			for(unsigned int j = 0; j < 3; j++)
				sum += pow(c[j], 2);
	
			ColSums[i] = sum;
			//cout << "Sum of col " << i << " = " << sum << endl;
		}
	
		double eps = 1e-4;
		for(unsigned int i = 0; i < 3; i++)
		{
			if( fabs(RowSums[i] - 1.0) > eps )
				return false;
			if( fabs(ColSums[i] - 1.0) > eps )
				return false;
		}
			
		return true;
	}