Home   >   User Resources   >   Online Help   >   apaGraph.kNN.Build.K
 

 

Function index Version 3.0.0

apaGraph.kNN.Build.K(Distances, K, DoAddUnconnectedOnly)

Excel=apaGraph.kNN.Build.K(Distances, K, DoAddUnconnectedOnly)

Result

Returns the edge list of the k-nearest-neighbor (kNN) graph for a given k. Each row contains node i, node j (i < j) and the distance d(i, j).

Syntax

Distances: n x n distance matrix

K: number of nearest neighbors to consider, between 0 and n - 1

DoAddUnconnectedOnly: optional; TRUE: from round k = 2 on, the k-th nearest neighbor of a node is only linked if the two nodes are not yet connected through a path; FALSE: all kNN edges; default: FALSE

Remarks

Nodes i and j are linked if j is among the K nearest neighbors of i or i is among the K nearest neighbors of j; ties are broken by the lower node index. With DoAddUnconnectedOnly = TRUE, the graph is built in rounds k = 1 to K as in apaGraph.kNN.Build: from round k = 2 on, the k-th nearest neighbor of a node is only linked if the two nodes were not connected through a path after round k - 1. If the graph has no edges (K = 0 or a single node), the function returns a row of #N/A.

Pressing Esc aborts the calculation; the function then returns "Calculation aborted by user."