Skip to content

Commit

Permalink
switched to pearson coefficient for belts similarity
Browse files Browse the repository at this point in the history
  • Loading branch information
Frix-x committed Jun 30, 2024
1 parent 6712506 commit 92a651b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions shaketune/graph_creators/belts_graph_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import matplotlib.pyplot as plt
import matplotlib.ticker
import numpy as np
from scipy.stats import pearsonr

matplotlib.use('Agg')

Expand Down Expand Up @@ -518,10 +519,11 @@ def belts_calibration(
signal1 = signal1._replace(paired_peaks=pairing_result.paired_peaks, unpaired_peaks=pairing_result.unpaired_peaks1)
signal2 = signal2._replace(paired_peaks=pairing_result.paired_peaks, unpaired_peaks=pairing_result.unpaired_peaks2)

# Calculating R^2 to y=x line to compute the similarity between the two belts
ss_res = np.sum((signal2.psd - signal1.psd) ** 2)
ss_tot = np.sum((signal2.psd - np.mean(signal2.psd)) ** 2)
similarity_factor = (1 - (ss_res / ss_tot)) * 100
# R² proved to be pretty instable to compute the similarity between the two belts
# So now, we use the Pearson correlation coefficient to compute the similarity
correlation, _ = pearsonr(signal1.psd, signal2.psd)
similarity_factor = correlation * 100
similarity_factor = np.clip(similarity_factor, 0, 100)
ConsoleOutput.print(f'Belts estimated similarity: {similarity_factor:.1f}%')

mhi = compute_mhi(similarity_factor, signal1, signal2)
Expand Down

0 comments on commit 92a651b

Please sign in to comment.