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
Merge requests
!1
Adding new methods and the consensual backbone
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Adding new methods and the consensual backbone
dev
into
main
Overview
0
Commits
18
Pipelines
0
Changes
34
Merged
Ali Yassin
requested to merge
dev
into
main
1 year ago
Overview
0
Commits
18
Pipelines
0
Changes
1
Expand
Adding new methods and the consensual backbone
0
0
Merge request reports
Viewing commit
604c8a18
Prev
Next
Show latest version
1 file
+
56
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
604c8a18
Adding the GLANB Filter
· 604c8a18
Yassin
authored
1 year ago
netbone/statistical/glanb.py
0 → 100644
+
56
−
0
Options
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
'
)
Loading