Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Julien Moutinho
haskell-gargantext
Commits
901125c8
Commit
901125c8
authored
May 13, 2019
by
Quentin Lobbé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add trace to cluster and optimisation to find candidates
parent
cb29fbd9
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
171 additions
and
83 deletions
+171
-83
Main.hs
bin/gargantext-phylo/Main.hs
+10
-12
Phylo.hs
src/Gargantext/Viz/Phylo.hs
+5
-5
Cluster.hs
src/Gargantext/Viz/Phylo/Aggregates/Cluster.hs
+79
-14
Cooc.hs
src/Gargantext/Viz/Phylo/Aggregates/Cooc.hs
+23
-3
BranchMaker.hs
src/Gargantext/Viz/Phylo/BranchMaker.hs
+10
-22
Example.hs
src/Gargantext/Viz/Phylo/Example.hs
+1
-1
LevelMaker.hs
src/Gargantext/Viz/Phylo/LevelMaker.hs
+2
-3
LinkMaker.hs
src/Gargantext/Viz/Phylo/LinkMaker.hs
+27
-19
Clustering.hs
src/Gargantext/Viz/Phylo/Metrics/Clustering.hs
+1
-1
Tools.hs
src/Gargantext/Viz/Phylo/Tools.hs
+13
-3
No files found.
bin/gargantext-phylo/Main.hs
View file @
901125c8
...
@@ -78,6 +78,10 @@ data Conf =
...
@@ -78,6 +78,10 @@ data Conf =
,
timeSens
::
Double
,
timeSens
::
Double
,
clusterTh
::
Double
,
clusterTh
::
Double
,
clusterSens
::
Double
,
clusterSens
::
Double
,
phyloLevel
::
Int
,
viewLevel
::
Int
,
fisSupport
::
Int
,
fisClique
::
Int
}
deriving
(
Show
,
Generic
)
}
deriving
(
Show
,
Generic
)
instance
FromJSON
Conf
instance
FromJSON
Conf
...
@@ -148,17 +152,13 @@ parse format limit path l = do
...
@@ -148,17 +152,13 @@ parse format limit path l = do
main
::
IO
()
main
::
IO
()
main
=
do
main
=
do
putStrLn
$
show
(
"--| Read the conf |--"
)
[
jsonPath
]
<-
getArgs
[
jsonPath
]
<-
getArgs
confJson
<-
(
eitherDecode
<$>
getJson
jsonPath
)
::
IO
(
P
.
Either
P
.
String
Conf
)
confJson
<-
(
eitherDecode
<$>
getJson
jsonPath
)
::
IO
(
P
.
Either
P
.
String
Conf
)
case
confJson
of
case
confJson
of
P
.
Left
err
->
putStrLn
err
P
.
Left
err
->
putStrLn
err
P
.
Right
conf
->
do
P
.
Right
conf
->
do
putStrLn
$
show
(
"--| Parse the corpus |--"
)
termList
<-
csvGraphTermList
(
listPath
conf
)
termList
<-
csvGraphTermList
(
listPath
conf
)
...
@@ -166,21 +166,19 @@ main = do
...
@@ -166,21 +166,19 @@ main = do
let
roots
=
DL
.
nub
$
DL
.
concat
$
map
text
corpus
let
roots
=
DL
.
nub
$
DL
.
concat
$
map
text
corpus
putStrLn
$
(
"-- | parsed docs : "
<>
show
(
length
corpus
)
<>
" |--"
)
putStrLn
$
(
show
(
length
corpus
)
<>
" parsed docs"
)
putStrLn
$
show
(
"--| Build the phylo |--"
)
let
query
=
PhyloQueryBuild
(
phyloName
conf
)
""
(
timeGrain
conf
)
(
timeStep
conf
)
let
query
=
PhyloQueryBuild
(
phyloName
conf
)
""
(
timeGrain
conf
)
(
timeStep
conf
)
defaultFis
[]
[]
(
WeightedLogJaccard
$
WLJParams
(
timeTh
conf
)
(
timeSens
conf
))
2
(
Fis
$
FisParams
True
(
fisSupport
conf
)
(
fisClique
conf
))
[]
[]
(
WeightedLogJaccard
$
WLJParams
(
timeTh
conf
)
(
timeSens
conf
))
(
phyloLevel
conf
)
(
RelatedComponents
$
RCParams
$
WeightedLogJaccard
$
WLJParams
(
clusterTh
conf
)
(
clusterSens
conf
))
(
RelatedComponents
$
RCParams
$
WeightedLogJaccard
$
WLJParams
(
clusterTh
conf
)
(
clusterSens
conf
))
let
queryView
=
PhyloQueryView
2
Merge
False
1
[
BranchAge
]
[
defaultSmallBranch
]
[
BranchPeakFreq
,
GroupLabelCooc
]
(
Just
(
ByBranchAge
,
Asc
))
Json
Flat
True
let
queryView
=
PhyloQueryView
(
viewLevel
conf
)
Merge
False
1
[
BranchAge
]
[
defaultSmallBranch
]
[
BranchPeakFreq
,
GroupLabelCooc
]
(
Just
(
ByBranchAge
,
Asc
))
Json
Flat
True
let
phylo
=
toPhylo
query
corpus
roots
termList
let
phylo
=
toPhylo
query
corpus
roots
termList
let
view
=
toPhyloView
queryView
phylo
let
view
=
toPhyloView
queryView
phylo
putStrLn
$
show
(
"--| Export the phylo as a dot graph |--"
)
putStrLn
$
(
"phylo completed until level "
<>
show
(
phyloLevel
conf
)
<>
", export at level "
<>
show
(
viewLevel
conf
)
)
let
outputFile
=
(
outputPath
conf
)
<>
(
DT
.
unpack
$
phyloName
conf
)
let
outputFile
=
(
outputPath
conf
)
<>
(
DT
.
unpack
$
phyloName
conf
)
<>
"_"
<>
show
(
limit
conf
)
<>
"_"
<>
"_"
<>
show
(
limit
conf
)
<>
"_"
...
@@ -190,4 +188,4 @@ main = do
...
@@ -190,4 +188,4 @@ main = do
<>
"_"
<>
show
(
clusterSens
conf
)
<>
"_"
<>
show
(
clusterSens
conf
)
<>
".dot"
<>
".dot"
P
.
writeFile
outputFile
$
dotToString
$
viewToDot
view
P
.
writeFile
outputFile
$
dotToString
$
viewToDot
view
src/Gargantext/Viz/Phylo.hs
View file @
901125c8
...
@@ -207,12 +207,12 @@ data PhyloFis = PhyloFis
...
@@ -207,12 +207,12 @@ data PhyloFis = PhyloFis
type
PhyloCluster
=
[
PhyloGroup
]
type
PhyloCluster
=
[
PhyloGroup
]
-- | A
List of
PhyloGroup in a Graph
-- | A PhyloGroup in a Graph
type
GroupNode
s
=
[
PhyloGroup
]
type
GroupNode
=
PhyloGroup
-- | A
List of weighted links between some
PhyloGroups in a Graph
-- | A
weighted links between two
PhyloGroups in a Graph
type
GroupEdge
s
=
[((
PhyloGroup
,
PhyloGroup
),
Weight
)]
type
GroupEdge
=
((
PhyloGroup
,
PhyloGroup
),
Weight
)
-- | The association as a Graph between a list of Nodes and a list of Edges
-- | The association as a Graph between a list of Nodes and a list of Edges
type
GroupGraph
=
(
GroupNodes
,
GroupEdges
)
type
GroupGraph
=
(
[
GroupNode
],[
GroupEdge
]
)
---------------
---------------
...
...
src/Gargantext/Viz/Phylo/Aggregates/Cluster.hs
View file @
901125c8
...
@@ -17,30 +17,95 @@ Portability : POSIX
...
@@ -17,30 +17,95 @@ Portability : POSIX
module
Gargantext.Viz.Phylo.Aggregates.Cluster
module
Gargantext.Viz.Phylo.Aggregates.Cluster
where
where
import
Data.List
(
null
,
tail
)
import
Data.List
(
null
,
tail
,
concat
)
import
Data.Map
(
Map
)
import
Data.Map
(
Map
)
import
Data.Tuple
(
fst
)
import
Data.Tuple
(
fst
)
import
Gargantext.Prelude
import
Gargantext.Prelude
import
Gargantext.Viz.Phylo
import
Gargantext.Viz.Phylo
import
Gargantext.Viz.Phylo.Tools
import
Gargantext.Viz.Phylo.Tools
import
Gargantext.Viz.Phylo.
BranchMaker
import
Gargantext.Viz.Phylo.
Metrics.Proximity
import
Gargantext.Viz.Phylo.Metrics.Clustering
import
Gargantext.Viz.Phylo.Metrics.Clustering
import
qualified
Data.Map
as
Map
import
qualified
Data.Map
as
Map
import
qualified
Data.Vector.Storable
as
VS
import
Debug.Trace
(
trace
)
import
Numeric.Statistics
(
percentile
)
-- | To apply a Clustering method to a PhyloGraph
-- | To transform a Graph into Clusters
graphToClusters
::
Cluster
->
GroupGraph
->
[
PhyloCluster
]
graphToClusters
::
Cluster
->
GroupGraph
->
[
PhyloCluster
]
graphToClusters
clust
(
nodes
,
edges
)
=
case
clust
of
graphToClusters
clust
(
nodes
,
edges
)
=
case
clust
of
Louvain
(
LouvainParams
_
)
->
undefined
-- louvain (nodes,edges)
Louvain
(
LouvainParams
_
)
->
undefined
RelatedComponents
(
RCParams
_
)
->
relatedComp
0
(
head'
"graphToClusters"
nodes
)
(
tail
nodes
,
edges
)
[]
[]
RelatedComponents
(
RCParams
_
)
->
relatedComp
0
(
head'
"graphToClusters"
nodes
)
(
tail
nodes
,
edges
)
[]
[]
_
->
panic
"[ERR][Viz.Phylo.Aggregates.Cluster.graphToClusters] not implemented"
_
->
panic
"[ERR][Viz.Phylo.Aggregates.Cluster.graphToClusters] not implemented"
-- | To transform a list of PhyloGroups into a Graph of Proximity
groupsToGraph
::
Proximity
->
[
PhyloGroup
]
->
([
GroupNode
],[
GroupEdge
])
groupsToGraph
prox
gs
=
case
prox
of
WeightedLogJaccard
(
WLJParams
_
sens
)
->
(
gs
,
map
(
\
(
x
,
y
)
->
((
x
,
y
),
weightedLogJaccard
sens
(
getGroupCooc
x
)
(
getGroupCooc
y
)))
$
listToDirectedCombi
gs
)
Hamming
(
HammingParams
_
)
->
(
gs
,
map
(
\
(
x
,
y
)
->
((
x
,
y
),
hamming
(
getGroupCooc
x
)
(
getGroupCooc
y
)))
$
listToDirectedCombi
gs
)
_
->
undefined
-- | To transform a Phylo into Clusters of PhyloGroups at a given level
-- | To filter a Graph of Proximity using a given threshold
filterGraph
::
Proximity
->
([
GroupNode
],[
GroupEdge
])
->
([
GroupNode
],[
GroupEdge
])
filterGraph
prox
(
ns
,
es
)
=
case
prox
of
WeightedLogJaccard
(
WLJParams
thr
_
)
->
(
ns
,
filter
(
\
(
_
,
v
)
->
v
>=
thr
)
es
)
Hamming
(
HammingParams
thr
)
->
(
ns
,
filter
(
\
(
_
,
v
)
->
v
<=
thr
)
es
)
_
->
undefined
-- | To clusterise a Phylo
phyloToClusters
::
Level
->
Cluster
->
Phylo
->
Map
(
Date
,
Date
)
[
PhyloCluster
]
phyloToClusters
::
Level
->
Cluster
->
Phylo
->
Map
(
Date
,
Date
)
[
PhyloCluster
]
phyloToClusters
lvl
clus
p
=
Map
.
fromList
phyloToClusters
lvl
clus
p
=
Map
.
fromList
$
zip
(
getPhyloPeriods
p
)
$
zip
periods
(
map
(
\
prd
->
let
graph
=
groupsToGraph
(
getProximity
clus
)
(
getGroupsWithFilters
lvl
prd
p
)
p
$
map
(
\
g
->
if
null
(
fst
g
)
in
if
null
(
fst
graph
)
then
[]
then
[]
else
graphToClusters
clus
g
)
graphs'
else
graphToClusters
clus
graph
)
where
(
getPhyloPeriods
p
))
--------------------------------------
graphs'
::
[([
GroupNode
],[
GroupEdge
])]
graphs'
=
traceGraphFiltered
lvl
$
map
(
\
g
->
filterGraph
prox
g
)
graphs
--------------------------------------
graphs
::
[([
GroupNode
],[
GroupEdge
])]
graphs
=
traceGraph
lvl
(
getThreshold
prox
)
$
map
(
\
prd
->
groupsToGraph
prox
(
getGroupsWithFilters
lvl
prd
p
))
periods
--------------------------------------
prox
::
Proximity
prox
=
getProximity
clus
--------------------------------------
periods
::
[
PhyloPeriodId
]
periods
=
getPhyloPeriods
p
--------------------------------------
----------------
-- | Tracer | --
----------------
traceGraph
::
Level
->
Double
->
[([
GroupNode
],[
GroupEdge
])]
->
[([
GroupNode
],[
GroupEdge
])]
traceGraph
lvl
thr
g
=
trace
(
"----
\n
Unfiltered clustering in Phylo"
<>
show
(
lvl
)
<>
" :
\n
"
<>
"count : "
<>
show
(
length
lst
)
<>
" potential edges ("
<>
show
(
length
$
filter
(
>=
thr
)
lst
)
<>
" >= "
<>
show
(
thr
)
<>
")
\n
"
<>
"similarity : "
<>
show
(
percentile
25
(
VS
.
fromList
lst
))
<>
" (25%) "
<>
show
(
percentile
50
(
VS
.
fromList
lst
))
<>
" (50%) "
<>
show
(
percentile
75
(
VS
.
fromList
lst
))
<>
" (75%) "
<>
show
(
percentile
90
(
VS
.
fromList
lst
))
<>
" (90%)
\n
"
)
g
where
lst
=
map
snd
$
concat
$
map
snd
g
traceGraphFiltered
::
Level
->
[([
GroupNode
],[
GroupEdge
])]
->
[([
GroupNode
],[
GroupEdge
])]
traceGraphFiltered
lvl
g
=
trace
(
"----
\n
Clustering in Phylo"
<>
show
(
lvl
)
<>
" :
\n
"
<>
"count : "
<>
show
(
length
lst
)
<>
" edges
\n
"
<>
"similarity : "
<>
show
(
percentile
25
(
VS
.
fromList
lst
))
<>
" (25%) "
<>
show
(
percentile
50
(
VS
.
fromList
lst
))
<>
" (50%) "
<>
show
(
percentile
75
(
VS
.
fromList
lst
))
<>
" (75%) "
<>
show
(
percentile
90
(
VS
.
fromList
lst
))
<>
" (90%)
\n
"
)
g
where
lst
=
map
snd
$
concat
$
map
snd
g
src/Gargantext/Viz/Phylo/Aggregates/Cooc.hs
View file @
901125c8
...
@@ -26,9 +26,9 @@ import qualified Data.Map as Map
...
@@ -26,9 +26,9 @@ import qualified Data.Map as Map
import
qualified
Data.Set
as
Set
import
qualified
Data.Set
as
Set
-- | To transform the Fis into a coocurency Matrix in a Phylo
-- | To transform the Fis into a coocurency Matrix in a Phylo
but as a triangle
fisToCooc
::
Map
(
Date
,
Date
)
[
PhyloFis
]
->
Phylo
->
Map
(
Int
,
Int
)
Double
fisToCooc
'
::
Map
(
Date
,
Date
)
[
PhyloFis
]
->
Phylo
->
Map
(
Int
,
Int
)
Double
fisToCooc
m
p
=
map
(
/
docs
)
fisToCooc
'
m
p
=
map
(
/
docs
)
$
foldl
(
\
mem
x
->
adjust
(
+
1
)
(
getKeyPair
x
mem
)
mem
)
cooc
$
foldl
(
\
mem
x
->
adjust
(
+
1
)
(
getKeyPair
x
mem
)
mem
)
cooc
$
concat
$
concat
$
map
(
\
x
->
listToUnDirectedCombiWith
(
\
y
->
getIdxInRoots
y
p
)
$
(
Set
.
toList
.
getClique
)
x
)
$
map
(
\
x
->
listToUnDirectedCombiWith
(
\
y
->
getIdxInRoots
y
p
)
$
(
Set
.
toList
.
getClique
)
x
)
...
@@ -46,5 +46,25 @@ fisToCooc m p = map (/docs)
...
@@ -46,5 +46,25 @@ fisToCooc m p = map (/docs)
--------------------------------------
--------------------------------------
-- | To transform the Fis into a full coocurency Matrix in a Phylo
fisToCooc
::
Map
(
Date
,
Date
)
[
PhyloFis
]
->
Phylo
->
Map
(
Int
,
Int
)
Double
fisToCooc
m
p
=
map
(
/
docs
)
$
foldl
(
\
mem
x
->
adjust
(
+
1
)
x
mem
)
cooc
$
concat
$
map
(
\
x
->
listToDirectedCombiWith
(
\
y
->
getIdxInRoots
y
p
)
$
(
Set
.
toList
.
getClique
)
x
)
$
(
concat
.
elems
)
m
where
--------------------------------------
fisNgrams
::
[
Ngrams
]
fisNgrams
=
foldl
(
\
mem
x
->
union
mem
$
(
Set
.
toList
.
getClique
)
x
)
[]
$
(
concat
.
elems
)
m
--------------------------------------
docs
::
Double
docs
=
fromIntegral
$
foldl
(
\
mem
x
->
mem
+
(
getSupport
x
))
0
$
(
concat
.
elems
)
m
--------------------------------------
cooc
::
Map
(
Int
,
Int
)
(
Double
)
cooc
=
Map
.
fromList
$
map
(
\
x
->
(
x
,
0
))
(
listToDirectedCombiWith
(
\
y
->
getIdxInRoots
y
p
)
fisNgrams
)
--------------------------------------
-- phyloCooc :: Map (Int, Int) Double
-- phyloCooc :: Map (Int, Int) Double
-- phyloCooc = fisToCooc phyloFis phylo1_0_1
-- phyloCooc = fisToCooc phyloFis phylo1_0_1
src/Gargantext/Viz/Phylo/BranchMaker.hs
View file @
901125c8
...
@@ -20,11 +20,9 @@ module Gargantext.Viz.Phylo.BranchMaker
...
@@ -20,11 +20,9 @@ module Gargantext.Viz.Phylo.BranchMaker
import
Control.Lens
hiding
(
both
,
Level
)
import
Control.Lens
hiding
(
both
,
Level
)
import
Data.List
(
concat
,
nub
,(
++
),
tail
)
import
Data.List
(
concat
,
nub
,(
++
),
tail
)
import
Data.Tuple
(
fst
,
snd
)
import
Data.Tuple
(
fst
,
snd
)
import
Data.Map
(
Map
,
fromList
,
toList
)
import
Gargantext.Prelude
import
Gargantext.Prelude
import
Gargantext.Viz.Phylo
import
Gargantext.Viz.Phylo
import
Gargantext.Viz.Phylo.Metrics.Clustering
import
Gargantext.Viz.Phylo.Metrics.Clustering
import
Gargantext.Viz.Phylo.Metrics.Proximity
import
Gargantext.Viz.Phylo.Tools
import
Gargantext.Viz.Phylo.Tools
-- import Debug.Trace (trace)
-- import Debug.Trace (trace)
...
@@ -37,26 +35,16 @@ graphToBranches _lvl (nodes,edges) _p = concat
...
@@ -37,26 +35,16 @@ graphToBranches _lvl (nodes,edges) _p = concat
$
relatedComp
0
(
head'
"branchMaker"
nodes
)
(
tail
nodes
,
edges
)
[]
[]
$
relatedComp
0
(
head'
"branchMaker"
nodes
)
(
tail
nodes
,
edges
)
[]
[]
mirror
::
Ord
a
=>
Map
(
a
,
a
)
b
->
Map
(
a
,
a
)
b
mirror
m
=
fromList
$
concat
$
map
(
\
((
k
,
k'
),
v
)
->
[((
k
,
k'
),
v
),((
k'
,
k
),
v
)])
$
toList
m
-- | To build a graph using the parents and childs pointers
-- | To transform a list of PhyloGroups into a PhyloGraph by using a given Proximity mesure
makeGraph
::
[
PhyloGroup
]
->
Phylo
->
GroupGraph
groupsToGraph
::
Proximity
->
[
PhyloGroup
]
->
Phylo
->
GroupGraph
makeGraph
gs
p
=
(
gs
,
edges
)
groupsToGraph
prox
groups
p
=
(
groups
,
edges
)
where
where
edges
::
[
GroupEdge
]
edges
::
GroupEdges
edges
=
(
nub
.
concat
)
edges
=
case
prox
of
$
map
(
\
g
->
(
map
(
\
g'
->
((
g'
,
g
),
1
))
$
getGroupParents
g
p
)
Filiation
->
(
nub
.
concat
)
$
map
(
\
g
->
(
map
(
\
g'
->
((
g'
,
g
),
1
))
$
getGroupParents
g
p
)
++
++
(
map
(
\
g'
->
((
g
,
g'
),
1
))
$
getGroupChilds
g
p
))
gs
(
map
(
\
g'
->
((
g
,
g'
),
1
))
$
getGroupChilds
g
p
))
groups
WeightedLogJaccard
(
WLJParams
thr
sens
)
->
filter
(
\
(
_
,
v
)
->
v
>=
thr
)
$
map
(
\
(
x
,
y
)
->
((
x
,
y
),
weightedLogJaccard
sens
(
mirror
$
getGroupCooc
x
)
(
mirror
$
getGroupCooc
y
)))
$
listToDirectedCombi
groups
Hamming
(
HammingParams
thr
)
->
filter
(
\
edge
->
snd
edge
<=
thr
)
$
map
(
\
(
x
,
y
)
->
((
x
,
y
),
hamming
(
getGroupCooc
x
)
(
unifySharedKeys
(
getGroupCooc
x
)
(
getGroupCooc
y
))))
$
listToDirectedCombi
groups
--
_
->
undefined
-- | To set all the PhyloBranches for a given Level in a Phylo
-- | To set all the PhyloBranches for a given Level in a Phylo
...
@@ -69,5 +57,5 @@ setPhyloBranches lvl p = alterGroupWithLevel (\g -> let bIdx = (fst $ head' "bra
...
@@ -69,5 +57,5 @@ setPhyloBranches lvl p = alterGroupWithLevel (\g -> let bIdx = (fst $ head' "bra
bs
=
graphToBranches
lvl
graph
p
bs
=
graphToBranches
lvl
graph
p
--------------------------------------
--------------------------------------
graph
::
GroupGraph
graph
::
GroupGraph
graph
=
groupsToGraph
Filiation
(
getGroupsWithLevel
lvl
p
)
p
graph
=
makeGraph
(
getGroupsWithLevel
lvl
p
)
p
--------------------------------------
--------------------------------------
src/Gargantext/Viz/Phylo/Example.hs
View file @
901125c8
...
@@ -104,7 +104,7 @@ queryEx = "title=Cesar et Cleôpatre"
...
@@ -104,7 +104,7 @@ queryEx = "title=Cesar et Cleôpatre"
phyloQueryBuild
::
PhyloQueryBuild
phyloQueryBuild
::
PhyloQueryBuild
phyloQueryBuild
=
PhyloQueryBuild
"Cesar et Cleôpatre"
"An example of Phylomemy (french without accent)"
phyloQueryBuild
=
PhyloQueryBuild
"Cesar et Cleôpatre"
"An example of Phylomemy (french without accent)"
5
3
defaultFis
[]
[]
(
WeightedLogJaccard
$
WLJParams
0.1
10
)
3
(
RelatedComponents
$
RCParams
$
WeightedLogJaccard
$
WLJParams
0.05
10
)
5
3
defaultFis
[]
[]
(
WeightedLogJaccard
$
WLJParams
0.1
10
)
2
(
RelatedComponents
$
RCParams
$
WeightedLogJaccard
$
WLJParams
0.1
10
)
...
...
src/Gargantext/Viz/Phylo/LevelMaker.hs
View file @
901125c8
...
@@ -270,14 +270,13 @@ instance PhyloMaker [Document]
...
@@ -270,14 +270,13 @@ instance PhyloMaker [Document]
tracePhyloBase
::
Phylo
->
Phylo
tracePhyloBase
::
Phylo
->
Phylo
tracePhyloBase
p
=
trace
(
"
----
\n
PhyloBase :
\n
"
tracePhyloBase
p
=
trace
(
"
\n
-----------------
\n
--| PhyloBase |--
\n
-----------------
\n
\n
"
<>
show
(
length
$
_phylo_periods
p
)
<>
" periods from "
<>
show
(
length
$
_phylo_periods
p
)
<>
" periods from "
<>
show
(
getPhyloPeriodId
$
(
head'
"PhyloMaker"
)
$
_phylo_periods
p
)
<>
show
(
getPhyloPeriodId
$
(
head'
"PhyloMaker"
)
$
_phylo_periods
p
)
<>
" to "
<>
" to "
<>
show
(
getPhyloPeriodId
$
last
$
_phylo_periods
p
)
<>
show
(
getPhyloPeriodId
$
last
$
_phylo_periods
p
)
<>
"
\n
"
<>
"
\n
"
<>
show
(
Vector
.
length
$
getFoundationsRoots
p
)
<>
" foundations roots
\n
"
)
p
<>
show
(
Vector
.
length
$
getFoundationsRoots
p
)
<>
" foundations roots
\n
"
)
p
traceTempoMatching
::
Filiation
->
Level
->
Phylo
->
Phylo
traceTempoMatching
::
Filiation
->
Level
->
Phylo
->
Phylo
...
@@ -299,7 +298,7 @@ traceTempoMatching fil lvl p = trace ( "----\n" <> show (fil) <> " filtered temp
...
@@ -299,7 +298,7 @@ traceTempoMatching fil lvl p = trace ( "----\n" <> show (fil) <> " filtered temp
traceBranches
::
Level
->
Phylo
->
Phylo
traceBranches
::
Level
->
Phylo
->
Phylo
traceBranches
lvl
p
=
trace
(
"----
\n
"
<>
"Branches in Phylo"
<>
show
lvl
<>
" :
\n
"
traceBranches
lvl
p
=
trace
(
"----
\n
"
<>
"Branches in Phylo"
<>
show
lvl
<>
" :
\n
"
<>
"count : "
<>
show
(
length
$
getBranchIds
p
)
<>
" branches
\n
"
<>
"count : "
<>
show
(
length
$
filter
(
\
(
lvl'
,
_
)
->
lvl'
==
lvl
)
$
getBranchIds
p
)
<>
" branches
\n
"
<>
"count : "
<>
show
(
length
$
getGroupsWithLevel
lvl
p
)
<>
" groups
\n
"
<>
"count : "
<>
show
(
length
$
getGroupsWithLevel
lvl
p
)
<>
" groups
\n
"
<>
"groups by branch : "
<>
show
(
percentile
25
(
VS
.
fromList
brs
))
<>
" (25%) "
<>
"groups by branch : "
<>
show
(
percentile
25
(
VS
.
fromList
brs
))
<>
" (25%) "
<>
show
(
percentile
50
(
VS
.
fromList
brs
))
<>
" (50%) "
<>
show
(
percentile
50
(
VS
.
fromList
brs
))
<>
" (50%) "
...
...
src/Gargantext/Viz/Phylo/LinkMaker.hs
View file @
901125c8
...
@@ -18,7 +18,7 @@ module Gargantext.Viz.Phylo.LinkMaker
...
@@ -18,7 +18,7 @@ module Gargantext.Viz.Phylo.LinkMaker
where
where
import
Control.Lens
hiding
(
both
,
Level
)
import
Control.Lens
hiding
(
both
,
Level
)
import
Data.List
((
++
),
sortOn
,
null
,
tail
,
splitAt
,
elem
,
concat
,
sort
,
delete
)
import
Data.List
((
++
),
sortOn
,
null
,
tail
,
splitAt
,
elem
,
concat
,
sort
,
delete
,
intersect
)
import
Data.Tuple.Extra
import
Data.Tuple.Extra
import
Data.Map
(
Map
,(
!
))
import
Data.Map
(
Map
,(
!
))
import
Gargantext.Prelude
import
Gargantext.Prelude
...
@@ -68,17 +68,16 @@ linkGroupToGroups (lvl,lvl') current targets
...
@@ -68,17 +68,16 @@ linkGroupToGroups (lvl,lvl') current targets
--------------------------------------
--------------------------------------
-- | To set the LevelLinks between two lists of PhyloGroups
linkGroupsByLevel
::
(
Level
,
Level
)
->
Phylo
->
[
PhyloGroup
]
->
[
PhyloGroup
]
linkGroupsByLevel
(
lvl
,
lvl'
)
p
groups
=
map
(
\
group
->
if
getGroupLevel
group
==
lvl
then
linkGroupToGroups
(
lvl
,
lvl'
)
group
(
getGroupsWithFilters
lvl'
(
getGroupPeriod
group
)
p
)
else
group
)
groups
-- | To set the LevelLink of all the PhyloGroups of a Phylo
-- | To set the LevelLink of all the PhyloGroups of a Phylo
setLevelLinks
::
(
Level
,
Level
)
->
Phylo
->
Phylo
setLevelLinks
::
(
Level
,
Level
)
->
Phylo
->
Phylo
setLevelLinks
(
lvl
,
lvl'
)
p
=
alterPhyloGroups
(
linkGroupsByLevel
(
lvl
,
lvl'
)
p
)
p
setLevelLinks
(
lvl
,
lvl'
)
p
=
alterPhyloGroups
(
\
gs
->
map
(
\
g
->
if
getGroupLevel
g
==
lvl
then
linkGroupToGroups
(
lvl
,
lvl'
)
g
(
filter
(
\
g'
->
getGroupPeriod
g'
==
getGroupPeriod
g
)
gs'
)
else
g
)
gs
)
p
where
--------------------------------------
gs'
::
[
PhyloGroup
]
gs'
=
getGroupsWithLevel
lvl'
p
--------------------------------------
------------------------------------------------------------------------
------------------------------------------------------------------------
...
@@ -88,8 +87,10 @@ setLevelLinks (lvl,lvl') p = alterPhyloGroups (linkGroupsByLevel (lvl,lvl') p) p
...
@@ -88,8 +87,10 @@ setLevelLinks (lvl,lvl') p = alterPhyloGroups (linkGroupsByLevel (lvl,lvl') p) p
-- | To apply the corresponding proximity function based on a given Proximity
-- | To apply the corresponding proximity function based on a given Proximity
applyProximity
::
Proximity
->
PhyloGroup
->
PhyloGroup
->
(
PhyloGroupId
,
Double
)
applyProximity
::
Proximity
->
PhyloGroup
->
PhyloGroup
->
(
PhyloGroupId
,
Double
)
applyProximity
prox
g1
g2
=
case
prox
of
applyProximity
prox
g1
g2
=
case
prox
of
WeightedLogJaccard
(
WLJParams
_
s
)
->
((
getGroupId
g2
),
weightedLogJaccard
s
(
getGroupCooc
g1
)
(
unifySharedKeys
(
getGroupCooc
g2
)
(
getGroupCooc
g1
)))
-- WeightedLogJaccard (WLJParams _ s) -> ((getGroupId g2),weightedLogJaccard s (getGroupCooc g1) (unifySharedKeys (getGroupCooc g2) (getGroupCooc g1)))
Hamming
(
HammingParams
_
)
->
((
getGroupId
g2
),
hamming
(
getGroupCooc
g1
)
(
unifySharedKeys
(
getGroupCooc
g2
)
(
getGroupCooc
g1
)))
-- Hamming (HammingParams _) -> ((getGroupId g2),hamming (getGroupCooc g1) (unifySharedKeys (getGroupCooc g2) (getGroupCooc g1)))
WeightedLogJaccard
(
WLJParams
_
s
)
->
((
getGroupId
g2
),
weightedLogJaccard
s
(
getGroupCooc
g1
)
(
getGroupCooc
g2
))
Hamming
(
HammingParams
_
)
->
((
getGroupId
g2
),
hamming
(
getGroupCooc
g1
)
(
getGroupCooc
g2
))
_
->
panic
(
"[ERR][Viz.Phylo.Example.applyProximity] Proximity function not defined"
)
_
->
panic
(
"[ERR][Viz.Phylo.Example.applyProximity] Proximity function not defined"
)
...
@@ -152,13 +153,20 @@ addPointers' fil pts g = g & case fil of
...
@@ -152,13 +153,20 @@ addPointers' fil pts g = g & case fil of
updateGroups
::
Filiation
->
Level
->
Map
PhyloGroupId
[
Pointer
]
->
Phylo
->
Phylo
updateGroups
::
Filiation
->
Level
->
Map
PhyloGroupId
[
Pointer
]
->
Phylo
->
Phylo
updateGroups
fil
lvl
m
p
=
alterPhyloGroups
(
\
gs
->
map
(
\
g
->
if
(
getGroupLevel
g
)
==
lvl
updateGroups
fil
lvl
m
p
=
alterPhyloGroups
(
\
gs
->
map
(
\
g
->
if
(
getGroupLevel
g
)
==
lvl
then
addPointers'
fil
(
m
!
(
getGroupId
g
))
g
then
addPointers'
fil
(
m
!
(
getGroupId
g
))
g
else
g
)
gs
)
p
else
g
)
gs
)
p
-- | Optimisation : to keep only the groups that have at least one ngrams in commons with the target
filterCandidates
::
PhyloGroup
->
[
PhyloGroup
]
->
[
PhyloGroup
]
filterCandidates
g
gs
=
filter
(
\
g'
->
(
not
.
null
)
$
intersect
(
getGroupNgrams
g
)
(
getGroupNgrams
g'
))
$
delete
g
gs
-- | To apply the intertemporal matching to Phylo at a given level
-- | To apply the intertemporal matching to Phylo at a given level
interTempoMatching
::
Filiation
->
Level
->
Proximity
->
Phylo
->
Phylo
interTempoMatching
::
Filiation
->
Level
->
Proximity
->
Phylo
->
Phylo
interTempoMatching
fil
lvl
prox
p
=
traceMatching
fil
lvl
scores
interTempoMatching
fil
lvl
prox
p
=
traceMatching
fil
lvl
(
getThreshold
prox
)
scores
$
updateGroups
fil
lvl
pointers
p
$
updateGroups
fil
lvl
pointers
p
where
where
--------------------------------------
--------------------------------------
...
@@ -167,9 +175,9 @@ interTempoMatching fil lvl prox p = traceMatching fil lvl scores
...
@@ -167,9 +175,9 @@ interTempoMatching fil lvl prox p = traceMatching fil lvl scores
--------------------------------------
--------------------------------------
scores
::
[
Double
]
scores
::
[
Double
]
scores
=
sort
$
concat
$
map
(
snd
.
snd
)
candidates
scores
=
sort
$
concat
$
map
(
snd
.
snd
)
candidates
--------------------------------------
--------------------------------------
candidates
::
[(
PhyloGroupId
,([
Pointer
],[
Double
]))]
candidates
::
[(
PhyloGroupId
,([
Pointer
],[
Double
]))]
candidates
=
map
(
\
g
->
(
getGroupId
g
,
findBestCandidates'
fil
1
5
prox
(
getNextPeriods
fil
(
getGroupPeriod
g
)
prds
)
(
delete
g
gs
)
g
))
gs
candidates
=
map
(
\
g
->
(
getGroupId
g
,
findBestCandidates'
fil
1
5
prox
(
getNextPeriods
fil
(
getGroupPeriod
g
)
prds
)
(
filterCandidates
g
gs
)
g
))
gs
--------------------------------------
--------------------------------------
gs
::
[
PhyloGroup
]
gs
::
[
PhyloGroup
]
gs
=
getGroupsWithLevel
lvl
p
gs
=
getGroupsWithLevel
lvl
p
...
@@ -184,9 +192,9 @@ interTempoMatching fil lvl prox p = traceMatching fil lvl scores
...
@@ -184,9 +192,9 @@ interTempoMatching fil lvl prox p = traceMatching fil lvl scores
----------------
----------------
traceMatching
::
Filiation
->
Level
->
[
Double
]
->
Phylo
->
Phylo
traceMatching
::
Filiation
->
Level
->
Double
->
[
Double
]
->
Phylo
->
Phylo
traceMatching
fil
lvl
lst
p
=
trace
(
"----
\n
"
<>
show
(
fil
)
<>
" unfiltered temporal Matching in Phylo"
<>
show
(
lvl
)
<>
" :
\n
"
traceMatching
fil
lvl
thr
lst
p
=
trace
(
"----
\n
"
<>
show
(
fil
)
<>
" unfiltered temporal Matching in Phylo"
<>
show
(
lvl
)
<>
" :
\n
"
<>
"count : "
<>
show
(
length
lst
)
<>
" potential pointers
\n
"
<>
"count : "
<>
show
(
length
lst
)
<>
" potential pointers
("
<>
show
(
length
$
filter
(
>=
thr
)
lst
)
<>
" >= "
<>
show
(
thr
)
<>
")
\n
"
<>
"similarity : "
<>
show
(
percentile
25
(
VS
.
fromList
lst
))
<>
" (25%) "
<>
"similarity : "
<>
show
(
percentile
25
(
VS
.
fromList
lst
))
<>
" (25%) "
<>
show
(
percentile
50
(
VS
.
fromList
lst
))
<>
" (50%) "
<>
show
(
percentile
50
(
VS
.
fromList
lst
))
<>
" (50%) "
<>
show
(
percentile
75
(
VS
.
fromList
lst
))
<>
" (75%) "
<>
show
(
percentile
75
(
VS
.
fromList
lst
))
<>
" (75%) "
...
...
src/Gargantext/Viz/Phylo/Metrics/Clustering.hs
View file @
901125c8
...
@@ -50,7 +50,7 @@ relatedComp idx curr (nodes,edges) next memo
...
@@ -50,7 +50,7 @@ relatedComp idx curr (nodes,edges) next memo
--------------------------------------
--------------------------------------
louvain
::
(
GroupNodes
,
GroupEdges
)
->
IO
[[
PhyloGroup
]]
louvain
::
(
[
GroupNode
],[
GroupEdge
]
)
->
IO
[[
PhyloGroup
]]
louvain
(
nodes
,
edges
)
=
map
(
\
community
->
map
(
\
node
->
nodes
!!
(
l_node_id
node
))
community
)
louvain
(
nodes
,
edges
)
=
map
(
\
community
->
map
(
\
node
->
nodes
!!
(
l_node_id
node
))
community
)
<$>
groupBy
(
\
a
b
->
(
l_community_id
a
)
==
(
l_community_id
b
))
<$>
groupBy
(
\
a
b
->
(
l_community_id
a
)
==
(
l_community_id
b
))
<$>
(
cLouvain
$
mapKeys
(
\
(
x
,
y
)
->
(
idx
x
,
idx
y
))
$
fromList
edges
)
<$>
(
cLouvain
$
mapKeys
(
\
(
x
,
y
)
->
(
idx
x
,
idx
y
))
$
fromList
edges
)
...
...
src/Gargantext/Viz/Phylo/Tools.hs
View file @
901125c8
...
@@ -471,12 +471,12 @@ getSupport = _phyloFis_support
...
@@ -471,12 +471,12 @@ getSupport = _phyloFis_support
-- | To filter some GroupEdges with a given threshold
-- | To filter some GroupEdges with a given threshold
filterGroupEdges
::
Double
->
GroupEdges
->
GroupEdges
filterGroupEdges
::
Double
->
[
GroupEdge
]
->
[
GroupEdge
]
filterGroupEdges
thr
edges
=
filter
(
\
((
_s
,
_t
),
w
)
->
w
>
thr
)
edges
filterGroupEdges
thr
edges
=
filter
(
\
((
_s
,
_t
),
w
)
->
w
>
thr
)
edges
-- | To get the neighbours (directed/undirected) of a PhyloGroup from a list of GroupEdges
-- | To get the neighbours (directed/undirected) of a PhyloGroup from a list of GroupEdges
getNeighbours
::
Bool
->
PhyloGroup
->
GroupEdges
->
[
PhyloGroup
]
getNeighbours
::
Bool
->
PhyloGroup
->
[
GroupEdge
]
->
[
PhyloGroup
]
getNeighbours
directed
g
e
=
case
directed
of
getNeighbours
directed
g
e
=
case
directed
of
True
->
map
(
\
((
_s
,
t
),
_w
)
->
t
)
True
->
map
(
\
((
_s
,
t
),
_w
)
->
t
)
$
filter
(
\
((
s
,
_t
),
_w
)
->
s
==
g
)
e
$
filter
(
\
((
s
,
_t
),
_w
)
->
s
==
g
)
e
...
@@ -686,6 +686,13 @@ getPeriodSteps q = q ^. q_periodSteps
...
@@ -686,6 +686,13 @@ getPeriodSteps q = q ^. q_periodSteps
-- | PhyloQueryBuild & PhyloQueryView Constructors | --
-- | PhyloQueryBuild & PhyloQueryView Constructors | --
--------------------------------------------------
--------------------------------------------------
-- | To get the threshold of a Proximity
getThreshold
::
Proximity
->
Double
getThreshold
prox
=
case
prox
of
WeightedLogJaccard
(
WLJParams
thr
_
)
->
thr
Hamming
(
HammingParams
thr
)
->
thr
Filiation
->
panic
"[ERR][Viz.Phylo.Tools.getThreshold] Filiation"
-- | To get the Proximity associated to a given Clustering method
-- | To get the Proximity associated to a given Clustering method
getProximity
::
Cluster
->
Proximity
getProximity
::
Cluster
->
Proximity
...
@@ -702,8 +709,11 @@ initFis (def True -> kmf) (def 1 -> min') (def 1 -> thr) = FisParams kmf min' th
...
@@ -702,8 +709,11 @@ initFis (def True -> kmf) (def 1 -> min') (def 1 -> thr) = FisParams kmf min' th
initHamming
::
Maybe
Double
->
HammingParams
initHamming
::
Maybe
Double
->
HammingParams
initHamming
(
def
0.01
->
sens
)
=
HammingParams
sens
initHamming
(
def
0.01
->
sens
)
=
HammingParams
sens
initSmallBranch'
::
Maybe
Int
->
Maybe
Int
->
Maybe
Int
->
SBParams
initSmallBranch'
(
def
2
->
periodsInf
)
(
def
2
->
periodsSup
)
(
def
1
->
minNodes
)
=
SBParams
periodsInf
periodsSup
minNodes
initSmallBranch
::
Maybe
Int
->
Maybe
Int
->
Maybe
Int
->
SBParams
initSmallBranch
::
Maybe
Int
->
Maybe
Int
->
Maybe
Int
->
SBParams
initSmallBranch
(
def
2
->
periodsInf
)
(
def
2
->
periodsSup
)
(
def
1
->
minNodes
)
=
SBParams
periodsInf
periodsSup
minNodes
initSmallBranch
(
def
0
->
periodsInf
)
(
def
0
->
periodsSup
)
(
def
1
->
minNodes
)
=
SBParams
periodsInf
periodsSup
minNodes
initLouvain
::
Maybe
Proximity
->
LouvainParams
initLouvain
::
Maybe
Proximity
->
LouvainParams
initLouvain
(
def
defaultWeightedLogJaccard
->
proxi
)
=
LouvainParams
proxi
initLouvain
(
def
defaultWeightedLogJaccard
->
proxi
)
=
LouvainParams
proxi
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment