我正在尝试计算 10 维空间中 9 个点的凸包。通过 scipy 接口,我正在调用scipy.spatial.ConvexHull(points)并获取QH6214 qhull input error: not enough points(9) to construct initial simplex (need 12)
我认为无论维度如何,凸包的定义都是明确的。这里发生了什么?我可以调用其他函数来解决这个问题吗?
小智 4
也许在计算船体之前将点投影到超平面上就可以了。
例如,使用工具包sklearn.decomposition.PCA中的主成分分析类scikit-learn来减少维度。
vertices = np.random.randn(9, 10)
from sklearn.decomposition import PCA
model = PCA(n_components=8).fit(vertices)
Run Code Online (Sandbox Code Playgroud)
model.transform现在,您可以使用和从顶点到投影来回变换model.inverse_transform。
proj_vertices = model.transform(vertices)
hull_kinda = ConvexHull(proj_vertices)
hull_kinda.simplices
Run Code Online (Sandbox Code Playgroud)
这会输出类似这样的内容
array([[6, 4, 3, 8, 0, 7, 5, 1],
[2, 4, 3, 8, 0, 7, 5, 1],
[2, 6, 3, 8, 0, 7, 5, 1],
[2, 6, 4, 8, 0, 7, 5, 1],
[2, 6, 4, 3, 0, 7, 5, 1],
[2, 6, 4, 3, 8, 7, 5, 1],
[2, 6, 4, 3, 8, 0, 5, 1],
[2, 6, 4, 3, 8, 0, 7, 1],
[2, 6, 4, 3, 8, 0, 7, 5]], dtype=int32)
Run Code Online (Sandbox Code Playgroud)
现在使用 将model.inverse_transform单纯形恢复到您的 10 维中。