-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Jonas Almeida edited this page Nov 6, 2025
·
29 revisions
Welcome to the metrics wiki!
Let's start by defining a ES6 module at basic.mjs for basic metrics, like Euclidean Distance.
https://epiverse.github.io/metrics/basic.mjsWe can now import this module, or any individual basic metric:
euclid = (await import('https://epiverse.github.io/metrics/basic.mjs')).euclidOne can also retrieve the full module
mod = (await import('https://epiverse.github.io/metrics/basic.mjs'))mod.euclid()
5.196152422706632Note how execution of, say, the Euclidean Distance, is entirely performed on the client side:
dist = ((await import('https://epiverse.github.io/metrics/basic.mjs')).euclid)([1,2,3],[4,5,6])
5.196152422706632note in these demonstrations that, when not specified, the vectors [1,2,3] and [4,5,6] will be used as default inputs.
A quick inspection of the module will show other metrics. such as cosine distance:
mod.cosine([1,2,3],[4,5,6])
0.025368153802923787By definition, metrics are functions that have to satisfy a number of properties, a) non-negative; b) permutable; and c) triangular inequality. The two metrics approached here, Euclidean and Cosine, provide examples of the distinction.
A=[1,0];
B=[0.6,0.8];
C=[-0.8,0.6];mod = (await import('https://epiverse.github.io/metrics/basic.mjs'))dAB = mod.euclid(A,B)
0.894427190999916
dBC = mod.euclid(B,C)
1.414213562373095
dAC = mod.euclid(A,C)
1.8973665961010275
dAB<=dAB+dAC
trueA=[1,0];
B=[0.6,0.8];
C=[-0.8,0.6];dAB = mod.cosine(A,B) = 0.4
dBC = mod.cosine(B,C) = 1
dAC = mod.cosine(A,C) = 1.8
dAC<=(dAB+dBC)
false