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
7adf6636
Commit
7adf6636
authored
Mar 31, 2020
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[ILouvain] fix HyperGraph' definition (and functions).
parent
c3c1e31e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
26 deletions
+35
-26
ILouvain.hs
src/Data/Graph/Clustering/ILouvain.hs
+35
-26
No files found.
src/Data/Graph/Clustering/ILouvain.hs
View file @
7adf6636
...
...
@@ -9,13 +9,12 @@ Portability : POSIX
ILouvain: really inductive Graph clustering with destructives updates
Metagraph:
metagraph (plural metagraphs) (mathematics) A graphical representation of a set of objects and the morphisms relating them
metagraph (plural metagraphs) (mathematics) A representation of a set of nodes and the morphisms relating them
https://en.wiktionary.org/wiki/metagraph
todo
FGL improvements:
- deg
should have return type
Maybe Int
- match
should be
Maybe (Context, Graph)
TODO
FGL improvements:
- deg
:: Graph gr => gr a b -> Node ->
Maybe Int
- match
:: Graph gr => Node -> gr a b ->
Maybe (Context, Graph)
-}
...
...
@@ -38,10 +37,10 @@ data NodePath = AllNodes | DfsNodes
-- MetaGraph (x,y) where x is space (hyper structure of labels), y is
-- time like (stream structure)
-- (Below LabGraph definition)
type
HyperGraph'
a
b
c
=
HyperGraph
(
HyperGraph
a
b
)
c
type
HyperGraph'
a
b
c
=
Gr
(
HyperGraph
a
b
)
c
type
HyperGraph
a
b
=
Gr
(
Gr
()
a
)
b
type
HyperContext
a
b
=
Context
(
Gr
()
a
)
b
type
HyperGraph
a
b
=
Gr
(
Gr
()
a
)
b
type
HyperContext
a
b
=
Context
(
Gr
()
a
)
b
-- TODO: EdgeGraph (StreamGraph)
-- type StreamGraph a b = Gr a (Gr () b)
...
...
@@ -59,7 +58,7 @@ iLouvain :: (Eq a, Show a)
iLouvain
0
s
p
g
=
g
iLouvain
n
s
p
g
|
length
(
toNodes
g'
)
<=
s
=
g'
|
otherwise
=
iLouvain'
p
g
g'
|
otherwise
=
iLouvain'
p
g
g'
where
g'
=
iLouvain
(
n
-
1
)
s
p
g
...
...
@@ -69,7 +68,7 @@ iLouvain' :: (Eq a, Show a)
->
HyperGraph
a
a
->
HyperGraph
a
a
->
HyperGraph
a
a
iLouvain'
p
g
g'
=
-- trace (show ps :: Text)
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
...
...
@@ -155,14 +154,19 @@ stepMax g g' x xs =
------------------------------------------------------------------------
class
IsHyperGraph
a
where
hnodes_
::
a
->
Node
->
[
Node
]
imodularity_
::
a
->
a
->
[
Node
]
->
Double
gmodularity_
::
a
->
a
->
Double
toHyperGraph_
::
Gr
()
Double
->
a
hnodes_
::
a
->
Node
->
[
Node
]
toNodes_
::
a
->
[[
Node
]]
mv_
::
a
->
[
Node
]
->
[
Node
]
->
a
-- flat is to HyperGraph what is empty to Graph
flat_
::
a
isFlat_
::
a
->
Bool
imodularity_
::
a
->
a
->
[
Node
]
->
Double
gmodularity_
::
a
->
a
->
Double
------------------------------------------------------------------------
hnodes
::
HyperGraph
a
b
->
Node
->
[
Node
]
hnodes
g
n
=
case
match
n
g
of
...
...
@@ -170,22 +174,24 @@ hnodes g n = case match n g of
(
Just
(
p
,
n
,
l
,
s
),
_
)
->
n
:
nodes
l
hnodes'
::
HyperGraph'
a
b
c
->
Node
->
[
Node
]
hnodes'
g
n
=
concat
$
map
(
hnodes
g
)
$
hnodes
g
n
hnodes'
g
n
=
case
match
n
g
of
(
Nothing
,
_
)
->
[]
(
Just
(
p
,
n
,
l
,
s
),
_
)
->
n
:
(
concat
$
map
(
hnodes
l
)
$
nodes
l
)
------------------------------------------------------------------------
toNodes
::
HyperGraph
a
a
->
[[
Node
]]
toNodes
g
=
map
(
hnodes
g
)
(
nodes
g
)
toNodes'
::
HyperGraph'
a
b
c
->
[[
Node
]]
toNodes'
g
=
map
(
hnodes'
g
)
(
nodes
g
)
------------------------------------------------------------------------
isFlat
::
HyperGraph
a
b
->
Bool
isFlat
g
=
all
(
isEmpty
.
snd
)
(
labNodes
g
)
-- flatten
{-
isFlat' :: HyperGraph' a b c-> Bool
isFlat' g = all (isFlat . concat . (map nodes) . snd) (labNodes g)
-}
-- needs of flatten?
isFlat'
::
HyperGraph'
a
b
c
->
Bool
isFlat'
g
=
all
(
isFlat
.
snd
)
(
labNodes
g
)
{-
...
...
@@ -193,6 +199,7 @@ hdeg :: Graph gr => gr a b -> Node -> Maybe Int
hdeg = undefined
-}
------------------------------------------------------------------------
------------------------------------------------------------------------
-- TODO go depth in HyperGraph (modularity at level/depth)
imodularity
::
HyperGraph
a
b
->
HyperGraph
a
a
->
[
Node
]
->
Double
imodularity
g
g'
ns
=
-- trace ("imodul" :: Text) $
...
...
@@ -207,14 +214,14 @@ imodularity' g g' ns =
$
fromList
$
concat
$
map
(
hnodes'
g'
)
ns
------------------------------------------------------------------------
gmodularity
::
HyperGraph
a
b
->
HyperGraph
a
a
->
Double
gmodularity
g
g'
=
sum
$
map
(
\
n
->
imodularity
g
g'
[
n
])
$
nodes
g'
gmodularity'
::
HyperGraph'
a
b
c
->
HyperGraph'
a
b
c
->
Double
gmodularity'
g
g'
=
sum
$
map
(
\
n
->
imodularity'
g
g'
[
n
])
$
nodes
g'
------------------------------------------------------------------------
------------------------------------------------------------------------
toHyperGraph
::
Gr
()
Double
->
HyperGraph
Double
Double
toHyperGraph
g
=
nmap
(
\
_
->
empty
)
g
...
...
@@ -222,6 +229,9 @@ toHyperGraph g = nmap (\_ -> empty) g
emptyHyperGraph
::
HyperGraph
Double
Double
emptyHyperGraph
=
toHyperGraph
empty
emptyHyperGraph'
::
HyperGraph'
Double
Double
Double
emptyHyperGraph'
=
undefined
{-
toHyperGraph' :: Gr () Double -> HyperGraph' Double Double Double
toHyperGraph' g = nmap (\_ -> emptyHyperGraph) g
...
...
@@ -306,9 +316,9 @@ mvMContext (Just (a1 ,n ,l ,a2 ))
where
c
=
(
a1
,
n
,
()
,
a2
)
mvMContext
_
(
Just
_
)
=
panic
"mv
mc
ontext: First Node does not exist"
mvMContext
(
Just
_
)
_
=
panic
"mv
mc
ontext: Snd Node does not exist"
mvMContext
_
_
=
panic
"mv
mc
ontext: Both Nodes do not exist"
mvMContext
_
(
Just
_
)
=
panic
"mv
MC
ontext: First Node does not exist"
mvMContext
(
Just
_
)
_
=
panic
"mv
MC
ontext: Snd Node does not exist"
mvMContext
_
_
=
panic
"mv
MC
ontext: Both Nodes do not exist"
merge
::
(
Graph
gr
,
DynGraph
gr
)
=>
gr
a
b
->
gr
a
b
->
gr
a
b
...
...
@@ -336,6 +346,5 @@ path g' = map sortNodes cs
path'
::
(
DynGraph
gr
,
Eq
b
)
=>
gr
a
b
->
[
Node
]
path'
=
maybe
[]
identity
.
head
.
path
------------------------------------------------------------------------
------------------------------------------------------------------------
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