Click or drag to resize
sqx

SQXCovarianceMatrix Method

Procedure CovarianceMatrix [nvarchar](max) @Query, [bit] @Population, [bit] @SnapShot, [Matrix] @CoVarianceMatrix OUTPUT

Namespace:  sqx
Assembly:  SQX (in SQX.dll) Version: 1.0.2.6 (1.0.2.6)
Syntax
C#
public static int CovarianceMatrix(
	SqlChars Query,
	SqlBoolean Population,
	SqlBoolean SnapShot,
	out Matrix CovarianceMatrix
)

Parameters

Query
Type: System.Data.SqlTypesSqlChars
[nvarchar](max)
Population
Type: System.Data.SqlTypesSqlBoolean
[bit]
SnapShot
Type: System.Data.SqlTypesSqlBoolean
[bit] 0 Read Commited | 1 SnapShot
CovarianceMatrix
Type: sqxMatrix
[Matrix] Output

Return Value

Type: Int32
[int] 0 success | -1 failure
Remarks
High performance Covariance Matrix procedure.
/// It can compute Covariance Matrix up to 91 Columns.

NOTE: Query must return a dataset with only the matrix columns with numeric data type.
NOTE: CTE not available in @Query parameter.
Examples
SQL
declare @Query nvarchar(max) = N'
select a.Value [1],b.Value [2],c.Value [3]
from sqx.VectorTable(sqx.RandomVector(10,1)) a
inner join sqx.VectorTable(sqx.RandomVector(10,2)) b ON a.ID = b.ID
inner join sqx.VectorTable(sqx.RandomVector(10,3)) c ON a.ID = c.ID
'
declare @C sqx.Matrix
exec sqx.CovarianceMatrix @Query = @Query
    , @Population = 1, @SnapShot = 0, @CovarianceMatrix = @C OUTPUT
exec sqx.MatrixToTable @C
/*
ID          1                      2                      3
----------- ---------------------- ---------------------- ----------------------
1           0.0709172334310987     0.00142036467919198    0.0182726203916543
2           0.00142036467919198    0.0968632683853888     -0.0326049475878277
3           0.0182726203916543     -0.0326049475878277    0.0703461206094948*/
See Also