forked from julianmer/DA-MUSIC_ICASSP22
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrorMeasures.py
More file actions
86 lines (63 loc) · 3.24 KB
/
errorMeasures.py
File metadata and controls
86 lines (63 loc) · 3.24 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
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
74
75
76
77
78
79
80
81
82
83
84
85
86
####################################################################################################
# errorMeasures.py #
####################################################################################################
# #
# Authors: J. M. #
# #
# Created: 27/04/21 #
# #
# Purpose: Definitions of custom error measures used to evaluate DoA estimation algorithms. #
# #
####################################################################################################
#*************#
# imports #
#*************#
import numpy as np
from utils import permutations
#***********************************************#
# eliminate randomness to reproduce results #
#***********************************************#
np.random.seed(42)
#**********************#
# simple mean rmse #
#**********************#
def mean_naive_rmse(predDoA, trueDoA):
"""
Calculates the mean of all the samples of a naive rmse, i.e. an rmse that
takes the squared error by padding/truncating and then sorting the DoA.
@param predDoA -- The estimated DoA angles in radians (same length as true DoA).
@param trueDoA -- The ground truth DoA angles in radians.
@returns -- The mean of the naive rmse.
"""
num_samples = trueDoA.shape[0]
allMSE = np.zeros(num_samples)
for i in range(num_samples):
# angular difference
diff = ((np.sort(predDoA[i]) - np.sort(trueDoA[i])) + np.pi / 2) % np.pi - np.pi / 2
# rmse
allMSE[i] = np.mean(diff ** 2) ** (1 / 2)
return np.mean(allMSE)
#***********************************#
# mean minimal permutation rmse #
#***********************************#
def mean_min_perm_rmse(predDoA, trueDoA):
"""
Calculates the mean of all the samples of the minimal rmse of
(all permutations of) the predicted DoA and the true DoA.
@param predDoA -- The estimated DoA angles in radians (same length as true DoA).
@param trueDoA -- The ground truth DoA angles in radians.
@returns -- The mean of minimal rmse.
"""
num_samples = trueDoA.shape[0]
allMSE = np.zeros(num_samples)
for i in range(num_samples):
# get permutations of estimated DoA
diffs = np.zeros(np.math.factorial(trueDoA.shape[1]))
for j, perm in enumerate(permutations(list(predDoA[i]))):
# angular difference
diff = ((perm - trueDoA[i]) + np.pi / 2) % np.pi - np.pi / 2
# rmse
diffs[j] = np.mean(diff ** 2) ** (1 / 2)
# choose minimal rmse as error
allMSE[i] = np.amin(diffs)
return np.mean(allMSE)