#66: Stop execution if Pearson correlation is negative

This commit is contained in:
Benjamin Loison 2024-05-15 20:15:20 +02:00
parent 60a9dfe89c
commit f719ff767a
No known key found for this signature in database
3 changed files with 10 additions and 6 deletions

View File

@ -26,7 +26,7 @@ match DISTANCE:
from rms_diff import rmsDiffNumpy
case PEARSON_CORRELATION:
import scipy
from utils import getPearsonCorrelation
from utils import getPearsonCorrelationDistance
setting = ','.join([escapeFilePath(imageCameraFolder) for imageCameraFolder in IMAGES_CAMERAS_FOLDER]) + f'_{DENOISER}'
@ -194,7 +194,7 @@ for computeExtremes in tqdm(([True] if minColor is None or maxColor is None else
case ROOT_MEAN_SQUARE:
distance = rmsDiffNumpy(cameraTestingImageNoise, camerasIterativeMean[camera].mean)
case PEARSON_CORRELATION:
distance = getPearsonCorrelation(cameraTestingImagesNoise[actualCamera][cameraTestingImageIndex], camerasIterativeMean[camera].mean)
distance = getPearsonCorrelationDistance(cameraTestingImagesNoise[actualCamera][cameraTestingImageIndex], camerasIterativeMean[camera].mean)
print(f'{cameraTrainingImageIndex=} {cameraTestingImageIndex=} {camera=} {actualCamera=} {distance=}')
if minimalDistance is None or distance < minimalDistance:
minimalDistance = distance

View File

@ -20,7 +20,7 @@ match DISTANCE:
from rms_diff import rmsDiffNumpy
case PEARSON_CORRELATION:
import scipy
from utils import getPearsonCorrelation
from utils import getPearsonCorrelationDistance
setting = escapeFilePath(IMAGES_FOLDER) + f'_{DENOISER}'
@ -67,7 +67,7 @@ for computeExtremes in tqdm(([True] if minColor is None or maxColor is None else
case ROOT_MEAN_SQUARE:
distance = rmsDiffNumpy(firstImage, secondImage)
case PEARSON_CORRELATION:
distance = getPearsonCorrelation(firstImage, secondImage)
distance = getPearsonCorrelationDistance(firstImage, secondImage)
distances += [distance]
for subgroupIndex in range(NUMBER_OF_SUBGROUPS):

View File

@ -43,8 +43,12 @@ class Distance(Enum)
def getEndUserName(self):
return self.name.replace('_', '').title()
def getPearsonCorrelation(firstImage, secondImage):
return abs(scipy.stats.pearsonr(firstImage.flatten(), secondImage.flatten()).statistic - 1)
def getPearsonCorrelationDistance(firstImage, secondImage):
pearsonCorrelation = scipy.stats.pearsonr(firstImage.flatten(), secondImage.flatten()).statistic
if pearsonCorrelation < 0:
print('Negative Pearson correlation, investigate further!')
exit(1)
return abs(pearsonCorrelation - 1)
# Source: https://stackoverflow.com/a/43346070
def getGaussianKernel(size, sigma):