qfeval_functions.functions.correl
- correl(x, y, dim=(), keepdim=False)[source]
Compute Pearson correlation coefficient between two tensors.
This function calculates the Pearson correlation coefficient between tensors
xandyalong the specified dimension(s). The correlation coefficient measures the linear relationship between two variables and ranges from -1 (perfect negative correlation) to 1 (perfect positive correlation), with 0 indicating no linear correlation.- Parameters:
x (
Tensor) – The first input tensor.y (
Tensor) – The second input tensor. Must be the same shape asx.dim (
Union[int,Tuple[int,...]]) – The dimension(s) along which to compute the correlation. If not specified (default is empty tuple), computes element-wise correlation and sums the result.keepdim (
bool) – Whether the output tensor hasdimretained or not. Default is False.
- Returns:
The Pearson correlation coefficient(s). The shape depends on the input dimensions and the
keepdimparameter.- Return type:
Example
>>> x = torch.tensor([1.0, 2.0, 3.0, 4.0, 5.0]) >>> y = torch.tensor([2.0, 4.0, 6.0, 8.0, 10.0]) >>> QF.correl(x, y, dim=0) tensor(1.)
>>> x = torch.tensor([[1.0, 2.0, 3.0], ... [4.0, 5.0, 6.0]]) >>> y = torch.tensor([[2.0, 4.0, 5.0], ... [8.0, 10.0, 12.0]]) >>> QF.correl(x, y, dim=1) tensor([0.9820, 1.0000])
>>> QF.correl(x, y, dim=1, keepdim=True) tensor([[0.9820], [1.0000]])