Overload List
| # | Signature | Description |
|---|---|---|
| 1 | procedure Covariance(const X: TDenseMtxVec; const Y: TDenseMtxVec; const aResult: TMtx; NormN: Boolean); | Calculate the variance-covariance matrix (Result), assuming vectors X and Y are two variable and their elements are the observations. |
| 2 | procedure Covariance(const X: TMtx; const aResult: TMtx; NormN: Boolean); | Calculate the covariance matrix (Result), assuming matrix X columns are variables and its rows are observations. |
| 3 | procedure Covariance(const X: TVec; out aResult: Double; NormN: Boolean); | Covariance/variance. |
Overload 1: procedure Covariance(const X: TDenseMtxVec; const Y: TDenseMtxVec; const aResult: TMtx; NormN: Boolean);
Calculate the variance-covariance matrix (Result), assuming vectors X and Y are two variable and their elements are the observations.
| # | Name | Type | Description |
|---|---|---|---|
| 1 | X | TDenseMtxVec | |
| 2 | Y | TDenseMtxVec | |
| 3 | aResult | TMtx | |
| 4 | NormN | Boolean |
Result: stored in self (calling object)
For column-vector valued random variables X and Y with respective expected values mu and nu, and respective scalar components m and n, the covariance is defined to be the m-by-n matrix called the covariance matrix:
Overload 2: procedure Covariance(const X: TMtx; const aResult: TMtx; NormN: Boolean);
Calculate the covariance matrix (Result), assuming matrix X columns are variables and its rows are observations.
| # | Name | Type | Description |
|---|---|---|---|
| 1 | X | TMtx | |
| 2 | aResult | TMtx | |
| 3 | NormN | Boolean |
Result: stored in self (calling object)
By definition the covariance matrix is a matrix of covariances between elements of a vector. It is the natural generalization to higher dimensions of the concept of the variance of a scalar-valued random variable.
If X columns represent observation samples (variables), it's rows sample(s) values (observables), muj Xj j-th column average value, then the covariance matrix is defined as:
or in matrix form:
where E is the expected value. The inverse of this matrix, is called the inverse covariance matrix or the precision matrix.
Note
This version does all necessary calculations to calculate covariance matrix.
Overload 3: procedure Covariance(const X: TVec; out aResult: Double; NormN: Boolean);
Covariance/variance.
| # | Name | Description |
|---|---|---|
| 1 | X | Defines sample (variable) values (observables). In this case X is treated as row and not (as normally) column vector. |
| 2 | aResult | Returns the covariance (in this case equal to variance) for X vector elements. Because in this case X is represented as row vectro, the the result is simply scalar value E(X(T)*X)-E(X(T))E(X) = Var(X). |
| 3 | NormN | If true (default value), the result will be normalized with number of observations (N), otherwise it will be normalized with N-1. |
Result: stored in self (calling object)
The covariance between two real-valued random variables x and y,with expected values E(x)=mu and E(y)=nu is defined as:
where E(x), E(y) are x and y expected values.
For more info about covariance definition and properties check thd following links:
var Data1, Data2: Vector;
CovMtx : Matrix;
begin
Data1.SetIt(false,[1.2,3]);
Data2.SetIt(false,[5,5.5]);
Covariance(Data1,Data2,CovMtx,False);
// cov = [1.62, 0.45,
// 0.45, 0.125]
end;