Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
142
Issues
142
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
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
purescript-gargantext
Commits
532e2cd0
Commit
532e2cd0
authored
Jan 09, 2020
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Graph] louvain.js small fixes, Louvain/Algorithm.purs added
parent
51818eb6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
91 additions
and
3 deletions
+91
-3
Louvain.js
src/Gargantext/Data/Louvain.js
+5
-3
Algorithm.purs
src/Gargantext/Data/Louvain/Algorithm.purs
+86
-0
No files found.
src/Gargantext/Data/Louvain.js
View file @
532e2cd0
...
@@ -28,6 +28,8 @@ exports._jLouvain = (function(){
...
@@ -28,6 +28,8 @@ exports._jLouvain = (function(){
};
};
function
obj_values
(
obj
){
function
obj_values
(
obj
){
return
Object
.
values
(
obj
);
/*
var vals = [];
var vals = [];
for( var key in obj ) {
for( var key in obj ) {
if ( obj.hasOwnProperty(key) ) {
if ( obj.hasOwnProperty(key) ) {
...
@@ -35,10 +37,11 @@ exports._jLouvain = (function(){
...
@@ -35,10 +37,11 @@ exports._jLouvain = (function(){
}
}
}
}
return vals;
return vals;
*/
};
};
function
get_degree_for_node
(
graph
,
node
){
function
get_degree_for_node
(
graph
,
node
){
var
neighbours
=
g
raph
.
_assoc_mat
[
node
]
?
Object
.
keys
(
graph
.
_assoc_mat
[
node
])
:
[]
;
var
neighbours
=
g
et_neighbours_of_node
(
graph
,
node
)
;
var
weight
=
0
;
var
weight
=
0
;
neighbours
.
forEach
(
function
(
neighbour
,
i
){
neighbours
.
forEach
(
function
(
neighbour
,
i
){
var
value
=
graph
.
_assoc_mat
[
node
][
neighbour
]
||
1
;
var
value
=
graph
.
_assoc_mat
[
node
][
neighbour
]
||
1
;
...
@@ -53,8 +56,7 @@ exports._jLouvain = (function(){
...
@@ -53,8 +56,7 @@ exports._jLouvain = (function(){
if
(
typeof
graph
.
_assoc_mat
[
node
]
==
'undefined'
)
if
(
typeof
graph
.
_assoc_mat
[
node
]
==
'undefined'
)
return
[];
return
[];
var
neighbours
=
Object
.
keys
(
graph
.
_assoc_mat
[
node
]);
return
Object
.
keys
(
graph
.
_assoc_mat
[
node
]);
return
neighbours
;
}
}
...
...
src/Gargantext/Data/Louvain/Algorithm.purs
0 → 100644
View file @
532e2cd0
module Gargantext.Data.Louvain.Algorithm where
import Data.Foldable (sum)
import Data.Map as Map
import Data.Maybe (Maybe(..))
import Data.Sequence as Seq
import Data.Set as Set
import Data.Tuple (Tuple(..))
import Prelude ((&&), (==), ($), (<$>), class Eq, class Ord)
newtype Cluster = Cluster String
newtype Node = Node String
derive instance eqNode :: Eq Node
derive instance ordNode :: Ord Node
newtype Edge = Edge {
source :: Node
, target :: Node
, weight :: Number
}
newtype Graph = Graph {
edges :: Seq.Seq Edge
, nodes :: Seq.Seq Node
}
newtype Status = Status {
--degrees
--gdegrees
--internals
--loops
--nodesToCom ::
totalWeight :: Number
}
newtype Dendrogram = Dendrogram (Map.Map Node Cluster)
-- edge helpers
eSource :: Edge -> Node
eSource (Edge {source}) = source
eTarget :: Edge -> Node
eTarget (Edge {target}) = target
eWeight :: Edge -> Number
eWeight (Edge {weight}) = weight
-- graph helpers
gEdges :: Graph -> Seq.Seq Edge
gEdges (Graph {edges}) = edges
gNodes :: Graph -> Seq.Seq Node
gNodes (Graph {nodes}) = nodes
getGraphSize :: Graph -> Number
getGraphSize g = sum $ Seq.map eWeight $ gEdges g
getEdgeWeight :: Graph -> Node -> Node -> Maybe Number
getEdgeWeight g n1 n2 = eWeight <$> Seq.head edges
where
edges = Seq.filter (\e -> eSource e == n1 && eTarget e == n2) (gEdges g)
getNeighboursOfNode :: Graph -> Node -> Seq.Seq Node
getNeighboursOfNode g n = Seq.fromFoldable $ Set.union sources targets
where
edges = gEdges g
sourceEdges = Seq.filter (\e -> eSource e == n) edges
targetEdges = Seq.filter (\e -> eTarget e == n) edges
-- edge target, when edge source matches n
sources = Set.fromFoldable $ Seq.map eTarget sourceEdges
-- edge source, when edge target matches n
targets = Set.fromFoldable $ Seq.map eSource targetEdges
-- TODO algorithm
initStatus :: Graph -> Status -> Maybe Dendrogram -> Status
initStatus g s Nothing = Status {totalWeight}
where
totalWeight = getGraphSize g
initStatus g s (Just d) = Status {totalWeight}
where
totalWeight = getGraphSize g
generateDendrogram :: Graph -> Dendrogram -> Dendrogram
generateDendrogram g partInit =
if Seq.null (gEdges g) then
Dendrogram $ Map.fromFoldable $ Seq.map (\n@(Node ns) -> Tuple n (Cluster ns)) (gNodes g)
else
Dendrogram $ Map.empty
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