Commit 3b5169dd authored by Alexandre Delanoë's avatar Alexandre Delanoë

[STASH] back to old work

parent 797ae29e
...@@ -22,7 +22,6 @@ import Test.Hspec ...@@ -22,7 +22,6 @@ import Test.Hspec
import Data.HashMap.Strict (HashMap) import Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as HashMap import qualified Data.HashMap.Strict as HashMap
import qualified Data.List as List import qualified Data.List as List
import Gargantext.Core.Viz.Graph.Tools (PartitionMethod(..))
import Gargantext.Core.Viz.Graph.Tools.IGraph (spinglass) import Gargantext.Core.Viz.Graph.Tools.IGraph (spinglass)
import Gargantext.Core.Methods.Similarities (Similarity(..)) import Gargantext.Core.Methods.Similarities (Similarity(..))
......
...@@ -26,8 +26,6 @@ import Gargantext.Prelude ...@@ -26,8 +26,6 @@ import Gargantext.Prelude
import Graph.Types (ClusterNode(..)) import Graph.Types (ClusterNode(..))
import qualified Data.Map as DM import qualified Data.Map as DM
---------------------------------------------------------------------- ----------------------------------------------------------------------
type Partitions a = Map (Int, Int) Double -> IO [a] type Partitions a = Map (Int, Int) Double -> IO [a]
---------------------------------------------------------------------- ----------------------------------------------------------------------
...@@ -45,23 +43,23 @@ instance ToComId ClusterNode where ...@@ -45,23 +43,23 @@ instance ToComId ClusterNode where
---------------------------------------------------------------------- ----------------------------------------------------------------------
type Bridgeness = Double type Bridgeness = Double
bridgeness :: ToComId a => Bridgeness bridgeness :: ToComId a
=> Bridgeness
-> [a] -> [a]
-> Map (NodeId, NodeId) Double -> Map (NodeId, NodeId) Double
-> Map (NodeId, NodeId) Double -> Map (NodeId, NodeId) Double
bridgeness = bridgeness' nodeId2comId bridgeness = bridgenessWith nodeId2comId
where
bridgenessWith :: (a -> (Int, Int))
bridgeness' :: (a -> (Int, Int)) -> Bridgeness
-> Bridgeness -> [a]
-> [a] -> Map (Int, Int) Double
-> Map (Int, Int) Double -> Map (Int, Int) Double
-> Map (Int, Int) Double bridgenessWith f b ns = DM.fromList
bridgeness' f b ns = DM.fromList . concat
. concat . DM.elems
. DM.elems . filterComs b
. filterComs b . groupEdges (DM.fromList $ map f ns)
. groupEdges (DM.fromList $ map f ns)
groupEdges :: (Ord a, Ord b1) groupEdges :: (Ord a, Ord b1)
...@@ -71,7 +69,7 @@ groupEdges :: (Ord a, Ord b1) ...@@ -71,7 +69,7 @@ groupEdges :: (Ord a, Ord b1)
groupEdges m = fromListWith (<>) groupEdges m = fromListWith (<>)
. catMaybes . catMaybes
. map (\((n1,n2), d) . map (\((n1,n2), d)
-> let -> let
n1n2_m = (,) <$> lookup n1 m <*> lookup n2 m n1n2_m = (,) <$> lookup n1 m <*> lookup n2 m
n1n2_d = Just [((n1,n2),d)] n1n2_d = Just [((n1,n2),d)]
in (,) <$> n1n2_m <*> n1n2_d in (,) <$> n1n2_m <*> n1n2_d
...@@ -79,7 +77,7 @@ groupEdges m = fromListWith (<>) ...@@ -79,7 +77,7 @@ groupEdges m = fromListWith (<>)
. toList . toList
-- | TODO : sortOn Confluence -- | TODO : sortOn Confluence
filterComs :: (Ord n1, Eq n2) filterComs :: (Ord n1, Eq n2)
=> p => p
-> Map (n2, n2) [(a3, n1)] -> Map (n2, n2) [(a3, n1)]
-> Map (n2, n2) [(a3, n1)] -> Map (n2, n2) [(a3, n1)]
...@@ -95,3 +93,22 @@ filterComs _b m = DM.filter (\n -> length n > 0) $ mapWithKey filter' m ...@@ -95,3 +93,22 @@ filterComs _b m = DM.filter (\n -> length n > 0) $ mapWithKey filter' m
a'= fromIntegral $ length a a'= fromIntegral $ length a
t :: Double t :: Double
t = fromIntegral $ length $ concat $ elems m t = fromIntegral $ length $ concat $ elems m
--------------------------------------------------------------
{--
Compute the median of a list
From: https://hackage.haskell.org/package/dsp-0.2.5.1/docs/src/Numeric.Statistics.Median.html
Compute the center of the list in a more lazy manner
and thus halves memory requirement.
-}
median :: (Ord a, Fractional a) => [a] -> a
median [] = panic "medianFast: empty list has no median"
median zs =
let recurse (x0:_) (_:[]) = x0
recurse (x0:x1:_) (_:_:[]) = (x0+x1)/2
recurse (_:xs) (_:_:ys) = recurse xs ys
recurse _ _ =
panic "median: this error cannot occur in the way 'recurse' is called"
in recurse zs zs
...@@ -97,7 +97,8 @@ cooc2graphWith :: PartitionMethod ...@@ -97,7 +97,8 @@ cooc2graphWith :: PartitionMethod
-> IO Graph -> IO Graph
cooc2graphWith Spinglass = cooc2graphWith' (spinglass 1) cooc2graphWith Spinglass = cooc2graphWith' (spinglass 1)
cooc2graphWith Confluence= cooc2graphWith' (\x -> pure $ BAC.defaultClustering x) cooc2graphWith Confluence= cooc2graphWith' (\x -> pure $ BAC.defaultClustering x)
cooc2graphWith Infomap = cooc2graphWith' (infomap "--silent --two-level -N2") cooc2graphWith Infomap = cooc2graphWith' (infomap "-v -N2")
--cooc2graphWith Infomap = cooc2graphWith' (infomap "--silent --two-level -N2")
-- TODO: change these options, or make them configurable in UI? -- TODO: change these options, or make them configurable in UI?
...@@ -132,8 +133,8 @@ cooc2graphWith' doPartitions multi similarity threshold strength myCooc = do ...@@ -132,8 +133,8 @@ cooc2graphWith' doPartitions multi similarity threshold strength myCooc = do
where where
(as, bs) = List.unzip $ Map.keys distanceMap (as, bs) = List.unzip $ Map.keys distanceMap
n' = Set.size $ Set.fromList $ as <> bs n' = Set.size $ Set.fromList $ as <> bs
!bridgeness' = bridgeness (fromIntegral nodesApprox) partitions distanceMap
!confluence' = BAC.computeConfluences 3 (Map.keys bridgeness') True !confluence' = BAC.computeConfluences 3 (Map.keys bridgeness') True
!bridgeness' = bridgeness (fromIntegral nodesApprox) partitions distanceMap
pure $ data2graph multi ti diag bridgeness' confluence' partitions pure $ data2graph multi ti diag bridgeness' confluence' partitions
type Reverse = Bool type Reverse = Bool
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment