spectral-clustering 0.2.2.0 → 0.2.2.2
raw patch · 5 files changed
+16/−15 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- spectral-clustering.cabal +1/−1
- src/Math/Clustering/Spectral/Dense.hs +7/−7
- src/Math/Clustering/Spectral/Eigen/AdjacencyMatrix.hs +3/−3
- src/Math/Clustering/Spectral/Eigen/FeatureMatrix.hs +2/−2
- src/Math/Clustering/Spectral/Sparse.hs +3/−2
spectral-clustering.cabal view
@@ -1,6 +1,6 @@ cabal-version: >=1.10 name: spectral-clustering-version: 0.2.2.0+version: 0.2.2.2 license: GPL-3 license-file: LICENSE copyright: 2019 Gregory W. Schwartz
src/Math/Clustering/Spectral/Dense.hs view
@@ -79,7 +79,7 @@ b1ToB2 :: B1 -> B2 b1ToB2 (B1 b1) = B2- . cimap (\ !i !j !x -> (log (fromIntegral n / (fromMaybe 0 $ dVec VS.!? j))) * x)+ . cimap (\ !i !j !x -> (log (fromIntegral n / (fromMaybe (error "Missing degree for observation. This would lead to divide by 0 error.") $ dVec VS.!? j))) * x) $ b1 where dVec :: H.Vector Double@@ -93,20 +93,20 @@ -- | Euclidean norm each row. b2ToB :: B2 -> B b2ToB (B2 b2) =- B . cimap (\ !i !j !x -> x / (fromMaybe 0 $ eVec VS.!? i)) $ b2+ B . cimap (\ !i !j !x -> x / (fromMaybe (error "Missing degree for observation. This would lead to divide by 0 error.") $ eVec VS.!? i)) $ b2 where eVec :: H.Vector Double eVec = H.fromList . fmap H.norm_2 . H.toRows $ b2 n = H.rows b2 m = H.cols b2 --- | Get the diagonal transformed B matrix.+-- | Get the signed diagonal transformed B matrix. bToD :: B -> D bToD (B b) = D . H.diag . H.flatten $ b- H.<> ((H.tr b) H.<> ((n H.>< 1) [1,1..]))+ H.<> ((H.cmap abs $ H.tr b) H.<> ((n H.>< 1) [1,1..])) where n = H.rows b @@ -237,10 +237,10 @@ $ mat i = H.ident . H.rows $ mat --- | Obtain the degree matrix.+-- | Obtain the signed degree matrix. getDegreeMatrix :: AdjacencyMatrix -> H.Matrix Double getDegreeMatrix = H.diag . getDegreeVector --- | Obtain the degree vector.+-- | Obtain the signed degree vector. getDegreeVector :: AdjacencyMatrix -> H.Vector Double-getDegreeVector = H.vector . fmap H.sumElements . H.toRows+getDegreeVector = H.vector . fmap (H.sumElements . H.cmap abs) . H.toRows
src/Math/Clustering/Spectral/Eigen/AdjacencyMatrix.hs view
@@ -173,10 +173,10 @@ . S.toList $ m --- | Obtain the degree matrix. Faster for columns.+-- | Obtain the signed degree matrix. Faster for columns. getDegreeMatrix :: AdjacencyMatrix -> S.SparseMatrixXd getDegreeMatrix = S.diagRow 0 . getDegreeVector --- | Obtain the degree vector. Faster for columns.+-- | Obtain the signed degree vector. Faster for columns. getDegreeVector :: AdjacencyMatrix -> S.SparseMatrixXd-getDegreeVector = S.getColSums+getDegreeVector = S.getColSums . S._map abs
src/Math/Clustering/Spectral/Eigen/FeatureMatrix.hs view
@@ -77,9 +77,9 @@ eVec :: VS.Vector Double eVec = VS.fromList . fmap S.norm . S.getRows $ b2 --- | Get the diagonal transformed B matrix.+-- | Get the signed diagonal transformed B matrix. bToD :: B -> D-bToD (B b) = D . S.diagCol 0 $ b * ((S.transpose b) * S.ones n)+bToD (B b) = D . S.diagCol 0 $ b * ((S._map abs $ S.transpose b) * S.ones n) where n = S.rows b
src/Math/Clustering/Spectral/Sparse.hs view
@@ -95,13 +95,13 @@ norm2 :: S.SpVector Double -> Double norm2 = sqrt . sum . fmap (** 2) --- | Get the diagonal transformed B matrix.+-- | Get the signed diagonal transformed B matrix. bToD :: B -> D bToD (B b) = D . S.diagonalSM . flip S.extractCol 0 $ b- S.#~# ((S.transposeSM b) S.#~# (S.fromColsL [S.onesSV n]))+ S.#~# ((fmap abs $ S.transposeSM b) S.#~# (S.fromColsL [S.onesSV n])) where n = S.nrows b @@ -202,6 +202,7 @@ . S.vr . fmap ((\x -> if x == 0 then x else x ** (- 1 / 2)) . sum) . S.toRowsL+ . fmap abs -- signed diagonal $ mat i = S.eye . S.nrows $ mat