Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
Netbone
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
coregraphie
Netbone
Commits
72000b32
Commit
72000b32
authored
2 years ago
by
Yassin
Browse files
Options
Downloads
Patches
Plain Diff
Updating modularity
parent
e9d10b96
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
netbone/structural/modulairy_backbone.py
+2
-7
2 additions, 7 deletions
netbone/structural/modulairy_backbone.py
with
2 additions
and
7 deletions
netbone/structural/modulairy_backbone.py
+
2
−
7
View file @
72000b32
import
community.community_louvain
as
community
import
community.community_louvain
as
community
import
heapq
import
heapq
import
operator
import
operator
import
math
import
networkx
as
nx
import
networkx
as
nx
import
numpy
as
np
import
numpy
as
np
from
scipy.sparse
import
csr_matrix
from
scipy.sparse
import
csr_matrix
...
@@ -29,7 +30,6 @@ def orderCommunities(c):
...
@@ -29,7 +30,6 @@ def orderCommunities(c):
return
partition
return
partition
def
communityInfo
(
c
,
partition
):
def
communityInfo
(
c
,
partition
):
print
(
'
Number of partitions:
'
,
len
(
partition
))
print
(
'
Number of partitions:
'
,
len
(
partition
))
l
=
list
()
l
=
list
()
...
@@ -43,9 +43,6 @@ def communityInfo(c, partition):
...
@@ -43,9 +43,6 @@ def communityInfo(c, partition):
print
()
print
()
print
()
print
()
def
getSparseA
(
g
):
def
getSparseA
(
g
):
return
nx
.
to_scipy_sparse_matrix
(
g
)
return
nx
.
to_scipy_sparse_matrix
(
g
)
# return nx.to_scipy_sparse_array(g)
# return nx.to_scipy_sparse_array(g)
...
@@ -163,18 +160,16 @@ def get_top_k_best_nodes(dict_centrality, k):
...
@@ -163,18 +160,16 @@ def get_top_k_best_nodes(dict_centrality, k):
return
top_k
,
first_nodes
return
top_k
,
first_nodes
def
modularity_backbone
(
data
,
node_fraction
):
def
modularity_backbone
(
data
,
node_fraction
):
is_graph
=
False
if
isinstance
(
data
,
pd
.
DataFrame
):
if
isinstance
(
data
,
pd
.
DataFrame
):
g
=
nx
.
from_pandas_edgelist
(
data
,
edge_attr
=
'
weight
'
,
create_using
=
nx
.
Graph
())
g
=
nx
.
from_pandas_edgelist
(
data
,
edge_attr
=
'
weight
'
,
create_using
=
nx
.
Graph
())
elif
isinstance
(
data
,
nx
.
Graph
):
elif
isinstance
(
data
,
nx
.
Graph
):
g
=
data
.
copy
()
g
=
data
.
copy
()
is_graph
=
True
else
:
else
:
print
(
"
data should be a panads dataframe or nx graph
"
)
print
(
"
data should be a panads dataframe or nx graph
"
)
return
return
g1
=
g
.
copy
()
g1
=
g
.
copy
()
k
=
len
(
g1
)
-
round
(
len
(
g1
)
*
node_fraction
)
k
=
len
(
g1
)
-
math
.
ceil
(
len
(
g1
)
*
node_fraction
)
communities
=
community
.
best_partition
(
g1
,
random_state
=
123
)
communities
=
community
.
best_partition
(
g1
,
random_state
=
123
)
modularity_value
=
community
.
modularity
(
communities
,
g1
)
modularity_value
=
community
.
modularity
(
communities
,
g1
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment