polars_online.corr.from_blocks

polars_online.corr.from_blocks(b: Any, labels: Sequence[Any]) → Any[source]

Build the block-equicorrelation matrix that a table of block correlations describes.

Use it to turn the block means block_means() returns, or a table of your own, back into a full matrix: a structured target or a forecast. It has a unit diagonal, but only some tables give a positive semidefinite one. Repair one that is not with nearest().

Parameters

b

The block correlations, one row and one column per block, in the order labels first names the blocks. It must be symmetric, to within 1e-12, the rounding of two block means summed in different orders; nan entries match each other.

labels

One block label per column of the result.

Returns

A k x k float array, with k the number of labels. Entry (i, j) is B[block(i), block(j)] off the diagonal, and 1 on it, with B the table b.

Raises

ValueError

b not square in the number of blocks the labels name, or not symmetric.

Examples

b = np.array([[0.6, 0.1], [0.1, 0.5]])
print(po.corr.from_blocks(b, ["a", "a", "b", "b"]))
[[1.  0.6 0.1 0.1]
 [0.6 1.  0.1 0.1]
 [0.1 0.1 1.  0.5]
 [0.1 0.1 0.5 1. ]]

See also