2

I have a data-set of 6000 thousands 3D coordinates that I store in a list I named allcoord. I find all the near neighbours of a given point using that function :

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

As you can see I look in a sphere to find all the neighbours of the given point. Now I would like to calculate the probability of the connection knowing that closer the neighbours is, higher is the probability of connection. The model is like a Gaussian but with 3D coordinates.

I'm gonna use this formula : enter image description here

Then for example :

    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)

But I have the following error :

    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

I have two questions :

1) How to determine a good value for sigma ?

2) How to perform that operation on 3D coordinates ?

I need this parameter to determine a minimum value of the Gaussian weight to consider there is a connection between 2 points.

Thank you for the help !

AntMau
  • 295
  • 3
  • 14
  • 2
    Is _coordCenter_ - _coordTest_ meant to be the distance between the points? If so, calculate that as you've done above, or see [this answer](https://stackoverflow.com/a/1401828/7675174) about using `numpy.linalg.norm` which would make your weight calculation `math.exp(-np.linalg.norm(a-b)/2*sygma)`. – import random Sep 21 '17 at 23:56
  • Yeah it is the distance I'm looking for, thank you. No idea concerning sygma ? – AntMau Sep 22 '17 at 15:51
  • Sorry Antoine, my theoretical knowledge in this area isn't strong, maybe you could try a few different values and see which performs better with your data. – import random Sep 24 '17 at 22:08

0 Answers0