STK++ 0.9.13
tutoStatCovariance.cpp
Go to the documentation of this file.
1#include "STKpp.h"
2using namespace STK;
4int main(int argc, char** argv)
5{
6 // create coovariance matrix and its Cholesky decomposition
7 CArraySquare<Real, 3> s; s << 2.0, 0.8, 0.36,
8 0.8, 2.0, 0.8,
9 0.36,0.8, 1.0;
11 cholesky(s, D, L);
12 // create correlated data set
14 a = a.randGauss() * D.sqrt() * L.transpose() + 1;
15 stk_cout << "True sigma=\n" << s;
16 stk_cout << "Estimated sigma=\n" << Stat::covariance(a);
17 return 0;
18}
#define stk_cout
Standard stk output stream.
This file include all the header files of the STK++ project.
Derivation of the Array2DDiagonal class for square arrays of Real.
Declaration of the lower triangular matrix class.
TransposeOperator< Derived > const transpose() const
Derived & randGauss()
set random values to this using a standard gaussian law.
specialization for the square case.
A CArray is a two dimensional array with a continuous storage like a C-array.
Definition STK_CArray.h:130
UnaryOperator< SqrtOp< Type >, Derived > sqrt() const
bool cholesky(ExprBase< Lhs > const &A, Array2DDiagonal< typename Lhs::Type > &D, Array2DLowerTriangular< typename Lhs::Type > &L)
Compute the Cholesky decomposition of a symmetric matrix.
Real covariance(ExprBase< XArray > const &X, ExprBase< YArray > const &Y, bool unbiased=false)
Compute the covariance of the variables X and Y.
The namespace STK is the main domain space of the Statistical ToolKit project.
int main(int argc, char **argv)