-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | High performance clustering algorithms -- @package clustering @version 0.2.0 -- | description starting at first column -- | Warning: To be used by developer only module AI.Clustering.KMeans.Internal forgy :: (PrimMonad m, Vector v a) => Gen (PrimState m) -> Int -> v a -> (a -> Vector Double) -> m (Matrix Double) kmeansPP :: (PrimMonad m, Vector v a) => Gen (PrimState m) -> Int -> v a -> (a -> Vector Double) -> m (Matrix Double) sumSquares :: Vector Double -> Vector Double -> Double -- | description starting at first column module AI.Clustering.KMeans.Types -- | Results from running kmeans data KMeans KMeans :: Vector Int -> Matrix Double -> KMeans -- | A vector of integers (0 ~ k-1) indicating the cluster to which each -- point is allocated. _clusters :: KMeans -> Vector Int -- | A matrix of cluster centers. _centers :: KMeans -> Matrix Double -- | Different initialization methods data Method -- | The Forgy method randomly chooses k unique observations from the data -- set and uses these as the initial means. Forgy :: Method -- | K-means++ algorithm. KMeansPP :: Method instance Show KMeans -- | Kmeans clustering module AI.Clustering.KMeans -- | Results from running kmeans data KMeans KMeans :: Vector Int -> Matrix Double -> KMeans -- | A vector of integers (0 ~ k-1) indicating the cluster to which each -- point is allocated. _clusters :: KMeans -> Vector Int -- | A matrix of cluster centers. _centers :: KMeans -> Matrix Double -- | Perform K-means clustering kmeans :: (PrimMonad m, Matrix mat Vector Double) => Gen (PrimState m) -> Method -> Int -> mat Vector Double -> m KMeans -- | K-means algorithm kmeansBy :: (PrimMonad m, Vector v a) => Gen (PrimState m) -> Method -> Int -> v a -> (a -> Vector Double) -> m KMeans -- | K-means algorithm kmeansWith :: Vector v a => Matrix Double -> v a -> (a -> Vector Double) -> KMeans -- | Different initialization methods data Method -- | The Forgy method randomly chooses k unique observations from the data -- set and uses these as the initial means. Forgy :: Method -- | K-means++ algorithm. KMeansPP :: Method -- | Assign data to clusters based on KMeans result decode :: KMeans -> [a] -> [[a]] -- | Compute within-cluster sum of squares withinSS :: KMeans -> Matrix Double -> [Double] module AI.Clustering.Hierarchical.Types type Distance = Double type DistFn a = a -> a -> Distance type Size = Int data Dendrogram a Leaf :: !a -> Dendrogram a Branch :: !Size -> !Distance -> !(Dendrogram a) -> !(Dendrogram a) -> Dendrogram a -- | O(1) Return the size of a dendrogram size :: Dendrogram a -> Int data DistanceMat DistanceMat :: !Int -> !(Vector Double) -> DistanceMat (!) :: DistanceMat -> (Int, Int) -> Double idx :: Int -> Int -> Int -> Int -- | compute distance matrix computeDists :: Vector v a => DistFn a -> v a -> DistanceMat -- | compute distance matrix in parallel computeDists' :: Vector v a => DistFn a -> v a -> DistanceMat instance Show a => Show (Dendrogram a) instance Eq a => Eq (Dendrogram a) instance Show DistanceMat instance Functor Dendrogram instance Binary a => Binary (Dendrogram a) -- | Warning: To be used by developer only module AI.Clustering.Hierarchical.Internal -- | nearest neighbor chain algorithm nnChain :: DistanceMat -> DistUpdateFn -> Dendrogram Int -- | all update functions perform destructive updates, and hence should not -- be called by end users -- -- single linkage update formula single :: DistUpdateFn -- | complete linkage update formula complete :: DistUpdateFn -- | average linkage update formula average :: DistUpdateFn -- | weighted linkage update formula weighted :: DistUpdateFn -- | ward linkage update formula ward :: DistUpdateFn -- | High performance agglomerative hierarchical clustering library. -- Example: -- --
--   >>> :set -XOverloadedLists
--   
--   >>> import qualified Data.Vector as V
--   
--   >>> let points = [[2, 3, 4], [2, 1, 2], [2, 1, 6], [2, 4, 6], [5, 1, 2]] :: V.Vector (V.Vector Double)
--   
--   >>> let dendro = hclust Average points euclidean
--   
--   >>> print dendro
--   Branch 5 4.463747440868191 (Branch 3 2.914213562373095 (Leaf (fromList [2.0,1.0,6.0]))
--   (Branch 2 2.23606797749979 (Leaf (fromList [2.0,3.0,4.0])) (Leaf (fromList [2.0,4.0,6.0]))))
--   (Branch 2 3.0 (Leaf (fromList [2.0,1.0,2.0])) (Leaf (fromList [5.0,1.0,2.0])))
--   
--   >>> putStr $ drawDendrogram $ fmap show dendro
--   h: 4.4637
--   |
--   +- h: 2.9142
--   |  |
--   |  +- fromList [2.0,1.0,6.0]
--   |  |
--   |  `- h: 2.2361
--   |     |
--   |     +- fromList [2.0,3.0,4.0]
--   |     |
--   |     `- fromList [2.0,4.0,6.0]
--   |
--   `- h: 3.0000
--      |
--      +- fromList [2.0,1.0,2.0]
--      |
--      `- fromList [5.0,1.0,2.0]
--   
module AI.Clustering.Hierarchical data Dendrogram a Leaf :: !a -> Dendrogram a Branch :: !Size -> !Distance -> !(Dendrogram a) -> !(Dendrogram a) -> Dendrogram a -- | O(1) Return the size of a dendrogram size :: Dendrogram a -> Int -- | Different hierarchical clustering schemes. data Linkage -- | O(n^2) Single linkage, $d(A,B) = min_{a in A, b in B} d(a,b)$. Single :: Linkage -- | O(n^2) Complete linkage, $d(A,B) = max_{a in A, b in B} d(a,b)$. Complete :: Linkage -- | O(n^2) Average linkage or UPGMA, $d(A,B) = frac{sum_{a in A}sum_{b in -- B}d(a,b)}{|A||B|}$. Average :: Linkage -- | O(n^2) Weighted linkage. Weighted :: Linkage -- | O(n^2) Ward's method. Ward :: Linkage -- | O(n^3) Centroid linkage, not implemented. Centroid :: Linkage -- | O(n^3) Median linkage, not implemented. Median :: Linkage -- | Perform hierarchical clustering. hclust :: Vector v a => Linkage -> v a -> DistFn a -> Dendrogram a -- | Cut a dendrogram at given height. cutAt :: Dendrogram a -> Distance -> [Dendrogram a] -- | Return the elements of a dendrogram in pre-order. flatten :: Dendrogram a -> [a] -- | 2-dimensional drawing of a dendrogram drawDendrogram :: Dendrogram String -> String -- | Compute euclidean distance between two points. euclidean :: Vector v Double => DistFn (v Double) -- | Hamming distance. hamming :: (Vector v a, Vector v Bool, Eq a) => DistFn (v a)