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
c75e7b68
Commit
c75e7b68
authored
Mar 26, 2020
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FLouvain] some refactoring
parent
2e1077dd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
4 deletions
+7
-4
Example.hs
src/Data/Graph/Clustering/Example.hs
+1
-0
FLouvain.hs
src/Data/Graph/Clustering/FLouvain.hs
+6
-4
No files found.
src/Data/Graph/Clustering/Example.hs
View file @
c75e7b68
...
...
@@ -19,6 +19,7 @@ exampleRemap gr = gmap remap gr
-- | Run FLouvain.iterate on an example graph
-- Example call:
-- putStrLn $ prettify $ iterateOnce cuiller
-- Prelude.map (fst3 . unCommunity . snd) $ labNodes $ iterateOnce karate
iterateOnce
::
Gr
()
Double
->
CGr
iterateOnce
gr
=
iteration
fgr
cgr
where
...
...
src/Data/Graph/Clustering/FLouvain.hs
View file @
c75e7b68
...
...
@@ -98,6 +98,8 @@ newtype Weight = Weight { unWeight :: Double }
type
FEdge
b
=
(
Weight
,
b
)
fedgeWeight
::
FEdge
b
->
Double
fedgeWeight
=
unWeight
.
fst
sumEdgeWeights
::
Adj
(
FEdge
b
)
->
Double
sumEdgeWeights
es
=
sum
$
map
(
fedgeWeight
.
fst
)
es
type
FGraph
a
b
=
Gr
a
(
FEdge
b
)
-- Used for k_i in formula (2)
...
...
@@ -143,7 +145,7 @@ type CGr = Gr Community ()
graphWeight
::
FGraph
a
b
->
GraphWeightSum
graphWeight
gr
=
GraphWeightSum
$
ufold
weight'
0
gr
where
weight'
(
p
,
_
,
_
,
s
)
acc
=
acc
+
sum
(
map
(
fedgeWeight
.
fst
)
$
p
<>
s
)
weight'
(
p
,
_
,
_
,
s
)
acc
=
acc
+
(
sumEdgeWeights
$
p
<>
s
)
-- | Compute initial 'CGr' for a given 'FGraph a b'. This means, put each node
-- in a separate community.
...
...
@@ -163,7 +165,7 @@ initialCGr gr = gmap singletonCom gr
-- no internal links
iws
=
InWeightSum
0.0
-- just sum over the edges coming into/out of node v
tws
=
TotWeightSum
$
sum
$
map
(
fedgeWeight
.
fst
)
edges
tws
=
TotWeightSum
$
sum
EdgeWeights
edges
-- ALGORITHM
...
...
@@ -178,7 +180,7 @@ delta com ki kiin m = DeltaQ $ acc - dec
where
inWeightSum
=
comInWeightSum
com
totWeightSum
=
comTotWeightSum
com
acc
=
accL
-
accR
*
accR
acc
=
accL
-
accR
*
accR
accL
=
0.5
*
(
unInWeightSum
inWeightSum
+
2.0
*
(
unNodeComWeightSum
kiin
))
/
(
unGraphWeightSum
m
)
accR
=
0.5
*
(
unTotWeightSum
totWeightSum
+
unNodeWeightSum
ki
)
/
(
unGraphWeightSum
m
)
dec
=
decL
-
decM
*
decM
-
decR
*
decR
...
...
@@ -196,7 +198,7 @@ delta com ki kiin m = DeltaQ $ acc - dec
-- We could avoid the higher complexity, eg. by precomputing the whole graph
-- into a HashMap Node [Edge].
iteration
::
FGraph
a
b
->
CGr
->
CGr
iteration
gr
cs
=
xdfsFoldWith
suc'
(
\
(
_
,
v
,
_
,
_
)
->
step
gw
$
context
gr
$
v
)
cs
(
nodes
gr
)
gr
iteration
gr
cs
=
xdfsFoldWith
suc'
(
\
(
_
,
v
,
_
,
_
)
->
step
gw
$
context
gr
v
)
cs
(
nodes
gr
)
gr
where
gw
=
graphWeight
gr
--weightSum = ufold weightSum' 0 gr
...
...
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