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>)
../../_images/45085b940074177f960164461191baf80e2f67c0394282c879cf84673844294d.png
nrc(easom_sample)
({'NRC_for_f0_ranks': '0.3308'}, <Figure size 500x500 with 1 Axes>)
../../_images/c70f85b835a88f7b29e492fd0f9f6502b858028a621456fedbe76323d7df9041.png