MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / distance

Function distance

examples/machine_learning/kmeans.cpp:19–29  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17using namespace af;
18
19array distance(array data, array means) {
20 int n = data.dims(0); // Number of data points
21 int k = means.dims(1); // Number of means
22
23 array data2 = tile(data, 1, k, 1);
24 array means2 = tile(means, n, 1, 1);
25
26 // Currently using manhattan distance
27 // Can be replaced with other distance measures
28 return sum(abs(data2 - means2), 2);
29}
30
31// Get cluster id of each location in data
32array clusterize(const array data, const array means) {

Callers 1

clusterizeFunction · 0.70

Calls 4

tileFunction · 0.50
sumFunction · 0.50
absFunction · 0.50
dimsMethod · 0.45

Tested by

no test coverage detected