-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculate_rmse.py
More file actions
75 lines (62 loc) · 2.64 KB
/
Copy pathcalculate_rmse.py
File metadata and controls
75 lines (62 loc) · 2.64 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
# Import libraries
import pandas as pd
import numpy as np
import json
def calc_RMSE(stoi_arr, listeners_arr) -> float:
"""
Calculates Root Mean Squared Error value when given two arrays.
Order of arguments doesn't matter in this function.
But remember to normalize before passing the arrays.
Output is in the same normalized scale as the input arrays.
Arguments:
stoi_arr (list[float] or np.ndarray): A list of STOI values
listeners_arr (list[float] or np.ndarray): A list of true intelligibility values from clarity JSON file
Returns:
float: RMSE value
"""
error = stoi_arr - listeners_arr
return np.sqrt(np.mean((error) ** 2))
def main() -> None:
# SECTION - Load Data from csv files
# With 'Silent Frame Removal'
mystoi_csv_path = "mystoi_scores_2025-01-16_09-47-05.csv"
pystoi_csv_path = "pystoi_scores_2025-01-16_09-47-05.csv"
true_scores_path = "true_listeners_scores.csv"
# Without 'Silent Frame Removal'
# mystoi_csv_path = "mystoi_scores_2025-01-16_10-37-23.csv"
# pystoi_csv_path = "pystoi_scores_2025-01-16_10-37-23.csv"
# Only 1000 samples
# mystoi_csv_path = "mystoi_scores_2025-01-16_17-25-56.csv"
# pystoi_csv_path = "pystoi_scores_2025-01-16_17-25-56.csv"
# Test Indep Dataset
mystoi_csv_path = "mystoi_train_indep_1.csv"
pystoi_csv_path = "mystoi_train_indep_2.csv"
# Import data frame
mystoi_df = pd.read_csv(mystoi_csv_path)
pystoi_df = pd.read_csv(pystoi_csv_path)
true_scores_df = pd.read_csv(true_scores_path)
# Extract columns
scene_indices = mystoi_df['Scene_Index'].to_numpy()
mystoi_scores = mystoi_df['STOI_Value'].to_numpy()
pystoi_scores = pystoi_df['STOI_Value'].to_numpy()
true_scores = true_scores_df['true_value'].to_numpy()
# Check for matching number of rows
if len(mystoi_df) != len(true_scores):
if len(mystoi_df) < len(true_scores):
true_scores = true_scores[:len(mystoi_scores)]
elif len(mystoi_df) > len(true_scores):
raise Exception("Number of rows in mystoi_scores is greater than the number of rows in true_scores.")
#!SECTION
# SECTION - Calculate RMSE
# Normalize so that true scores are between 0 and 1
true_scores = true_scores/100
rmse_mystoi = calc_RMSE(mystoi_scores, true_scores)
rmse_pystoi = calc_RMSE(pystoi_scores, true_scores)
# Print RMSEs
print(f'MySTOI RMSE: {rmse_mystoi}')
print(f'PySTOI RMSE: {rmse_pystoi}')
print(f'Mystoi RMSE [%]: {rmse_mystoi * 100:.2f}%')
print(f'PySTOI RMSE [%]: {rmse_pystoi * 100:.2f}%')
#!SECTION
if __name__ == '__main__':
main()