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 withnearest().Parameters
bThe block correlations, one row and one column per block, in the order
labelsfirst names the blocks. It must be symmetric, to within 1e-12, the rounding of two block means summed in different orders;nanentries match each other.labelsOne block label per column of the result.
Returns
A
k x kfloat array, withkthe number of labels. Entry(i, j)isB[block(i), block(j)]off the diagonal, and 1 on it, withBthe tableb.Raises
ValueErrorbnot 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
block_means(), its inverse up to the averaging within blocks.