-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.py
73 lines (65 loc) · 1.53 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 18 13:01:10 2018
@author: qsyang
"""
import numpy as np
import torch
import math
from scipy.stats import pearsonr
from scipy.stats import spearmanr
def LCC(x,y):
'''
Calculate the LCC of the two 1D tensors
Args:
x,y are 1D tensors
'''
x = np.array(x)
y = np.array(y)
return pearsonr(x,y)[0]
def LCC_Mean(x,y):
'''
Calculate LCC of the row-mean of 2D tensor : x,y
Args:
x,y are 2D tensors with the shape: [testset_size, 10]
'''
x_mean = x.mean(dim=1)
y_mean = y.mean(dim=1)
return LCC(x_mean,y_mean)
def LCC_Std(x,y):
'''
Calculate LCC of the row-std of 2D tensor : x,y
Args:
x,y are 2D tensors with the shape: [testset_size, 10]
'''
x_std = x.std(dim=1)
y_std = y.std(dim=1)
return LCC(x_std,y_std)
def SRCC(x,y):
'''
Calculate the SRCC of the two 1D tensors
Args:
x,y are 1D tensors
'''
x = np.array(x)
y = np.array(y)
return spearmanr(x,y)[0]
def SRCC_Mean(x,y):
'''
Calculate SRCC of the row-mean of 2D tensor : x,y
Args:
x,y are 2D tensors with the shape: [testset_size, 10]
'''
x_mean = x.mean(dim=1)
y_mean = y.mean(dim=1)
return SRCC(x_mean,y_mean)
def SRCC_Std(x,y):
'''
Calculate SRCC of the row-std of 2D tensor : x,y
Args:
x,y are 2D tensors with the shape: [testset_size, 10]
'''
x_std = x.std(dim=1)
y_std = y.std(dim=1)
return SRCC(x_std,y_std)