elbow 0.1.0.0 → 0.1.1.0
raw patch · 2 files changed
+22/−10 lines, 2 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Math.Elbow: Max :: MaxMin
+ Math.Elbow: Min :: MaxMin
+ Math.Elbow: data MaxMin
- Math.Elbow: findElbow :: (RealFloat a, Numeric a) => Matrix a -> Maybe (Int, (a, a))
+ Math.Elbow: findElbow :: (RealFloat a, Numeric a) => MaxMin -> Matrix a -> Maybe (Int, (a, a))
- Math.Elbow: findElbowList :: (RealFloat a, Numeric a) => [[a]] -> Maybe (Int, (a, a))
+ Math.Elbow: findElbowList :: (RealFloat a, Numeric a) => MaxMin -> [[a]] -> Maybe (Int, (a, a))
Files
- elbow.cabal +1/−1
- src/Math/Elbow.hs +21/−9
elbow.cabal view
@@ -1,5 +1,5 @@ name: elbow-version: 0.1.0.0+version: 0.1.1.0 synopsis: Find the elbow point. description: Use rotations to identify the elbow point of a two-dimensional long-tailed distribution. homepage: http://github.com/GregorySchwartz/elbow#readme
src/Math/Elbow.hs view
@@ -10,6 +10,7 @@ ( findElbow , findElbowList , getRotationAngle+ , MaxMin (..) ) where -- Remote@@ -18,6 +19,9 @@ -- Local ++data MaxMin = Max | Min+ -- | Convert a list to a tuple. listToTuple :: [a] -> Maybe (a, a) listToTuple [x, y] = Just (x, y)@@ -32,22 +36,30 @@ . fmap (\x -> H.maxElement x - H.minElement x) . H.toColumns --- | Get the elbow point (and its index) of a two-dimensional distribution.--- Matrix rows are observations, columns are dimensions.-findElbow :: (RealFloat a, H.Numeric a) => H.Matrix a -> Maybe (Int, (a, a))-findElbow m = do+-- | Get the elbow point (and its index) of a two-dimensional distribution. Uses+-- the Max or Min to identify convex / concave point, depending on the choice+-- (for positive x and y, top left hump would be Max, bottom right dip would be+-- Min). Matrix rows are observations, columns are dimensions.+findElbow :: (RealFloat a, H.Numeric a)+ => MaxMin -> H.Matrix a -> Maybe (Int, (a, a))+findElbow maxMin m = do theta <- getRotationAngle m let co = cos theta si = sin theta rot = (2 H.>< 2) [co, -si, si, co] rotated = m H.<> rot+ findMaxMin Max = H.maxIndex+ findMaxMin Min = H.minIndex - idx <- fmap H.minIndex . flip atMay 1 . H.toColumns $ rotated+ idx <- fmap (findMaxMin maxMin) . flip atMay 1 . H.toColumns $ rotated fmap (idx,) . listToTuple . H.toList $ m H.! idx --- | Get the elbow point (and its index) of a two-dimensional distribution.--- Matrix rows are observations, columns are dimensions. List of columns.-findElbowList :: (RealFloat a, H.Numeric a) => [[a]] -> Maybe (Int, (a, a))-findElbowList = findElbow . H.fromColumns . fmap H.fromList+-- | Get the elbow point (and its index) of a two-dimensional distribution. Uses+-- the Max or Min to identify convex / concave point, depending on the choice+-- (for positive x and y, top left hump would be Max, bottom right dip would be+-- Min). Matrix rows are observations, columns are dimensions. List of columns.+findElbowList :: (RealFloat a, H.Numeric a)+ => MaxMin -> [[a]] -> Maybe (Int, (a, a))+findElbowList maxMin = findElbow maxMin . H.fromColumns . fmap H.fromList