covar.h
Go to the documentation of this file.
00001 namespace Eigen { 
00002 
00003 namespace internal {
00004 
00005 template <typename Scalar>
00006 void covar(
00007         Matrix< Scalar, Dynamic, Dynamic > &r,
00008         const VectorXi &ipvt,
00009         Scalar tol = sqrt(NumTraits<Scalar>::epsilon()) )
00010 {
00011     typedef DenseIndex Index;
00012 
00013     /* Local variables */
00014     Index i, j, k, l, ii, jj;
00015     bool sing;
00016     Scalar temp;
00017 
00018     /* Function Body */
00019     const Index n = r.cols();
00020     const Scalar tolr = tol * abs(r(0,0));
00021     Matrix< Scalar, Dynamic, 1 > wa(n);
00022     assert(ipvt.size()==n);
00023 
00024     /* form the inverse of r in the full upper triangle of r. */
00025     l = -1;
00026     for (k = 0; k < n; ++k)
00027         if (abs(r(k,k)) > tolr) {
00028             r(k,k) = 1. / r(k,k);
00029             for (j = 0; j <= k-1; ++j) {
00030                 temp = r(k,k) * r(j,k);
00031                 r(j,k) = 0.;
00032                 r.col(k).head(j+1) -= r.col(j).head(j+1) * temp;
00033             }
00034             l = k;
00035         }
00036 
00037     /* form the full upper triangle of the inverse of (r transpose)*r */
00038     /* in the full upper triangle of r. */
00039     for (k = 0; k <= l; ++k) {
00040         for (j = 0; j <= k-1; ++j)
00041             r.col(j).head(j+1) += r.col(k).head(j+1) * r(j,k);
00042         r.col(k).head(k+1) *= r(k,k);
00043     }
00044 
00045     /* form the full lower triangle of the covariance matrix */
00046     /* in the strict lower triangle of r and in wa. */
00047     for (j = 0; j < n; ++j) {
00048         jj = ipvt[j];
00049         sing = j > l;
00050         for (i = 0; i <= j; ++i) {
00051             if (sing)
00052                 r(i,j) = 0.;
00053             ii = ipvt[i];
00054             if (ii > jj)
00055                 r(ii,jj) = r(i,j);
00056             if (ii < jj)
00057                 r(jj,ii) = r(i,j);
00058         }
00059         wa[jj] = r(j,j);
00060     }
00061 
00062     /* symmetrize the covariance matrix in r. */
00063     r.topLeftCorner(n,n).template triangularView<StrictlyUpper>() = r.topLeftCorner(n,n).transpose();
00064     r.diagonal() = wa;
00065 }
00066 
00067 } // end namespace internal
00068 
00069 } // end namespace Eigen


win_eigen
Author(s): Daniel Stonier
autogenerated on Mon Oct 6 2014 12:24:21