Commit ca99d1c1 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[WIP] Bridgeness with Confluence, ok for order 1, order 2 needs more work

parent be6461cb
...@@ -19,16 +19,18 @@ TODO use Map LouvainNodeId (Map LouvainNodeId) ...@@ -19,16 +19,18 @@ TODO use Map LouvainNodeId (Map LouvainNodeId)
module Gargantext.Core.Viz.Graph.Bridgeness -- (bridgeness) module Gargantext.Core.Viz.Graph.Bridgeness -- (bridgeness)
where where
import Debug.Trace (trace) import Gargantext.Core.Methods.Similarities (Similarity(..))
import Data.IntMap (IntMap)
import Data.Map (Map, fromListWith, lookup, toList, mapWithKey, elems) import Data.Map (Map, fromListWith, lookup, toList, mapWithKey, elems)
import Data.Maybe (catMaybes) import Data.Maybe (catMaybes)
import Data.Ord (Down(..))
import Debug.Trace (trace)
import Gargantext.Prelude import Gargantext.Prelude
import Graph.Types (ClusterNode(..)) import Graph.Types (ClusterNode(..))
import Data.Ord (Down(..))
import Data.IntMap (IntMap)
import qualified Data.IntMap as IntMap import qualified Data.IntMap as IntMap
import qualified Data.List as List import qualified Data.List as List
import qualified Data.Map as Map import qualified Data.Map as Map
import qualified Data.Set as Set
---------------------------------------------------------------------- ----------------------------------------------------------------------
type Partitions a = Map (Int, Int) Double -> IO [a] type Partitions a = Map (Int, Int) Double -> IO [a]
...@@ -49,12 +51,13 @@ type Bridgeness = Double ...@@ -49,12 +51,13 @@ type Bridgeness = Double
type Confluence = Map (NodeId, NodeId) Double type Confluence = Map (NodeId, NodeId) Double
bridgeness3 :: Confluence bridgeness3 :: Similarity
-> Confluence
-> Map (NodeId, NodeId) Double -> Map (NodeId, NodeId) Double
-> Map (NodeId, NodeId) Double -> Map (NodeId, NodeId) Double
bridgeness3 c m = Map.fromList bridgeness3 sim c m = Map.fromList
$ map (\(ks, (v1,_v2)) -> (ks,v1)) $ map (\(ks, (v1,_v2)) -> (ks,v1))
$ List.take n $ List.take (if sim == Conditional then 2*n else 4*n)
$ List.sortOn (Down . (snd . snd)) $ List.sortOn (Down . (snd . snd))
$ Map.toList $ Map.toList
$ trace ("bridgeness3 m c" <> show (m,c)) $ Map.intersectionWithKey (\k v1 v2 -> trace ("intersectionWithKey " <> (show (k, v1, v2))) (v1, v2)) m c $ trace ("bridgeness3 m c" <> show (m,c)) $ Map.intersectionWithKey (\k v1 v2 -> trace ("intersectionWithKey " <> (show (k, v1, v2))) (v1, v2)) m c
...@@ -63,7 +66,12 @@ bridgeness3 c m = Map.fromList ...@@ -63,7 +66,12 @@ bridgeness3 c m = Map.fromList
n :: Int n :: Int
!n = trace ("bridgeness m size: " <> (show $ List.length m')) !n = trace ("bridgeness m size: " <> (show $ List.length m'))
$ round $ round
$ (fromIntegral $ List.length m') / (50 :: Double) $ (fromIntegral $ List.length m') / (log $ fromIntegral nodesNumber :: Double)
nodesNumber :: Int
nodesNumber = Set.size $ Set.fromList $ as <> bs
where
(as, bs) = List.unzip $ Map.keys m
map2intMap :: Map (Int, Int) a -> IntMap (IntMap a) map2intMap :: Map (Int, Int) a -> IntMap (IntMap a)
...@@ -82,13 +90,6 @@ look (k1,k2) m = if k1 < k2 ...@@ -82,13 +90,6 @@ look (k1,k2) m = if k1 < k2
else look (k2,k1) m else look (k2,k1) m
{-
n :: Int
n = Set.size $ Set.fromList $ as <> bs
where
(as, bs) = List.unzip $ Map.keys m
-}
bridgeness :: ToComId a bridgeness :: ToComId a
=> Confluence => Confluence
-> [a] -> [a]
......
...@@ -14,7 +14,6 @@ Portability : POSIX ...@@ -14,7 +14,6 @@ Portability : POSIX
module Gargantext.Core.Viz.Graph.Tools module Gargantext.Core.Viz.Graph.Tools
where where
import Debug.Trace (trace)
import Data.Aeson import Data.Aeson
import Data.HashMap.Strict (HashMap) import Data.HashMap.Strict (HashMap)
import Data.Map (Map) import Data.Map (Map)
...@@ -131,7 +130,7 @@ cooc2graphWith' doPartitions multi similarity threshold strength myCooc = do ...@@ -131,7 +130,7 @@ cooc2graphWith' doPartitions multi similarity threshold strength myCooc = do
let let
!confluence' = BAC.computeConfluences 3 (Map.keys distanceMap) True !confluence' = BAC.computeConfluences 3 (Map.keys distanceMap) True
!bridgeness' = trace ("bridgeness3 in tools" <> show (confluence', distanceMap)) $ bridgeness3 confluence' distanceMap !bridgeness' = bridgeness3 similarity confluence' distanceMap
pure $ data2graph multi ti diag bridgeness' confluence' partitions pure $ data2graph multi ti diag bridgeness' confluence' partitions
......
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