Neighbouring Change in Feasibility (N∆Feas)

import math

from pyxla import ncf
from pyxla.util import load_data
from pyxla.sampling import HilbertCurveSampler
from matplotlib import rc_file
rc_file('../../../../src/.matplotlibrc')
sphere_sample_all_v = {
    "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)]
}

sphere_sample_v0 = {
    "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]
}

sphere_sample_v1 = {
    "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: 8 * math.sin(20 * x)]
}

load_data(sphere_sample_all_v)
load_data(sphere_sample_v0)
load_data(sphere_sample_v1)

The constrained sphere problem has 2 constraints:

(1)\[v_0(x) = x^2 - 2 \leq 0,~\text{and}\]
(2)\[v_1(x) = 8 \cdot \sin(20 \cdot x) \leq 0.\]

NCF with both constraints:

proportions, plot = ncf(sphere_sample_all_v, title=False)
plot.figure.savefig('ncf-all-v.pdf', bbox_inches='tight')

For the spherical constraint:

proportions, plot = ncf(sphere_sample_v0, title=False)
plot.figure.savefig('ncf-v0.pdf', bbox_inches='tight')

For the sinusodial constraint:

proportions, plot = ncf(sphere_sample_v1, title=False)
plot.figure.savefig('ncf-v1.pdf', bbox_inches='tight')