quantlab.model.ensemble.member_correlation#

quantlab.model.ensemble.member_correlation(predictions)[source]#

Return the mean pairwise correlation of member predictions, overall and per bar.

On each bar only the symbols where every member is finite count. Over them the Pearson correlation of each pair of members is computed and the pairs are averaged; a pair is left out on a bar where one of its members is constant. A bar with fewer than two common symbols, or with no pair left, is NaN. The overall value is the mean of the per-bar values, ignoring NaN.

With k members of mean information coefficient IC and mean pairwise correlation rho, an equal-weight average has roughly IC * sqrt(k / (1 + (k - 1) * rho)): members that agree (rho near 1) add little, and uncorrelated members amplify whatever they share, noise included.

Parameters:
predictionssequence of array_like

One 2-D [T, S] panel per member, all of the same shape and aligned on the same bars and symbols.

Returns:
meanfloat

The mean over bars of the per-bar value; NaN with fewer than two members or no usable bar.

per_barnp.ndarray

The per-bar mean pairwise correlation, float64 of length T, within [-1, 1], NaN on a skipped bar.

Raises:
ValueError

If predictions is empty, a panel is not 2-D, or two panels differ in shape.

Examples

>>> import numpy as np
>>> a = np.array([[1.0, 2.0, 3.0, 4.0], [4.0, 3.0, 2.0, 1.0]])
>>> b = np.array([[1.0, 3.0, 2.0, 4.0], [1.0, 2.0, 3.0, 4.0]])
>>> mean, per_bar = member_correlation([a, b])
>>> per_bar
array([ 0.8, -1. ])
>>> round(mean, 6)
-0.1