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
604c8a18
Commit
604c8a18
authored
2 years ago
by
Yassin
Browse files
Options
Downloads
Patches
Plain Diff
Adding the GLANB Filter
parent
89c62155
No related branches found
No related tags found
1 merge request
!1
Adding new methods and the consensual backbone
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
netbone/statistical/glanb.py
+56
-0
56 additions, 0 deletions
netbone/statistical/glanb.py
with
56 additions
and
0 deletions
netbone/statistical/glanb.py
0 → 100644
+
56
−
0
View file @
604c8a18
import
networkx
as
nx
import
igraph
as
ig
import
pandas
as
pd
from
netbone.backbone
import
Backbone
from
netbone.filters
import
threshold_filter
,
fraction_filter
def
count_included_subarrays
(
arrays
,
target_array
):
count
=
0
target_len
=
len
(
target_array
)
for
array
in
arrays
:
array_len
=
len
(
array
)
for
i
in
range
(
array_len
-
target_len
+
1
):
if
array
[
i
:
i
+
target_len
]
==
target_array
:
count
+=
1
return
count
def
glanb
(
data
,
**
kwargs
):
if
isinstance
(
data
,
pd
.
DataFrame
):
graph
=
nx
.
from_pandas_edgelist
(
data
,
edge_attr
=
'
weight
'
,
create_using
=
nx
.
Graph
())
elif
isinstance
(
data
,
nx
.
Graph
):
graph
=
data
.
copy
()
else
:
print
(
"
data should be a panads dataframe or nx graph
"
)
return
c
=
-
1
for
key
,
value
in
kwargs
.
items
():
if
key
==
'
c
'
:
c
=
int
(
value
)
if
c
==
-
1
:
print
(
"
Please send the c value
"
)
return
# convert weights to distances
wes
=
nx
.
get_edge_attributes
(
graph
,
'
weight
'
)
values
=
{
pair
:
1
/
wes
[
pair
]
for
pair
in
wes
}
nx
.
set_edge_attributes
(
graph
,
values
,
name
=
'
distance
'
)
node_labels
=
dict
(
zip
(
graph
.
nodes
(),
range
(
len
(
graph
))))
igraph
=
ig
.
Graph
.
from_networkx
(
graph
)
for
source
in
graph
.
nodes
():
k_i
=
graph
.
degree
[
source
]
if
k_i
>
1
:
ig_paths
=
igraph
.
get_all_shortest_paths
(
node_labels
[
source
],
weights
=
'
distance
'
)
for
u
,
v
in
graph
.
edges
(
source
):
g_ij
=
count_included_subarrays
(
ig_paths
,
[
node_labels
[
u
],
node_labels
[
v
]])
g_is
=
len
(
ig_paths
)
-
1
I_ij
=
(
g_ij
/
g_is
)
S_ij
=
(
1
-
I_ij
)
**
((
k_i
-
1
)
**
c
)
if
'
SI
'
in
graph
[
u
][
v
]:
if
S_ij
<
graph
[
u
][
v
][
'
SI
'
]:
graph
[
u
][
v
][
'
SI
'
]
=
S_ij
else
:
graph
[
u
][
v
][
'
SI
'
]
=
S_ij
return
Backbone
(
graph
,
method_name
=
"
Globally and Locally Adaptive Backbone Filter
"
,
property_name
=
"
SI
"
,
ascending
=
True
,
compatible_filters
=
[
threshold_filter
,
fraction_filter
],
filter_on
=
'
Edges
'
)
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