Canonical distance between points in hypercube

130 Views Asked by At

I want to find the distance between a point and the other points of the hypercube. Thus, I compute the euclidean distance between my anchor point and all the points of the domain. I normalize everything in the unity hypercube prior to that.

In 2D, I get the expected behavior: for a given distance from the center point, I get a circle.

(fig 1. 2D, d=0.2)

But when looking at 3D, there is no more circle (with the same distance) when looking at canonical planes. If I increase the distance to $d = 0.5$, the circle seems to come back. I also tried to change the type of norm but I don't find any to have a circle.

(fig 2. 3D, d=0.2)

  • Is this behavior coherent?
  • How to correctly get a circle for every canonical plot?

I will use this to find a point which is not to close from the others in any projections.

If you want to recreate the figures, here is the python script I am using (you can comment it of course but I am more interested about the math part):

from sklearn import preprocessing
import matplotlib.pyplot as plt
from matplotlib import cm
import numpy as np
import itertools

scaler = preprocessing.MinMaxScaler()
scaler.fit(np.array([[-5, 0, -2], [10, 15, 1]]))

num = 30
dim = 3

x = np.linspace(-5, 10, num=num)
y = np.linspace(0, 15, num=num)
z = np.linspace(-2, 1, num=num)
points = []
for i, j, k in itertools.product(x, y, z):
    points += [(float(i), float(j), float(k))]

point = [(2.5, 7.5, -0.5)]
point_scaled = scaler.transform(point)

def f(x):
    x_scaled = scaler.transform(np.array(x).reshape(1, -1))
    too_close = [True if np.linalg.norm(x_scaled - point_scaled) < 0.2
                          else False]
    if too_close[0]:
        return 0
    else:
        return 1

pred = []
for p in points:
    pred.append(f(p))
points = np.array(points)
pred = np.array(pred).flatten()

# Plotting
point = [2.5, 7.5, -0.5]
c_map = cm.viridis
bounds = np.linspace(-0.1, 1.1, 4, endpoint=True)
p_lst = [r"$x_1$", r"$x_2$", r"$x_3$"]

fig = plt.figure('Design of Experiment')
plt.tick_params(axis='both', labelsize=8)

for i in range(0, dim - 1):
    for j in range(i + 1, dim):
        ax = plt.subplot2grid((dim, dim), (j, i))
        plt.tricontourf(points[:, i], points[:, j], pred, bounds,
                        antialiased=True, cmap=c_map)
        ax.scatter(point[i], point[j], s=10, c='k', marker='o')
        ax.tick_params(axis='both', labelsize=(10 - dim))
        if i == 0:
            ax.set_ylabel(p_lst[j])
        if j == (dim - 1):
            ax.set_xlabel(p_lst[i])

cbar = plt.colorbar()
cbar.set_label('f', fontsize=28)
fig.tight_layout()
plt.show()