Understanding Isometrization with a Known Transformation
In [1]:
Copied!
import random
import numpy as np
import pandas as pd
random.seed(20250409)
N = 500
u = np.random.uniform(0, 1, (N, 2))
u_df = pd.DataFrame(u, columns=['x', 'y'])
import random
import numpy as np
import pandas as pd
random.seed(20250409)
N = 500
u = np.random.uniform(0, 1, (N, 2))
u_df = pd.DataFrame(u, columns=['x', 'y'])
In [2]:
Copied!
from distortions.geometry import bind_metric
from distortions.visualization import dplot
def plot_transformation(f, H, Hvv, Hs, transformation_bw=2, metric_bw=20, width=450, height=450, radiusMin=1, radiusMax=10):
combined_df = bind_metric(f, Hvv, Hs)
combined_df["id"] = combined_df.index
f_df = pd.DataFrame(f, columns=['x', 'y'])
embed_dict = {}
for n in range(len(f_df)):
embed_dict[n] = f_df.iloc[n, :]
embed_dict[n]["id"] = n
h_dict = {k: H[k] for k in range(len(H))}
return dplot(combined_df, width=width, height=height, labelFontSize=14)\
.mapping(x="embedding_0", y="embedding_1")\
.geom_ellipse(radiusMin=radiusMin, radiusMax=radiusMax, opacity=0.8)\
.inter_isometry(metrics=h_dict, otherClasses=["ellipse"], transformation_bw=transformation_bw, metric_bw=metric_bw, opacity=0.4, stroke="#c6c6c6", strokeWidth=1.5)\
.labs(x="x-axis", y="y-axis")
from distortions.geometry import bind_metric
from distortions.visualization import dplot
def plot_transformation(f, H, Hvv, Hs, transformation_bw=2, metric_bw=20, width=450, height=450, radiusMin=1, radiusMax=10):
combined_df = bind_metric(f, Hvv, Hs)
combined_df["id"] = combined_df.index
f_df = pd.DataFrame(f, columns=['x', 'y'])
embed_dict = {}
for n in range(len(f_df)):
embed_dict[n] = f_df.iloc[n, :]
embed_dict[n]["id"] = n
h_dict = {k: H[k] for k in range(len(H))}
return dplot(combined_df, width=width, height=height, labelFontSize=14)\
.mapping(x="embedding_0", y="embedding_1")\
.geom_ellipse(radiusMin=radiusMin, radiusMax=radiusMax, opacity=0.8)\
.inter_isometry(metrics=h_dict, otherClasses=["ellipse"], transformation_bw=transformation_bw, metric_bw=metric_bw, opacity=0.4, stroke="#c6c6c6", strokeWidth=1.5)\
.labs(x="x-axis", y="y-axis")
In [3]:
Copied!
H = np.zeros((N, 2, 2))
Hvv = np.zeros((N, 2, 2))
Hs = np.zeros((N, 2))
for i in range(N):
H[i] = np.array([[1, 0], [0, 1]])
Hvv[i] = np.eye(2)
Hs[i] = [1, 1]
H = np.zeros((N, 2, 2))
Hvv = np.zeros((N, 2, 2))
Hs = np.zeros((N, 2))
for i in range(N):
H[i] = np.array([[1, 0], [0, 1]])
Hvv[i] = np.eye(2)
Hs[i] = [1, 1]
In [4]:
Copied!
plots = {}
plots["original"] = plot_transformation(u, H, Hvv, Hs)
plots = {}
plots["original"] = plot_transformation(u, H, Hvv, Hs)
In [5]:
Copied!
f = u.copy()
f[:, 1] = f[:, 1] ** 2
f = u.copy()
f[:, 1] = f[:, 1] ** 2
In [6]:
Copied!
plots["transformed"] = plot_transformation(f, H, Hvv, Hs)
plots["transformed"] = plot_transformation(f, H, Hvv, Hs)
In [7]:
Copied!
for i in range(N):
H[i] = np.array([[1, 0], [0, 2 * f[i, 1]]])
Hvv[i] = np.eye(2)
Hs[i] = [1, 2 * f[i, 1]]
plots["distortion"] = plot_transformation(f, H, Hvv, Hs)
for i in range(N):
H[i] = np.array([[1, 0], [0, 2 * f[i, 1]]])
Hvv[i] = np.eye(2)
Hs[i] = [1, 2 * f[i, 1]]
plots["distortion"] = plot_transformation(f, H, Hvv, Hs)
In [8]:
Copied!
#[p.save(f"../paper/figures/{k}.svg") for k, p in plots.items()]
#[p.save(f"../paper/figures/{k}.svg") for k, p in plots.items()]
In [9]:
Copied!
[display(p) for p in plots.values()]
[display(p) for p in plots.values()]
dplot(dataset=[{'embedding_0': 0.8448678500972645, 'embedding_1': 0.8949533007524632, 'x0': 1.0, 'y0': 0.0, 'x…
dplot(dataset=[{'embedding_0': 0.8448678500972645, 'embedding_1': 0.8009414105277287, 'x0': 1.0, 'y0': 0.0, 'x…
dplot(dataset=[{'embedding_0': 0.8448678500972645, 'embedding_1': 0.8009414105277287, 'x0': 1.0, 'y0': 0.0, 'x…
Out[9]:
[None, None, None]