math.distances: adding some distance functions.
parent
95b82eecfa
commit
af8f23a78c
|
@ -0,0 +1 @@
|
||||||
|
John Benediktsson
|
|
@ -0,0 +1,8 @@
|
||||||
|
! Copyright (C) 2012 John Benediktsson
|
||||||
|
! See http://factorcode.org/license.txt for BSD license
|
||||||
|
|
||||||
|
USING: math.distances tools.test ;
|
||||||
|
|
||||||
|
IN: math.distances.tests
|
||||||
|
|
||||||
|
{ 1 } [ "hello" "jello" hamming-distance ] unit-test
|
|
@ -0,0 +1,21 @@
|
||||||
|
! Copyright (C) 2012 John Benediktsson
|
||||||
|
! See http://factorcode.org/license.txt for BSD license
|
||||||
|
|
||||||
|
USING: kernel math math.functions sequences sequences.extras ;
|
||||||
|
|
||||||
|
IN: math.distances
|
||||||
|
|
||||||
|
: hamming-distance ( a b -- n )
|
||||||
|
[ = not ] 2count ; inline
|
||||||
|
|
||||||
|
: minkowski-distance ( a b p -- n )
|
||||||
|
[ [ [ - abs ] dip ^ ] curry 2map-sum ] keep recip ^ ;
|
||||||
|
|
||||||
|
: euclidian-distance ( a b -- n )
|
||||||
|
2 minkowski-distance ; ! also math.vectors.distance
|
||||||
|
|
||||||
|
: manhattan-distance ( a b -- n )
|
||||||
|
1 minkowski-distance ;
|
||||||
|
|
||||||
|
: chebyshev-distance ( a b -- n )
|
||||||
|
[ - abs ] 2map supremum ;
|
Loading…
Reference in New Issue