math.distances: adding correlation-distance.

db4
John Benediktsson 2012-05-03 15:52:28 -07:00
parent d3d109aa3e
commit 3c3ad89a22
2 changed files with 9 additions and 2 deletions

View File

@ -14,3 +14,7 @@ IN: math.distances.tests
{ 143/105 } [ { 1 2 3 } { 4 5 6 } canberra-distance ] unit-test
{ 3/7 } [ { 1 2 3 } { 4 5 6 } bray-curtis-distance ] unit-test
{ t } [ { 1 2 3 } dup correlation-distance 0.0 1e-10 ~ ] unit-test
{ t } [ { 1 2 3 } { 1 2 1 } correlation-distance 1.0 1e-10 ~ ] unit-test
{ t } [ { 1 2 3 } { 3 2 1 } correlation-distance 2.0 1e-10 ~ ] unit-test

View File

@ -1,8 +1,8 @@
! Copyright (C) 2012 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
USING: kernel math math.functions math.vectors sequences
sequences.extras ;
USING: kernel math math.functions math.statistics math.vectors
sequences sequences.extras ;
IN: math.distances
@ -29,3 +29,6 @@ IN: math.distances
: bray-curtis-distance ( a b -- n )
[ v- ] [ v+ ] 2bi [ vabs sum ] bi@ / ;
: correlation-distance ( a b -- n )
[ dup mean v-n ] bi@ [ v* sum ] [ [ norm ] bi@ * ] 2bi / 1 swap - ;