math: using ``v.`` instead of ``v* sum`` in a few places.

factor-shell
John Benediktsson 2017-10-24 12:26:39 -07:00
parent 37902e3903
commit aa5623eede
6 changed files with 10 additions and 10 deletions

View File

@ -36,7 +36,7 @@ ALIAS: n*p n*v
[ drop length [ <iota> ] keep ]
[ nip <reversed> ]
[ drop ] 2tri
'[ _ _ <slice> _ v* sum ] map reverse! ;
'[ _ _ <slice> _ v. ] map reverse! ;
: p-sq ( p -- p^2 ) dup p* ; inline

View File

@ -208,10 +208,10 @@ ERROR: shaped-bounds-error seq shape ;
! Inefficient
: calculate-row-major-index ( seq shape -- i )
1 [ * ] accumulate nip reverse v* sum ;
1 [ * ] accumulate nip reverse v. ;
: calculate-column-major-index ( seq shape -- i )
1 [ * ] accumulate nip v* sum ;
1 [ * ] accumulate nip v. ;
: set-shaped-row-major ( obj seq shaped -- )
shaped-bounds-check [ shape calculate-row-major-index ] [ underlying>> ] bi set-nth ;

View File

@ -65,7 +65,7 @@ sharp-continue ;
:: project-pt-line ( p p0 p1 -- q )
p1 p0 v- :> vt
p p0 v- vt v* sum
p p0 v- vt v.
vt norm-sq /
vt n*v p0 v+ ; inline

View File

@ -191,7 +191,7 @@ GML: aNormal ( x -- y )
} cond ;
: det2 ( x y -- z )
{ 1 0 } vshuffle double-2{ 1 -1 } v* v* sum ; inline
{ 1 0 } vshuffle double-2{ 1 -1 } v* v. ; inline
: det3 ( x y z -- w )
[ cross ] dip v. ; inline

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.statistics math.vectors
sequences sequences.extras ;
USING: kernel math math.functions math.similarity
math.statistics math.vectors sequences sequences.extras ;
IN: math.distances
@ -22,7 +22,7 @@ IN: math.distances
v- vabs supremum ;
: cosine-distance ( a b -- n )
[ v* sum ] [ [ norm ] bi@ * ] 2bi / 1 swap - ;
cosine-similarity 1 swap - ;
: canberra-distance ( a b -- n )
[ v- vabs ] [ [ vabs ] bi@ v+ ] 2bi v/ sum ;
@ -31,4 +31,4 @@ IN: math.distances
[ v- ] [ v+ ] 2bi [ vabs sum ] bi@ / ;
: correlation-distance ( a b -- n )
[ demean ] bi@ [ v* sum ] [ [ norm ] bi@ * ] 2bi / 1 swap - ;
[ demean ] bi@ cosine-distance ;

View File

@ -12,4 +12,4 @@ IN: math.similarity
over length 3 < [ 2drop 1.0 ] [ population-corr 0.5 * 0.5 + ] if ;
: cosine-similarity ( a b -- n )
[ v* sum ] [ [ norm ] bi@ * ] 2bi / ;
[ v. ] [ [ norm ] bi@ * ] 2bi / ;