Commit ec76f8f5 authored by david Chavalarias's avatar david Chavalarias

Merge branch 'dev-phylo' of...

Merge branch 'dev-phylo' of ssh://gitlab.iscpif.fr:20022/gargantext/haskell-gargantext into dev-phylo
parents 01f84708 e78b322d
Pipeline #1361 failed with stage
...@@ -166,7 +166,7 @@ main = do ...@@ -166,7 +166,7 @@ main = do
let clq = case (clique config) of let clq = case (clique config) of
Fis s s' -> "fis_" <> (show s) <> "_" <> (show s') Fis s s' -> "fis_" <> (show s) <> "_" <> (show s')
MaxClique s -> "clique_" <> (show s) MaxClique s _ _ -> "clique_" <> (show s)
let sensibility = case (phyloProximity config) of let sensibility = case (phyloProximity config) of
Hamming -> undefined Hamming -> undefined
......
...@@ -108,13 +108,16 @@ data TimeUnit = ...@@ -108,13 +108,16 @@ data TimeUnit =
, _year_matchingFrame :: Int } , _year_matchingFrame :: Int }
deriving (Show,Generic,Eq) deriving (Show,Generic,Eq)
data CliqueFilter = ByThreshold | ByNeighbours deriving (Show,Generic,Eq)
data Clique = data Clique =
Fis Fis
{ _fis_support :: Int { _fis_support :: Int
, _fis_size :: Int } , _fis_size :: Int }
| MaxClique | MaxClique
{ _mcl_size :: Int } { _mcl_size :: Int
, _mcl_threshold :: Double
, _mcl_filter :: CliqueFilter }
deriving (Show,Generic,Eq) deriving (Show,Generic,Eq)
...@@ -155,10 +158,10 @@ defaultConfig = ...@@ -155,10 +158,10 @@ defaultConfig =
, phyloProximity = WeightedLogJaccard 10 , phyloProximity = WeightedLogJaccard 10
, seaElevation = Constante 0.1 0.1 , seaElevation = Constante 0.1 0.1
, findAncestors = True , findAncestors = True
, phyloSynchrony = ByProximityThreshold 0.2 10 SiblingBranches MergeAllGroups , phyloSynchrony = ByProximityThreshold 0.1 10 SiblingBranches MergeAllGroups
, phyloQuality = Quality 0 1 , phyloQuality = Quality 0 1
, timeUnit = Year 3 1 5 , timeUnit = Year 3 1 5
, clique = MaxClique 0 , clique = MaxClique 0 3 ByNeighbours
, exportLabel = [BranchLabel MostEmergentTfIdf 2, GroupLabel MostEmergentInclusive 2] , exportLabel = [BranchLabel MostEmergentTfIdf 2, GroupLabel MostEmergentInclusive 2]
, exportSort = ByHierarchy , exportSort = ByHierarchy
, exportFilter = [ByBranchSize 2] , exportFilter = [ByBranchSize 2]
...@@ -174,6 +177,8 @@ instance FromJSON SeaElevation ...@@ -174,6 +177,8 @@ instance FromJSON SeaElevation
instance ToJSON SeaElevation instance ToJSON SeaElevation
instance FromJSON TimeUnit instance FromJSON TimeUnit
instance ToJSON TimeUnit instance ToJSON TimeUnit
instance FromJSON CliqueFilter
instance ToJSON CliqueFilter
instance FromJSON Clique instance FromJSON Clique
instance ToJSON Clique instance ToJSON Clique
instance FromJSON PhyloLabel instance FromJSON PhyloLabel
......
...@@ -60,17 +60,19 @@ import Data.Set (Set) ...@@ -60,17 +60,19 @@ import Data.Set (Set)
import Data.Set (fromList, toList, isSubsetOf) import Data.Set (fromList, toList, isSubsetOf)
import Data.Graph.Inductive hiding (Graph, neighbors, subgraph, (&)) import Data.Graph.Inductive hiding (Graph, neighbors, subgraph, (&))
import Gargantext.Core.Viz.Graph.FGL (Graph_Undirected, degree, neighbors, mkGraphUfromEdges) import Gargantext.Core.Viz.Graph.FGL (Graph_Undirected, degree, neighbors, mkGraphUfromEdges)
import Gargantext.Core.Viz.Graph.Tools (cooc2graph', Threshold) import Gargantext.Core.Viz.Graph.Tools (cooc2graph',cooc2graph'', Threshold)
import Gargantext.Core.Viz.Graph.Distances (Distance) import Gargantext.Core.Viz.Graph.Distances (Distance)
import Gargantext.Core.Viz.Graph.Index (createIndices, toIndex) import Gargantext.Core.Viz.Graph.Index (createIndices, toIndex)
import Gargantext.Core.Viz.AdaptativePhylo
-- import Debug.Trace (trace)
type Graph = Graph_Undirected type Graph = Graph_Undirected
type Neighbor = Node type Neighbor = Node
-- | getMaxCliques -- | getMaxCliques
-- TODO chose distance order -- TODO chose distance order
getMaxCliques :: Ord a => Distance -> Threshold -> Map (a, a) Int -> [[a]] getMaxCliques :: Ord a => CliqueFilter -> Distance -> Threshold -> Map (a, a) Int -> [[a]]
getMaxCliques d t m = map fromIndices $ getMaxCliques' t m' getMaxCliques f d t m = map fromIndices $ getMaxCliques' t m'
where where
m' = toIndex to m m' = toIndex to m
(to,from) = createIndices m (to,from) = createIndices m
...@@ -80,7 +82,10 @@ getMaxCliques d t m = map fromIndices $ getMaxCliques' t m' ...@@ -80,7 +82,10 @@ getMaxCliques d t m = map fromIndices $ getMaxCliques' t m'
getMaxCliques' t' n = maxCliques graph getMaxCliques' t' n = maxCliques graph
where where
graph = mkGraphUfromEdges (Map.keys n') graph = mkGraphUfromEdges (Map.keys n')
n' = cooc2graph' d t' n -- n' = cooc2graph' d t' n
n' = case f of ByThreshold -> cooc2graph' d t' n
ByNeighbours -> cooc2graph'' d t' n
maxCliques :: Graph -> [[Node]] maxCliques :: Graph -> [[Node]]
maxCliques g = map (\n -> subMaxCliques g (n:ns)) ns & concat & takeMax maxCliques g = map (\n -> subMaxCliques g (n:ns)) ns & concat & takeMax
......
...@@ -35,6 +35,7 @@ import qualified IGraph.Algorithms.Layout as Layout ...@@ -35,6 +35,7 @@ import qualified IGraph.Algorithms.Layout as Layout
import qualified Data.Vector.Storable as Vec import qualified Data.Vector.Storable as Vec
import qualified Data.Map as Map import qualified Data.Map as Map
import qualified Data.List as List import qualified Data.List as List
-- import Debug.Trace (trace)
type Threshold = Double type Threshold = Double
...@@ -52,6 +53,39 @@ cooc2graph' distance threshold myCooc = distanceMap ...@@ -52,6 +53,39 @@ cooc2graph' distance threshold myCooc = distanceMap
distanceMap = Map.filter (> threshold) $ mat2map distanceMat distanceMap = Map.filter (> threshold) $ mat2map distanceMat
cooc2graph'' :: Ord t => Distance
-> Double
-> Map (t, t) Int
-> Map (Index, Index) Double
cooc2graph'' distance threshold myCooc = neighbouMap
where
(ti, _) = createIndices myCooc
myCooc' = toIndex ti myCooc
matCooc = map2mat 0 (Map.size ti) $ Map.filter (> 1) myCooc'
distanceMat = measure distance matCooc
neighbouMap = filterByNeighbours threshold
$ mat2map distanceMat
-- Quentin
filterByNeighbours :: Double -> Map (Index, Index) Double -> Map (Index, Index) Double
filterByNeighbours threshold distanceMap = filteredMap
where
indexes :: [Index]
indexes = List.nub $ List.concat $ map (\(idx,idx') -> [idx,idx'] ) $ Map.keys distanceMap
filteredMap :: Map (Index, Index) Double
filteredMap = Map.fromList
$ List.concat
$ map (\idx ->
let selected = List.reverse
$ List.sortOn snd
$ Map.toList
$ Map.filter (> 0)
$ Map.filterWithKey (\(from,_) _ -> idx == from) distanceMap
in List.take (round threshold) selected
) indexes
cooc2graph :: Distance cooc2graph :: Distance
-> Threshold -> Threshold
-> (Map (Text, Text) Int) -> (Map (Text, Text) Int)
......
...@@ -104,7 +104,7 @@ config = ...@@ -104,7 +104,7 @@ config =
defaultConfig { phyloName = "Cesar et Cleopatre" defaultConfig { phyloName = "Cesar et Cleopatre"
, phyloLevel = 2 , phyloLevel = 2
, exportFilter = [ByBranchSize 0] , exportFilter = [ByBranchSize 0]
, clique = MaxClique 0 } , clique = MaxClique 0 3 ByNeighbours }
docs :: [Document] docs :: [Document]
......
...@@ -203,8 +203,8 @@ toPhyloClique phylo phyloDocs = case (clique $ getConfig phylo) of ...@@ -203,8 +203,8 @@ toPhyloClique phylo phyloDocs = case (clique $ getConfig phylo) of
$ filterClique True s (filterCliqueBySupport) $ filterClique True s (filterCliqueBySupport)
{- \$ traceFis "Unfiltered Fis" -} {- \$ traceFis "Unfiltered Fis" -}
phyloClique phyloClique
MaxClique s -> filterClique True s (filterCliqueBySize) MaxClique s _ _ -> filterClique True s (filterCliqueBySize)
phyloClique phyloClique
where where
-------------------------------------- --------------------------------------
phyloClique :: Map (Date,Date) [PhyloClique] phyloClique :: Map (Date,Date) [PhyloClique]
...@@ -216,13 +216,13 @@ toPhyloClique phylo phyloDocs = case (clique $ getConfig phylo) of ...@@ -216,13 +216,13 @@ toPhyloClique phylo phyloDocs = case (clique $ getConfig phylo) of
$ toList phyloDocs $ toList phyloDocs
fis' = fis `using` parList rdeepseq fis' = fis `using` parList rdeepseq
in fromList fis' in fromList fis'
MaxClique _ -> MaxClique _ thr filterType ->
let mcl = map (\(prd,docs) -> let mcl = map (\(prd,docs) ->
let cooc = map round let cooc = map round
$ foldl sumCooc empty $ foldl sumCooc empty
$ map listToMatrix $ map listToMatrix
$ map (\d -> ngramsToIdx (text d) (getRoots phylo)) docs $ map (\d -> ngramsToIdx (text d) (getRoots phylo)) docs
in (prd, map (\cl -> PhyloClique cl 0 prd) $ getMaxCliques Conditional 0.001 cooc)) in (prd, map (\cl -> PhyloClique cl 0 prd) $ getMaxCliques filterType Conditional thr cooc))
$ toList phyloDocs $ toList phyloDocs
mcl' = mcl `using` parList rdeepseq mcl' = mcl `using` parList rdeepseq
in fromList mcl' in fromList mcl'
......
...@@ -225,12 +225,12 @@ traceFis msg mFis = trace ( "\n" <> "-- | " <> msg <> " : " <> show (sum $ map l ...@@ -225,12 +225,12 @@ traceFis msg mFis = trace ( "\n" <> "-- | " <> msg <> " : " <> show (sum $ map l
getCliqueSupport :: Clique -> Int getCliqueSupport :: Clique -> Int
getCliqueSupport unit = case unit of getCliqueSupport unit = case unit of
Fis s _ -> s Fis s _ -> s
MaxClique _ -> 0 MaxClique _ _ _ -> 0
getCliqueSize :: Clique -> Int getCliqueSize :: Clique -> Int
getCliqueSize unit = case unit of getCliqueSize unit = case unit of
Fis _ s -> s Fis _ s -> s
MaxClique s -> s MaxClique s _ _ -> s
-------------- --------------
......
...@@ -190,13 +190,13 @@ synchronicClustering phylo = ...@@ -190,13 +190,13 @@ synchronicClustering phylo =
sync = phyloSynchrony $ getConfig phylo sync = phyloSynchrony $ getConfig phylo
docs = phylo ^. phylo_timeDocs docs = phylo ^. phylo_timeDocs
diagos = map coocToDiago $ phylo ^. phylo_timeCooc diagos = map coocToDiago $ phylo ^. phylo_timeCooc
newBranches = map (\branch -> levelUpAncestors $ reduceGroups prox sync docs diagos branch) newBranches = map (\branch -> reduceGroups prox sync docs diagos branch)
$ map processDynamics $ map processDynamics
$ adjustClustering sync $ adjustClustering sync
$ phyloToLastBranches $ phyloToLastBranches
$ traceSynchronyStart phylo $ traceSynchronyStart phylo
newBranches' = newBranches `using` parList rdeepseq newBranches' = newBranches `using` parList rdeepseq
in toNextLevel' phylo $ concat newBranches' in toNextLevel' phylo $ levelUpAncestors $ concat newBranches'
-- synchronicDistance :: Phylo -> Level -> String -- synchronicDistance :: Phylo -> Level -> String
......
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