math.distances: adding some distance functions.

db4
John Benediktsson 2012-05-03 13:38:59 -07:00
parent 95b82eecfa
commit af8f23a78c
3 changed files with 30 additions and 0 deletions

View File

@ -0,0 +1 @@
John Benediktsson

View File

@ -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

View File

@ -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 ;