Last active
April 14, 2017 13:56
-
-
Save yuanw/bca233bc8e393abc6b8e91e8a6f20092 to your computer and use it in GitHub Desktop.
Beginning Haskell Chapter 6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Data.List | |
| import qualified Data.Map as M | |
| -- Data.List.minimumBy :: Foldable t => (a -> a -> Ordering) -> t a -> a -- | |
| -- M.adjust :: Ord k => (a -> a) -> k -> Map k a -> Map k a -- | |
| clusterAssignmentPhase :: (Vector v, Vectorizable e v) => [v] -> [e] -> M.Map v [e] | |
| clusterAssignmentPhase centroids points = | |
| let initialMap = M.fromList $ zip centroids (repeat []) | |
| in foldr (\p m -> let chosenCentroid = minimumBy (\x y -> compare (distance x $ toVector p) | |
| (distance y $ toVector p)) | |
| centroids | |
| in M.adjust (p:) chosenCentroid m) | |
| initialMap points |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment