Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
clustering-louvain
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
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
gargantext
clustering-louvain
Commits
ea8646e5
Commit
ea8646e5
authored
Mar 30, 2020
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[ILouvain] ineighbors
parent
ef7e8303
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
27 deletions
+35
-27
ILouvain.hs
src/Data/Graph/Clustering/ILouvain.hs
+35
-27
No files found.
src/Data/Graph/Clustering/ILouvain.hs
View file @
ea8646e5
...
...
@@ -16,6 +16,7 @@ module Data.Graph.Clustering.ILouvain
import
Debug.SimpleReflect
import
Data.Set
(
fromList
)
import
qualified
Data.Set
as
Set
import
Data.Maybe
(
catMaybes
,
maybe
)
import
Data.List
(
zip
,
cycle
,
null
)
import
Protolude
hiding
(
empty
,
(
&
))
...
...
@@ -42,37 +43,43 @@ isFlat g = all (isEmpty . snd) (labNodes g)
iLouvain
::
(
Eq
a
,
Show
a
)
=>
Int
->
NodePath
->
HyperGraph
a
a
->
HyperGraph
a
a
iLouvain
0
p
g
=
g
iLouvain
n
p
g
=
iLouvain'
p
g
(
iLouvain
(
n
-
1
)
p
g
)
iLouvain
n
p
g
=
trace
(
show
$
toNodes
g
::
Text
)
$
iLouvain'
p
g
(
iLouvain
(
n
-
1
)
p
g
)
iLouvain'
::
(
Eq
a
,
Show
a
)
=>
NodePath
->
HyperGraph
a
a
->
HyperGraph
a
a
->
HyperGraph
a
a
iLouvain'
p
g
g'
=
iLouvain''
g
$
filter
(
\
n
->
elem
n
(
nodes
g
))
ps
where
-- quick trick to filter path but path of HyperGraph can be different
-- ps = nodes g0
ps
=
if
isFlat
g'
then
case
p
of
AllNodes
->
nodes
g
DfsNodes
->
path'
g
else
reverse
$
sortOn
(
Down
.
length
.
hnodes
g'
)
$
nodes
g
iLouvain'
p
g
g'
=
trace
(
show
ps
::
Text
)
iLouvain''
g
g'
ps
-- $ filter (\n -> elem n (nodes g)) ps
where
-- quick trick to filter path but path of HyperGraph can be different
ps
=
if
isFlat
g'
then
case
p
of
AllNodes
->
nodes
g
DfsNodes
->
path'
g
else
sortOn
(
length
.
hnodes
g'
)
(
nodes
g'
)
iLouvain''
::
Show
a
=>
HyperGraph
a
a
->
HyperGraph
a
a
->
[
Node
]
->
HyperGraph
a
a
iLouvain''
g
[ ]
=
g
iLouvain''
g
[
_
]
=
g
iLouvain''
g
ns
=
foldl'
(
\
g1
n
->
step
g
g1
n
$
filter
(
\
m
->
elem
m
(
nodes
g1
))
$
neighbors
g
n
)
g
ns
-- /!\ Above fixes possible error
-- g1 has holes in network (case below):
-- iLouvain'' g ns = foldl' (\g1 n -> step' g g1 n $ neighbors g1 n) g ns
iLouvain''
g
g'
[ ]
=
g'
iLouvain''
g
g'
ns
=
foldl'
(
\
g1
n
->
step
g
g1
n
$
ineighbors
g1
n
)
g'
ns
-- | ineihbors Definition
-- TODO optim sort by jackard
ineighbors
::
HyperGraph
a
a
->
Node
->
[
Node
]
ineighbors
g
n
=
case
isEmpty
g
of
True
->
neighbors
g
n
False
->
filter
(
\
m
->
Set
.
null
(
Set
.
intersection
(
fromList
$
hnodes
g
m
)
n'
)
&&
m
/=
n
)
(
nodes
g
)
where
n'
=
H
.
exclusion
candidates
(
fromList
ns
)
candidates
=
fromList
$
concat
$
map
(
neighbors
g
)
ns
ns
=
hnodes
g
n
step
::
Show
a
=>
HyperGraph
a
b
...
...
@@ -92,10 +99,10 @@ step' :: Show a
->
Node
->
Node
->
HyperGraph
a
a
step'
g
g'
n1
n2
=
-- trace ("step
"
:: Text) $
--
if s2 > 0 && s2 >= s1
if
s2
>=
s1
then
-- trace ("step:mv"
:: Text) $
step'
g
g'
n1
n2
=
-- trace ("step
" <> show n1 <> " " <> show n2
:: Text) $
if
s2
>
0
&&
s2
>=
s1
--
if s2 >= s1
then
trace
(
"step:mv "
<>
show
n1
<>
" "
<>
show
n2
::
Text
)
$
mv
g'
[
n1
]
[
n2
]
else
-- trace ("step:else" :: Text) $
g'
...
...
@@ -105,13 +112,13 @@ step' g g' n1 n2 = -- trace ("step" :: Text) $
s2
=
-- trace ("step:mod2" :: Text) $
imodularity
g
[
n1
,
n2
]
step
B
::
Show
a
step
Max
::
Show
a
=>
HyperGraph
a
b
->
HyperGraph
a
a
->
Node
->
[
Node
]
->
HyperGraph
a
a
step
B
g
g'
n
ns
=
snd
step
Max
g
g'
n
ns
=
snd
$
maximumBy
(
\
(
n1
,
g1
)
(
n2
,
g2
)
->
compare
(
imodularity
g
[
n1
])
(
imodularity
g
[
n2
]))
gs
where
gs
=
(
n
,
g'
)
:
map
(
\
m
->
(
m
,
mv
g'
[
n
]
[
m
]))
ns
...
...
@@ -161,7 +168,7 @@ spoon = mkGraph ns es
,
(
4
,
5
,
1.0
)
]
-- | Needed function
s (WIP)
-- | Needed function
-- mv: a Node elsewhere in the HyperGraph
-- Move Properties:
...
...
@@ -227,6 +234,7 @@ merge = ufold (&)
------------------------------------------------------------------------
test_mv
::
(
Ord
a
,
Show
a
)
=>
HyperGraph
a
a
->
Node
->
Node
->
Bool
test_mv
g
a
b
=
(
mv
(
mv
g
[
a
]
[
b
])
[
b
,
a
]
[]
)
==
g
------------------------------------------------------------------------
-- Paths in the Graph to be tested
-- Directed graph strategy
...
...
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