2.4.5.1. Special case of vector
As for all methods above, this one has been modified so that it can handle constant-size vectors (at least given the pre-selection of event from the combination of the overall selection and the one provided in the method, as a second argument). As usual, the idea is to consider all elements of a vector independent from the other. If one considers the correlation matrix computed between two attributes, one being a scalar while the other one is a constant-sized vector with 10 elements, the resulting correlation matrix will be a 11 by 11 matrix.
Here are two examples of computeCorrelationMatrix calls, both using the tdstest.dat file already
shown in Adding attributes to a TDataServer, which contains four attributes, three of which can
be used here (\(y\) being a non constant-size vector, using it in this method will bring an exception
error). In the following example, two correlation matrices are computed: the first one providing the
correlation of both \(a\) and \(x\) attributes while the second focus on the former and only the second
element of the latter.
"""
Example of correlation matrix computation for vector
"""
from URANIE import DataServer
tdsop = DataServer.TDataServer("foo", "poet")
tdsop.fileDataRead("tdstest.dat")
# Consider a and x attributes (every element of the vector)
globalOne = tdsop.computeCorrelationMatrix("x:a")
globalOne.Print()
# Consider a and x attributes (cherry-picking a single element of the vector)
focusedOne = tdsop.computeCorrelationMatrix("x[1]:a")
focusedOne.Print()
This should lead to the following console return, where the first correlation matrix contains all pearson correlation coefficient (considering \(x\) as a constant-size vector whose element are independent one to another) while the second on focus only on the second element of this vector (a vector’s number start at 0). The following macro is shown in Macro “dataserverComputeCorrelationMatrixVector.py”.
4x4 matrix is as follows
| 0 | 1 | 2 | 3 |
---------------------------------------------------------
0 | 1 0.9449 0.6286 0.189
1 | 0.9449 1 0.8486 0.5
2 | 0.6286 0.8486 1 0.8825
3 | 0.189 0.5 0.8825 1
2x2 matrix is as follows
| 0 | 1 |
-------------------------------
0 | 1 0.5
1 | 0.5 1
Warning
When considering correlation matrix, the vectors are handled ONLY FOR PEARSON ESTIMATION. No adaptation has been made for rank ones.