Fitness Distance Correlation (FDC)¶
import math
from pyxla import fdc
from pyxla.util import load_data, load_sample
from pyxla.sampling import HilbertCurveSampler
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)
WARNING:root:The Hilbert curve with dimension 1 is just a number line. You are sampling around points on a number line.
WARNING:root:The Hilbert curve with dimension 1 is just a number line. You are sampling around points on a number line.
fdc(sphere_sample)
WARNING:root:No D file is present, thus, computing the D file... Computing an entire D file can be time consuming. Instead, you can call the function with the keyword argument `compute_D_file` set to `False` to speed up computation, as only the required distances will be calculated.
INFO:root:D file has been loaded to the current sample and is saved to ./Sphere_D.csv
({'fdc_f0': np.float64(0.9994749459239282)}, <Figure size 500x500 with 1 Axes>)
fdc(deceptive_sample)
WARNING:root:No D file is present, thus, computing the D file... Computing an entire D file can be time consuming. Instead, you can call the function with the keyword argument `compute_D_file` set to `False` to speed up computation, as only the required distances will be calculated.
INFO:root:D file has been loaded to the current sample and is saved to ./Deceptive_D.csv
({'fdc_f0': np.float64(-0.7225442544254425)},
<Figure size 500x500 with 1 Axes>)
On NK instances¶
Note: computing the D file can take a while…
%cd ../../..
nk_k1 = load_sample('nk_n14_k1')
nk_k2 = load_sample('nk_n14_k2')
nk_k4 = load_sample('nk_n14_k4')
fdc(nk_k1)
fdc(nk_k2)
fdc(nk_k4)