LMcovar.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // This code initially comes from MINPACK whose original authors are:
5 // Copyright Jorge More - Argonne National Laboratory
6 // Copyright Burt Garbow - Argonne National Laboratory
7 // Copyright Ken Hillstrom - Argonne National Laboratory
8 //
9 // This Source Code Form is subject to the terms of the Minpack license
10 // (a BSD-like license) described in the campaigned CopyrightMINPACK.txt file.
11 
12 #ifndef EIGEN_LMCOVAR_H
13 #define EIGEN_LMCOVAR_H
14 
15 #include "./InternalHeaderCheck.h"
16 
17 namespace Eigen {
18 
19 namespace internal {
20 
21 template <typename Scalar>
22 void covar(
24  const VectorXi& ipvt,
25  Scalar tol = std::sqrt(NumTraits<Scalar>::epsilon()) )
26 {
27  using std::abs;
28  /* Local variables */
29  Index i, j, k, l, ii, jj;
30  bool sing;
31  Scalar temp;
32 
33  /* Function Body */
34  const Index n = r.cols();
35  const Scalar tolr = tol * abs(r(0,0));
37  eigen_assert(ipvt.size()==n);
38 
39  /* form the inverse of r in the full upper triangle of r. */
40  l = -1;
41  for (k = 0; k < n; ++k)
42  if (abs(r(k,k)) > tolr) {
43  r(k,k) = 1. / r(k,k);
44  for (j = 0; j <= k-1; ++j) {
45  temp = r(k,k) * r(j,k);
46  r(j,k) = 0.;
47  r.col(k).head(j+1) -= r.col(j).head(j+1) * temp;
48  }
49  l = k;
50  }
51 
52  /* form the full upper triangle of the inverse of (r transpose)*r */
53  /* in the full upper triangle of r. */
54  for (k = 0; k <= l; ++k) {
55  for (j = 0; j <= k-1; ++j)
56  r.col(j).head(j+1) += r.col(k).head(j+1) * r(j,k);
57  r.col(k).head(k+1) *= r(k,k);
58  }
59 
60  /* form the full lower triangle of the covariance matrix */
61  /* in the strict lower triangle of r and in wa. */
62  for (j = 0; j < n; ++j) {
63  jj = ipvt[j];
64  sing = j > l;
65  for (i = 0; i <= j; ++i) {
66  if (sing)
67  r(i,j) = 0.;
68  ii = ipvt[i];
69  if (ii > jj)
70  r(ii,jj) = r(i,j);
71  if (ii < jj)
72  r(jj,ii) = r(i,j);
73  }
74  wa[jj] = r(j,j);
75  }
76 
77  /* symmetrize the covariance matrix in r. */
78  r.topLeftCorner(n,n).template triangularView<StrictlyUpper>() = r.topLeftCorner(n,n).transpose();
79  r.diagonal() = wa;
80 }
81 
82 } // end namespace internal
83 
84 } // end namespace Eigen
85 
86 #endif // EIGEN_LMCOVAR_H
int n
int i
#define eigen_assert(x)
EIGEN_CONSTEXPR Index size() const EIGEN_NOEXCEPT
EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
void covar(Matrix< Scalar, Dynamic, Dynamic > &r, const VectorXi &ipvt, Scalar tol=std::sqrt(NumTraits< Scalar >::epsilon()))
Definition: LMcovar.h:22
: TensorContractionSycl.h, provides various tensor contraction kernel for SYCL backend
Eigen::AutoDiffScalar< EIGEN_EXPR_BINARYOP_SCALAR_RETURN_TYPE(Eigen::internal::remove_all_t< DerType >, typename Eigen::internal::traits< Eigen::internal::remove_all_t< DerType >>::Scalar, product) > sqrt(const Eigen::AutoDiffScalar< DerType > &x)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_abs_op< typename Derived::Scalar >, const Derived > abs(const Eigen::ArrayBase< Derived > &x)
adouble abs(const adouble &x)
Definition: AdolcForward:74
std::ptrdiff_t j