Pairwise Distance Correlation (PDC)

import math
import numpy as np

from pyxla import pdc
from pyxla.util import load_data, load_sample
from pyxla.sampling import HilbertCurveSampler
from matplotlib import rc_file
rc_file('../../../../src/.matplotlibrc')
sphere_sample = {
    "name": "Sphere",
    "X": HilbertCurveSampler(sample_size=100, dim=1, l_bound=-5, u_bound=5, seed=42),
    "F": lambda x: x**2,
    "V": [lambda x: x**2 - 2, lambda x: 8 * math.sin(20 * x)]
}

deceptive_sample = {
    "name": "Deceptive",
    "X": HilbertCurveSampler(sample_size=100, dim=1, l_bound=0, u_bound=6, seed=42),
    "F": lambda x: (0.4 * x - 2) ** 2 if x > 0.625 else (10 * x - 4) ** 2 - 2,
    "V": lambda x: ((0.4 * x - 2) ** 2 if x > 0.625 else (10 * x - 4) ** 2 - 2) - 1
}

easom_sample = {
    "name": "Easom",
    "X": HilbertCurveSampler(sample_size=100, dim=2, l_bound=-5, u_bound=5, seed=42),
    "F": lambda X: np.cos(X[0]) * X[1] * np.e**(- (X[0] - np.pi)**2 - (X[1] - np.pi)**2)
}


load_data(sphere_sample)
load_data(deceptive_sample)
load_data(easom_sample)
corr, plot = pdc(sphere_sample, suptitle=False)
plot.savefig('pdc-sphere.pdf', bbox_inches='tight')
corr, plot = pdc(deceptive_sample, suptitle=False)
plot.savefig('pdc-deceptive.pdf', bbox_inches='tight')
corr, plot = pdc(easom_sample, suptitle=False)
plot.savefig('pdc-easom.pdf', bbox_inches='tight')