假设我在6维空间中给出了一个点云,可以根据需要将该点云设为任意密度。这些点原来位于低维多面体的表面上(即,点向量(x1,x2,... x6)看起来是共面的)。
我想找到这个未知多面体的顶点,而我目前的尝试是通过Python中的scipy接口利用qhull算法。一开始,我只会收到错误消息,这显然是由较低维的输入和/或许多退化点引起的。我已经尝试了几种蛮力方法来消除退化点,但并不是很成功,因此最终,我认为所有这些点都必须位于凸包上。
这个问题非常有帮助,因为它建议通过主成分分析进行降维。如果将这些点投影到4D超平面,则qhull算法将运行而不会出错(对于任何更高维度,它均不会运行)。
from scipy.spatial import ConvexHull
from sklearn.decomposition import PCA
model = PCA(n_components=4).fit(initial_points)
proj_points = model.transform(initial_points)
hull = ConvexHull(proj_points, qhull_options = "Qx")
上述问题的答案提到,在计算投影点的凸包后,需要将这些单纯形转换回去。但是qhull输出仅包含索引,为什么这些索引不匹配初始点的索引?
现在我的问题是我不知道要使用哪种精度才能实际获得正确的顶点。无论我使点云有多密集,获得的顶点都以不同的精度而不同。例如,对于(10000,6)数组中的初始点,我得到(其中E0.03是此值的最大值):
hull1 = ConvexHull(proj_points, qhull_options = "Qx, E0.03")
print len(hull1.vertices)
print hull1.vertices
5
[ 437 2116 3978 7519 9381]
并将其绘制在轴0,1,2(某些蓝色点代表对初始点云的选择)的某些(不是十分有用的)投影中:
但是为了获得更高的精度(当然),我得到了不同的设置:
hull2 = ConvexHull(proj_points, qhull_options = "Qx, E0.003")
print len(hull2.vertices)
print hull2.vertices
29
[ 74 75 436 437 756 1117 2116 2366 2618 2937 3297 3615 3616 3978 3979
4340 4561 4657 4659 4924 5338 5797 6336 7519 7882 8200 9381 9427 9470]
相同的投影(角度略有不同):
I would suspect that the first picture has not enough vertices and that the second picture possibly has too many. Though of course I cannot extract rigorous information from these plots. But is there a good way of finding out which precision to use? Or perhaps a completely different approach to this problem (I tried a few already)?
In this answer, I will assume you have already used PCA to near-losslessly compress the data to 4-dimensional data, where the reduced data lies in a 4-dimensional polytope with conceptually few faces. I will describe an approach to solve for the faces of this polytope, which will in turn give you the vertices.
Let xi in R4, i = 1, ..., m, be the PCA-reduced data points.
Let F = (a, b) be a face, where a is in R4 with a • a = 1 and b is in R.
We define the face loss function L as follows, where λ+, λ- > 0 are parameters you choose. λ+ should be a very small positive number. λ- should be a very large positive number.
L(F) = sumi(λ+ • max(0, a • xi + b) - λ- • min(0, a • xi + b))
We want to find minimal faces F with respect to the loss function L. The small set of all minimal faces will describe your polytope. You can solve for minimal faces by randomly initializing F and then performing gradient descent using the partial derivatives ∂L / ∂aj, j = 1, 2, 3, 4, and ∂L / ∂b. At each step of gradient descent, constrain a • a to be 1 by normalizing.
∂L / ∂aj = sumi(λ+ • xj • [a • xi + b > 0] - λ- • xj • [a • xi + b < 0]) for j = 1, 2, 3, 4
∂L/∂b= SUM我(λ + •[一个•X我+ B> 0] - λ - •[一个•X我+ B <0])
注意艾弗森括号:如果P为true,则[P] = 1;如果P为false,则[P] = 0。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句