Fitness Distance Correlation (FDC)¶
import math
from pyxla import fdc
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),
"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
}
load_data(sphere_sample)
load_data(deceptive_sample)
corr, plot = fdc(sphere_sample)
plot.savefig('fdc-sphere.pdf', bbox_inches='tight')
corr, plot = fdc(deceptive_sample)
plot.savefig('fdc-deceptive.pdf', bbox_inches='tight')
On NK instances¶
Note: computing the D file can take a while…
%cd ../../..
nk_k1 = load_sample('nk_n14_k1')
corr, plot = fdc(nk_k1)
plot.savefig('fdc-nk1.pdf', bbox_inches='tight')
nk_k2 = load_sample('nk_n14_k2')
corr, plot = fdc(nk_k2)
plot.savefig('fdc-nk2.pdf', bbox_inches='tight')
nk_k4 = load_sample('nk_n14_k4')
corr, plot = fdc(nk_k4)
plot.savefig('fdc-nk4.pdf', bbox_inches='tight')