All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Protected Attributes | List of all members
ana::IncrementalCholeskyDecomp Class Reference

#include <IncrementalCholeskyDecomp.h>

Public Member Functions

 IncrementalCholeskyDecomp ()
 Initialize for a 0x0 matrix. More...
 
void Extend ()
 Add one row and column of zeros. More...
 
void SetLastRow (const std::vector< double > &row)
 This is of course also the right-most column... More...
 
void SetLastRow (const std::vector< double > &bigrow, const std::vector< int > &idxs)
 
void AddRow (const std::vector< double > &row)
 
void AddRow (const std::vector< double > &row, const std::vector< int > &idxs)
 
std::vector< double > Solve (const std::vector< double > &b) const
 
void Print () const
 

Protected Attributes

std::vector< std::vector
< double > > 
fUpper
 

Detailed Description

Definition at line 8 of file IncrementalCholeskyDecomp.h.

Constructor & Destructor Documentation

ana::IncrementalCholeskyDecomp::IncrementalCholeskyDecomp ( )
inline

Initialize for a 0x0 matrix.

Definition at line 12 of file IncrementalCholeskyDecomp.h.

12 {}

Member Function Documentation

void ana::IncrementalCholeskyDecomp::AddRow ( const std::vector< double > &  row)
inline

Definition at line 23 of file IncrementalCholeskyDecomp.h.

24  {
25  Extend();
26  SetLastRow(row);
27  }
void Extend()
Add one row and column of zeros.
void SetLastRow(const std::vector< double > &row)
This is of course also the right-most column...
void ana::IncrementalCholeskyDecomp::AddRow ( const std::vector< double > &  row,
const std::vector< int > &  idxs 
)
inline

Definition at line 29 of file IncrementalCholeskyDecomp.h.

31  {
32  Extend();
33  SetLastRow(row, idxs);
34  }
void Extend()
Add one row and column of zeros.
void SetLastRow(const std::vector< double > &row)
This is of course also the right-most column...
void ana::IncrementalCholeskyDecomp::Extend ( )

Add one row and column of zeros.

Definition at line 11 of file IncrementalCholeskyDecomp.cxx.

12  {
13  // First up, expand the decomp matrix
14  for(std::vector<double>& row: fUpper) row.push_back(0); // extend each row
15  fUpper.emplace_back(fUpper.size()+1, 0); // and add one more
16  }
std::vector< std::vector< double > > fUpper
void ana::IncrementalCholeskyDecomp::Print ( ) const

Definition at line 77 of file IncrementalCholeskyDecomp.cxx.

78  {
79  for(const std::vector<double>& row: fUpper){
80  for(double v: row) std::cout << v << "\t";
81  std::cout << std::endl;
82  }
83  }
std::vector< std::vector< double > > fUpper
BEGIN_PROLOG could also be cout
void ana::IncrementalCholeskyDecomp::SetLastRow ( const std::vector< double > &  row)

This is of course also the right-most column...

Definition at line 19 of file IncrementalCholeskyDecomp.cxx.

20  {
21  // Implementation based on https://en.wikipedia.org/wiki/Cholesky_decomposition#Adding_and_removing_rows_and_columns
22 
23  const unsigned int N = fUpper.size();
24 
25  // S11 = L11 -- true automatically
26 
27  // S12 = L11^T \ A12
28  for(unsigned int i = 0; i+1 < N; ++i){ // which row we're solving
29  double res = row[i];
30  for(unsigned int j = 0; j < i; ++j) res -= fUpper[j][i] * fUpper[j][N-1];
31  if(res != 0) fUpper[i][N-1] = res/fUpper[i][i];
32  }
33 
34  // S22 = chol(A22 - S12T S12)
35  double dot = 0;
36  for(unsigned int i = 0; i+1 < N; ++i) dot += util::sqr(fUpper[i][N-1]);
37  fUpper[N-1][N-1] = sqrt(row[N-1] - dot);
38  }
constexpr auto dot(Vector const &a, Vector const &b)
Return cross product of two vectors.
std::vector< std::vector< double > > fUpper
T sqr(T x)
More efficient square function than pow(x,2)
Definition: MathUtil.h:23
process_name largeant stream1 can override from command line with o or output physics producers generator N
void ana::IncrementalCholeskyDecomp::SetLastRow ( const std::vector< double > &  bigrow,
const std::vector< int > &  idxs 
)

Definition at line 41 of file IncrementalCholeskyDecomp.cxx.

43  {
44  std::vector<double> row;
45  row.reserve(idxs.size());
46  for(int i: idxs) row.push_back(bigrow[i]);
47  SetLastRow(row);
48  }
void SetLastRow(const std::vector< double > &row)
This is of course also the right-most column...
std::vector< double > ana::IncrementalCholeskyDecomp::Solve ( const std::vector< double > &  b) const

Definition at line 51 of file IncrementalCholeskyDecomp.cxx.

52  {
53  const unsigned int N = fUpper.size();
54 
55  // Solve Ly = b
56  std::vector<double> y(N);
57 
58  for(unsigned int i = 0; i < N; ++i){ // which row we're solving
59  double res = b[i];
60  for(unsigned int j = 0; j < i; ++j) res -= fUpper[j][i] * y[j];
61  if(res != 0) y[i] = res/fUpper[i][i];
62  }
63 
64  // And now LTx = y
65  std::vector<double> x(N);
66 
67  for(int i = N-1; i >= 0; --i){
68  double res = y[i];
69  for(unsigned int j = i+1; j < N; ++j) res -= fUpper[i][j] * x[j];
70  if(res != 0) x[i] = res/fUpper[i][i];
71  }
72 
73  return x;
74  }
process_name opflash particleana ie x
std::vector< std::vector< double > > fUpper
process_name opflash particleana ie ie y
process_name largeant stream1 can override from command line with o or output physics producers generator N

Member Data Documentation

std::vector<std::vector<double> > ana::IncrementalCholeskyDecomp::fUpper
protected

Definition at line 41 of file IncrementalCholeskyDecomp.h.


The documentation for this class was generated from the following files: