Permalink
Browse files

My distance metric for vectors was stupid: let's try again

  • Loading branch information...
1 parent fdd4ac5 commit 994b028c82d30dc235f88a2fdab7b578d847478f @batterseapower committed Sep 12, 2008
Showing with 6 additions and 1 deletion.
  1. +2 −1 Algorithms/MachineLearning/Framework.hs
  2. +4 −0 Algorithms/MachineLearning/LinearAlgebra.hs
@@ -2,6 +2,7 @@
-- the machine learning algorithms.
module Algorithms.MachineLearning.Framework where
+import Algorithms.MachineLearning.LinearAlgebra
import Algorithms.MachineLearning.Utilities
import Numeric.LinearAlgebra
@@ -126,7 +127,7 @@ instance MetricSpace Double where
distance x y = abs (x - y)
instance MetricSpace (Vector Double) where
- distance = (<.>)
+ distance x y = vectorSumSquares (x - y)
--
-- Models
@@ -56,6 +56,10 @@ applyVector fns inputs = fromList $ map ($ inputs) fns
vectorSum :: Element a => Vector a -> a
vectorSum v = constant 1 (dim v) <.> v
+-- | The sum of the squares of the elements of the vector
+vectorSumSquares :: Element a => Vector a -> a
+vectorSumSquares v = v <.> v
+
-- | Mean of the elements in a vector.
vectorMean :: Element a => Vector a -> a
vectorMean v = (vectorSum v) / fromIntegral (dim v)

0 comments on commit 994b028

Please sign in to comment.