MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / jdst

Function jdst

subprojects/llama.cpp/tests/test-backend-ops.cpp:291–316  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

289// difference between 2 sets (Jaccard distance, 0 - no difference, 1 - no overlap)
290template <typename T>
291static double jdst(const T * a, const T * b, size_t n) {
292 std::unordered_map<T, size_t> set_a;
293 std::unordered_map<T, size_t> set_b;
294
295 for (size_t i = 0; i < n; ++i) {
296 set_a[a[i]]++;
297 set_b[b[i]]++;
298 }
299
300 size_t diff = 0;
301
302 for (const auto & p : set_a) {
303 const int64_t na = p.second;
304 const int64_t nb = set_b.find(p.first) != set_b.end() ? set_b.at(p.first) : 0;
305
306 diff += std::abs(na - nb);
307 }
308
309 for (const auto & p : set_b) {
310 if (set_a.find(p.first) == set_a.end()) {
311 diff += p.second;
312 }
313 }
314
315 return (double) diff / (2*n);
316}
317
318// maximum absolute asymmetry between a and b
319// asymmetry: (a - b) / (a + b)

Callers 1

errMethod · 0.85

Calls 3

findMethod · 0.65
atMethod · 0.65
endMethod · 0.45

Tested by

no test coverage detected