Neighbouring Solutions’ Ranks Correlation (NRC)¶
import numpy as np
import math
from pyxla import load_data, nrc
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)]
}
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) # loaded in-place
load_data(easom_sample) # loaded in-place
WARNING:root:The Hilbert curve with dimension 1 is just a number line. You are sampling around points on a number line.
nrc(sphere_sample)
({'NRC_for_f0_ranks': '0.9970',
'NRC_for_v0_ranks': '0.9949',
'NRC_for_v1_ranks': '-0.2022',
'NRC_for_paretoV_ranks': '0.8840',
'NRC_for_Deb_ranks': '0.8898',
'NRC_for_paretoFV_ranks': '0.9961'},
<Figure size 1500x1000 with 6 Axes>)
nrc(easom_sample)
({'NRC_for_f0_ranks': '0.3308'}, <Figure size 500x500 with 1 Axes>)