这是想法 - 来自 D+1 中狄利克雷分布的样本点,选择 D 点,这样你在单纯形中是均匀的
x 0 +x 1 +x 2 <= 1, x i >= 0
要制作八面体,请随机选择八分圆来说明您的观点。
Python 中的代码
import math
import random
def Dirichlet():
"""sample 4d Dirichlet"""
x0 = -math.log(1.0 - random.random()) # exponential
x1 = -math.log(1.0 - random.random()) # exponential
x2 = -math.log(1.0 - random.random()) # exponential
x3 = -math.log(1.0 - random.random()) # exponential
s = 1.0/(x0+x1+x2+x3) # scaling
return (x0*s, x1*s, x2*s, x3*s)
def OctahedronSampling():
x0, x1, x2, _ = Dirichlet()
octant = random.randint(0, 7)
if octant == 0:
return (x0, x1, x2)
elif octant == 1:
return (x0, -x1, x2)
elif octant == 2:
return (x0, x1, -x2)
elif octant == 3:
return (x0, -x1, -x2)
elif octant == 4:
return (-x0, x1, x2)
elif octant == 5:
return (-x0, -x1, x2)
elif octant == 6:
return (-x0, x1, -x2)
elif octant == 7:
return (-x0, -x1, -x2)
return None
for _ in range(0, 2000):
x0, x1, x2 = OctahedronSampling()
print(f"{x0} {x1} {x2}")
这是带有 2K 点的快速图表
