packages feed

hierarchical-clustering 0.3.0.1 → 0.3.1

raw patch · 3 files changed

+28/−17 lines, 3 filesdep ~containersPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: containers

API changes (from Hackage documentation)

- Data.Clustering.Hierarchical.Internal.DistanceMatrix: type ClusterDistance d = Cluster -> (Cluster, d) -> (Cluster, d) -> Cluster -> d
+ Data.Clustering.Hierarchical.Internal.DistanceMatrix: type ClusterDistance d = (Cluster, d) -> (Cluster, d) -> d

Files

Data/Clustering/Hierarchical.hs view
@@ -133,19 +133,19 @@  -- Some cluster distances cdistSingleLinkage      :: Ord d => ClusterDistance d-cdistSingleLinkage      = \_ (_, d1) (_, d2) _ -> d1 `min` d2+cdistSingleLinkage      = \(_, d1) (_, d2) -> d1 `min` d2  cdistCompleteLinkage    :: Ord d => ClusterDistance d-cdistCompleteLinkage    = \_ (_, d1) (_, d2) _ -> d1 `max` d2+cdistCompleteLinkage    = \(_, d1) (_, d2) -> d1 `max` d2  cdistUPGMA              :: Fractional d => ClusterDistance d-cdistUPGMA              = \_ (b1,d1) (b2,d2) _ ->+cdistUPGMA              = \(b1,d1) (b2,d2) ->                             let n1 = fromIntegral (size b1)                                 n2 = fromIntegral (size b2)                             in (n1 * d1 + n2 * d2) / (n1 + n2)  cdistFakeAverageLinkage :: Fractional d => ClusterDistance d-cdistFakeAverageLinkage = \_ (_, d1) (_, d2) _ -> (d1 + d2) / 2+cdistFakeAverageLinkage = \(_, d1) (_, d2) -> (d1 + d2) / 2   -- | /O(n^3)/ Calculates a complete, rooted dendrogram for a list@@ -200,18 +200,18 @@       act _noMonomorphismRestrictionPlease = do         let xs = listArray (1, n) items         fromDistance (dist `on` (xs !)) n >>= go xs (n-1) IM.empty-      go xs i ds dm = do+      go xs i ds dm = xs `seq` i `seq` ds `seq` dm `seq` do         ((c1,c2), distance) <- findMin dm         cu <- mergeClusters cdist dm (c1,c2)         let dendro c = case size c of-                         1 -> Leaf (xs ! key c)+                         1 -> Leaf $! xs ! key c                          _ -> ds IM.! key c             d1 = dendro c1             d2 = dendro c2-            du = Branch distance d1 d2+            du = d1 `seq` d2 `seq` Branch distance d1 d2         case i of           1 -> return du           _ -> let ds' = IM.insert (key cu) du $                          IM.delete (key c1) $                          IM.delete (key c2) ds-               in go xs (i-1) ds' dm+               in du `seq` go xs (i-1) ds' dm
Data/Clustering/Hierarchical/Internal/DistanceMatrix.hs view
@@ -86,6 +86,7 @@       choose b i m' = if m' < snd b then (i, m') else b       go1 (i:is)   = readArray matrix_ i >>= go2 is . (,) i       go1 []       = mkErr "findMin: empty DistMatrix"+      go2 i b | i `seq` b `seq` False = undefined       go2 (i:is) b = readArray matrix_ i >>= go2 is . choose b i       go2 []     b = do c1 <- readArray (clusters dm) (fst $ fst b)                         c2 <- readArray (clusters dm) (snd $ fst b)@@ -95,11 +96,9 @@ -- | Type for functions that calculate distances between -- clusters. type ClusterDistance d =-       Cluster        -- ^ Cluster A-    -> (Cluster, d)   -- ^ Cluster B1 and distance from A to B1+       (Cluster, d)   -- ^ Cluster B1 and distance from A to B1     -> (Cluster, d)   -- ^ Cluster B2 and distance from A to B2-    -> Cluster        -- ^ Cluster B = B1 U B2-    -> d              -- ^ Distance from A to B.+    -> d              -- ^ Distance from A to (B1 U B2).   -- | /O(n)/ Merges two clusters, returning the new cluster and@@ -120,11 +119,11 @@   -- Calculate new distances   activeV <- readSTRef active_   forM_ activeV $ \k -> when (k `notElem` [b1k, b2k]) $ do-      a      <- readArray clusters_ k+      -- a   <- readArray clusters_ k       d_a_b1 <- readArray matrix_ $ ix k b1k       d_a_b2 <- readArray matrix_ $ ix k b2k-      let d = cdist a (b1, d_a_b1) (b2, d_a_b2) bu-      writeArray matrix_ (ix k km) d+      let d = cdist (b1, d_a_b1) (b2, d_a_b2)+      d `seq` writeArray matrix_ (ix k km) d    -- Save new cluster, invalidate old one   writeArray clusters_ km bu
hierarchical-clustering.cabal view
@@ -1,5 +1,5 @@ Name:                hierarchical-clustering-Version:             0.3.0.1+Version:             0.3.1 Synopsis:            Algorithms for single, average/UPGMA and complete linkage clustering. License:             BSD3 License-file:        LICENSE@@ -25,6 +25,12 @@   the whole matrix on every iteration just to see what the   minimum is).   .+  Changes in version 0.3.1:+  .+  * Works with containers 0.4 (thanks, Doug Beardsley).+  .+  * Removed some internal unnecessary overheads and added some strictness.+  .   Changes in version 0.3.0.1:   .   * Listed changes of unreleased version 0.2.@@ -43,9 +49,15 @@     useful if you want to create a dendrogram and your distance     data type isn't an instance of @Floating@. ++Source-repository head+  type: darcs+  location: http://patch-tag.com/r/felipe/hierarchical-clustering++ Library   Exposed-modules:     Data.Clustering.Hierarchical,     Data.Clustering.Hierarchical.Internal.DistanceMatrix-  Build-depends: base == 4.*, array == 0.3.*, containers == 0.3.*+  Build-depends: base == 4.*, array == 0.3.*, containers >= 0.3 && < 0.5   GHC-options: -Wall