def point2cluster(datapointwts,seeds,theta):
cluster = {};p2cluster = []; gedges = {}; gedges1 = {}; nedges = {}; std = {}; seeds1 = []; seedweight = [];
X = [(lonconst * xx[0], latconst * xx[1], theta / 180 * xx[2]) for xx in datapointwts]; S = [(lonconst * xx[0], latconst * xx[1], theta / 180 * xx[2]) for xx in seeds];
Xrot = [(lonconst * xx[0], latconst * xx[1], theta / 180 * (xx[2]%360)) for xx in datapointwts]; Srot = [(lonconst * xx[0], latconst * xx[1], theta / 180 * (xx[2]%360)) for xx in seeds];
for cd in range(len(seeds)):
cluster[cd] = []
nbrs = NearestNeighbors(n_neighbors=1, algorithm='ball_tree').fit(S)
distances, indices = nbrs.kneighbors(X)
nbrsrot = NearestNeighbors(n_neighbors=1, algorithm='ball_tree').fit(Srot)
distancesrot, indicesrot = nbrsrot.kneighbors(Xrot)
for ii, ll in enumerate(indices):
# print(distances[ii],distancesrot[ii],ll,indices[ii],indicesrot[ii])
cd = indicesrot[ii][0]
if distances[ii][0] < distancesrot[ii][0]:
cd = indices[ii][0];
# print(cd,distances[ii],distancesrot[ii],ll,indices[ii],indicesrot[ii])
cluster[cd].append(datapointwts[ii])
p2cluster.append(cd)
return(cluster,p2cluster)
评论列表
文章目录