Neighbouring Solutions’ Ranks Correlation (NRC)¶
import numpy as np
import math
from pyxla import load_data, nrc
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)]
}
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
corr, plot = nrc(sphere_sample, suptitle=False)
plot.savefig('nrc-sphere.pdf', bbox_inches='tight')
corr, plot = nrc(easom_sample, suptitle=False)
plot.savefig('nrc-easom.pdf', bbox_inches='tight')