-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalibrationStatistics.py
More file actions
35 lines (30 loc) · 1.04 KB
/
CalibrationStatistics.py
File metadata and controls
35 lines (30 loc) · 1.04 KB
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
import numpy as np
from scipy import stats
def CalibrationStatistics(yh,gt,Bh,Bgt):
'''
Different statistics/metrics for benchmarking calibration performance:
rmse: Root-Mean-Square-Error
nrmse: Normalized RMSE
corr: Pearson correlation between calibrated and groundtruth samples
deltaB: Froebinus norm between underyling and calculated calibration matrix B
Inputs:
yh: calibrated measurements, size [n x m]
gt: ground-truth measurement, size [n x m]
Bh: estimated calibration matrix, size [n x n]
Bgt: ground-truth calibration matrix, size [n x n]
returns dict holding the 4 metrics as described above
'''
S = {
'rmse': rms(yh-gt),
'nrmse': rms(yh-gt)/rms(gt),
'corr': mean_row_wise_corr(yh,gt),
'deltaB': np.linalg.norm(Bh-Bgt,ord='fro')
}
return S
def rms(a):
return np.sqrt( np.mean( (a)**2) )
def mean_row_wise_corr(a,b):
r = np.zeros((a.shape[0],1))
for i in range(a.shape[0]):
r[i] = stats.pearsonr(a[i,:],b[i,:])[0]
return np.mean(r)