(x, y)
return cov
Compute covariance between two 2D tensors.

    Parameters
    ----------
    x : torch.tensor
        Torch tensor of shape `(n_samples, horizon)`

    y : torch.tensor
        Tensor of shape `(n_samples, horizon)`

    Returns
    -------
    cov : torch.tensor
        Torch tensor of shape `(n_samples,)`.
Compute covariance between two 2D tensors.
Compute covariance between two 2D tensors .
def covariance(x, y):
    """Compute covariance between two 2D tensors.

    Parameters
    ----------
    x : torch.tensor
        Torch tensor of shape `(n_samples, horizon)`

    y : torch.tensor
        Tensor of shape `(n_samples, horizon)`

    Returns
    -------
    cov : torch.tensor
        Torch tensor of shape `(n_samples,)`.
    """
    n_samples, horizon = x.shape
    mean_x = x.mean(dim=1, keepdim=True)
    mean_y = y.mean(dim=1, keepdim=True)
    xm = x - mean_x  # (n_samples, horizon)
    ym = y - mean_y  # (n_samples, horizon)

    cov = (xm * ym).sum(dim=1) / horizon

    return cov
def covariance ( x , y ) : n_samples , horizon = x . shape mean_x = x . mean ( dim = 1 , keepdim = True ) mean_y = y . mean ( dim = 1 , keepdim = True ) xm = x - mean_x # (n_samples, horizon) ym = y - mean_y # (n_samples, horizon) cov = ( xm * ym ) . sum ( dim = 1 ) / horizon return cov