注意
跳转到末尾 以下载完整示例代码。
S^2上分布的球面切片Wasserstein
这个例子说明了按照[46]中提出的球形切片Wasserstein差异的计算。
[46] Bonet, C., Berg, P., Courty, N., Septier, F., Drumetz, L., & Pham, M. T. (2023). ‘球面切片-瓦瑟斯坦”。国际学习表示会议。
# Author: Clément Bonet <clement.bonet@univ-ubs.fr>
#
# License: MIT License
# sphinx_gallery_thumbnail_number = 2
import matplotlib.pylab as pl
import numpy as np
import ot
生成数据
绘制数据
fig = pl.figure(figsize=(10, 10))
ax = pl.axes(projection="3d")
ax.grid(False)
u, v = np.mgrid[0 : 2 * np.pi : 30j, 0 : np.pi : 30j]
x = np.cos(u) * np.sin(v)
y = np.sin(u) * np.sin(v)
z = np.cos(v)
ax.plot_surface(x, y, z, color="gray", alpha=0.03)
ax.plot_wireframe(x, y, z, linewidth=1, alpha=0.25, color="gray")
ax.scatter(xs[:, 0], xs[:, 1], xs[:, 2], label="Source")
ax.scatter(xt[:, 0], xt[:, 1], xt[:, 2], label="Target")
fs = 10
# Labels
ax.set_xlabel("x", fontsize=fs)
ax.set_ylabel("y", fontsize=fs)
ax.set_zlabel("z", fontsize=fs)
ax.view_init(20, 120)
ax.set_xlim(-1.5, 1.5)
ax.set_ylim(-1.5, 1.5)
ax.set_zlim(-1.5, 1.5)
# Ticks
ax.set_xticks([-1, 0, 1])
ax.set_yticks([-1, 0, 1])
ax.set_zticks([-1, 0, 1])
pl.legend(loc=0)
pl.title("Source and Target distribution")

Text(0.5, 1.0, 'Source and Target distribution')
不同种子和投影数量的球形切片瓦瑟斯坦
n_seed = 20
n_projections_arr = np.logspace(0, 3, 10, dtype=int)
res = np.empty((n_seed, 10))
绘制球形切片瓦瑟斯坦
pl.figure(2)
pl.plot(n_projections_arr, res_mean, label=r"$SSW_1$")
pl.fill_between(
n_projections_arr, res_mean - 2 * res_std, res_mean + 2 * res_std, alpha=0.5
)
pl.legend()
pl.xscale("log")
pl.xlabel("Number of projections")
pl.ylabel("Distance")
pl.title("Spherical Sliced Wasserstein Distance with 95% confidence interval")
pl.show()

脚本的总运行时间: (0 分钟 5.158 秒)