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

[STASH] back to old work

parent 797ae29e
......@@ -22,7 +22,6 @@ import Test.Hspec
import Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as HashMap
import qualified Data.List as List
import Gargantext.Core.Viz.Graph.Tools (PartitionMethod(..))
import Gargantext.Core.Viz.Graph.Tools.IGraph (spinglass)
import Gargantext.Core.Methods.Similarities (Similarity(..))
......
......@@ -26,8 +26,6 @@ import Gargantext.Prelude
import Graph.Types (ClusterNode(..))
import qualified Data.Map as DM
----------------------------------------------------------------------
type Partitions a = Map (Int, Int) Double -> IO [a]
----------------------------------------------------------------------
......@@ -45,19 +43,19 @@ instance ToComId ClusterNode where
----------------------------------------------------------------------
type Bridgeness = Double
bridgeness :: ToComId a => Bridgeness
bridgeness :: ToComId a
=> Bridgeness
-> [a]
-> Map (NodeId, NodeId) Double
-> Map (NodeId, NodeId) Double
bridgeness = bridgeness' nodeId2comId
bridgeness' :: (a -> (Int, Int))
bridgeness = bridgenessWith nodeId2comId
where
bridgenessWith :: (a -> (Int, Int))
-> Bridgeness
-> [a]
-> Map (Int, Int) Double
-> Map (Int, Int) Double
bridgeness' f b ns = DM.fromList
bridgenessWith f b ns = DM.fromList
. concat
. DM.elems
. filterComs b
......@@ -95,3 +93,22 @@ filterComs _b m = DM.filter (\n -> length n > 0) $ mapWithKey filter' m
a'= fromIntegral $ length a
t :: Double
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
-> IO Graph
cooc2graphWith Spinglass = cooc2graphWith' (spinglass 1)
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?
......@@ -132,8 +133,8 @@ cooc2graphWith' doPartitions multi similarity threshold strength myCooc = do
where
(as, bs) = List.unzip $ Map.keys distanceMap
n' = Set.size $ Set.fromList $ as <> bs
!bridgeness' = bridgeness (fromIntegral nodesApprox) partitions distanceMap
!confluence' = BAC.computeConfluences 3 (Map.keys bridgeness') True
!bridgeness' = bridgeness (fromIntegral nodesApprox) partitions distanceMap
pure $ data2graph multi ti diag bridgeness' confluence' partitions
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