1 ! Copyright (C) 2012 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
4 USING: kernel math math.functions math.statistics math.vectors
5 sequences sequences.extras ;
9 : euclidian-similarity ( a b -- n )
12 : pearson-similarity ( a b -- n )
13 over length 3 < [ 2drop 1.0 ] [ population-corr 0.5 * 0.5 + ] if ;
15 : cosine-similarity ( a b -- n )
16 [ v. ] [ [ norm ] bi@ * ] 2bi / ;
20 : weighted-v. ( w a b -- n )
21 [ * * ] [ + ] 3map-reduce ;
23 : weighted-norm ( w a -- n )
24 [ absq * ] [ + ] 2map-reduce ;
28 : weighted-cosine-similarity ( w a b -- n )
30 [ [ over ] dip [ weighted-norm ] 2bi@ * ] 3bi / ;