三维坐标间的高斯权重

2024-09-29 23:26:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个60万个三维坐标的数据集,我把它存储在一个名为allcoord的列表中。我使用该函数找到给定点的所有近邻:

def nearNeighbors(allcoord, idself, radius):

    xc, yc, zc = allcoord[idself][0:3]
    neighbors = []   
    for i in range(len(allcoord)):
        if i != idself:
            x, y, z = allcoord[i][0:3]          
            if (x-xc)*(x-xc) + (y-yc)*(y-yc) + (z-zc)*(z-zc) <= radius*radius:
                neighbors.append(i) 

    return neighbors

如你所见,我在一个球体中寻找给定点的所有邻域。现在我想计算连接的概率,知道邻居越近,连接的概率就越高。这个模型就像一个高斯模型,但是有三维坐标。你知道吗

我要用这个公式: enter image description here

例如:

    import math 
    import numpy as np

    a = np.asarray([1,1,3])
    b = np.asarray([1.5,0.8,2.4])
    sygma = 1

    gaussianweight = math.exp(-(a-b)*(a-b)/2*sygma)

但我有以下错误:

    Traceback (most recent call last):

    File "<ipython-input-39-96dd84161692>", line 9, in <module>
    gaussianweight = math.exp(-(a-b)*(a-b)/2*sygma)

    TypeError: only length-1 arrays can be converted to Python scalars

我有两个问题:

1)如何确定西格玛的良好价值?你知道吗

2)如何在三维坐标上执行该操作?你知道吗

我需要这个参数来确定高斯权重的最小值,以考虑两点之间有联系。你知道吗

谢谢你的帮助!你知道吗


Tags: in模型ifnpzcneighborsmath概率

热门问题