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
48a784c1
Commit
48a784c1
authored
2 years ago
by
Yassin
Browse files
Options
Downloads
Patches
Plain Diff
Updating df and lans filters
parent
dc405d1a
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
netbone/statistical/disparity.py
+41
-17
41 additions, 17 deletions
netbone/statistical/disparity.py
netbone/statistical/lans.py
+19
-9
19 additions, 9 deletions
netbone/statistical/lans.py
netbone/visualize.py
+1
-1
1 addition, 1 deletion
netbone/visualize.py
with
61 additions
and
27 deletions
netbone/statistical/disparity.py
+
41
−
17
View file @
48a784c1
import
networkx
as
nx
import
numpy
as
np
from
scipy
import
integrate
import
pandas
as
pd
from
netbone.backbone
import
Backbone
from
netbone.filters
import
threshold_filter
,
fraction_filter
def
disparity
(
G
:
nx
.
Graph
)
->
Backbone
:
weight
=
'
weight
'
G
=
G
.
copy
()
B
=
nx
.
Graph
()
for
u
in
G
:
k
=
len
(
G
[
u
])
if
k
>
1
:
sum_w
=
sum
(
np
.
absolute
(
G
[
u
][
v
][
weight
])
for
v
in
G
[
u
])
for
v
in
G
[
u
]:
w
=
G
[
u
][
v
][
weight
]
p_ij
=
float
(
np
.
absolute
(
w
))
/
sum_w
alpha_ij
=
1
-
\
(
k
-
1
)
*
integrate
.
quad
(
lambda
x
:
(
1
-
x
)
**
(
k
-
2
),
0
,
p_ij
)[
0
]
# float('%.4f' % alpha_ij)
B
.
add_edge
(
u
,
v
,
weight
=
w
,
p_value
=
float
(
alpha_ij
))
return
Backbone
(
B
,
name
=
"
Disparity Filter
"
,
column
=
"
p_value
"
,
ascending
=
True
,
filters
=
[
threshold_filter
,
fraction_filter
])
\ No newline at end of file
def
disparity
(
data
,
weight
=
'
weight
'
):
if
isinstance
(
data
,
pd
.
DataFrame
):
g
=
nx
.
from_pandas_edgelist
(
data
,
edge_attr
=
'
weight
'
,
create_using
=
nx
.
Graph
())
elif
isinstance
(
data
,
nx
.
Graph
):
g
=
data
.
copy
()
else
:
print
(
"
data should be a panads dataframe or nx graph
"
)
return
strength
=
g
.
degree
(
weight
=
weight
)
for
node
in
g
.
nodes
():
k
=
g
.
degree
[
node
]
if
k
>
1
:
for
neighbour
in
g
[
node
]:
w
=
float
(
g
[
node
][
neighbour
][
'
weight
'
])
p_ij
=
w
/
strength
[
node
]
alpha_ij
=
(
1
-
p_ij
)
**
(
k
-
1
)
if
'
alpha
'
in
g
[
node
][
neighbour
]:
if
alpha_ij
<
g
[
node
][
neighbour
][
'
alpha
'
]:
g
[
node
][
neighbour
][
'
alpha
'
]
=
alpha_ij
else
:
g
[
node
][
neighbour
][
'
alpha
'
]
=
alpha_ij
return
Backbone
(
g
,
name
=
"
Disparity Filter
"
,
column
=
"
p_value
"
,
ascending
=
True
,
filters
=
[
threshold_filter
,
fraction_filter
])
# b = nx.Graph()
# for u in g:
# k = len(g[u])
# if k > 1:
# sum_w = sum(np.absolute(g[u][v][weight]) for v in g[u])
# for v in g[u]:
# w = g[u][v][weight]
# p_ij = float(np.absolute(w))/sum_w
# alpha_ij = 1 - \
# (k-1) * integrate.quad(lambda x: (1-x)
# ** (k-2), 0, p_ij)[0]
# # float('%.4f' % alpha_ij)
# b.add_edge(u, v, weight=w, p_value=float(alpha_ij))
# return Backbone(b, name="Disparity Filter", column="p_value", ascending=True, filters=[threshold_filter, fraction_filter])
This diff is collapsed.
Click to expand it.
netbone/statistical/lans.py
+
19
−
9
View file @
48a784c1
import
networkx
as
nx
import
pandas
as
pd
from
netbone.backbone
import
Backbone
from
netbone.filters
import
threshold_filter
,
fraction_filter
def
lans
(
G
:
nx
.
Graph
)
->
Backbone
:
G
=
G
.
copy
()
for
u
,
v
,
w
in
G
.
edges
(
data
=
'
weight
'
):
G
[
u
][
v
][
'
p_value
'
]
=
min
(
compute_pvalue
(
G
,
v
,
w
),
compute_pvalue
(
G
,
u
,
w
))
return
Backbone
(
G
,
name
=
"
Locally Adaptive Network Sparsification Filter
"
,
column
=
"
p_value
"
,
ascending
=
True
,
filters
=
[
threshold_filter
,
fraction_filter
])
def
lans
(
data
):
if
isinstance
(
data
,
pd
.
DataFrame
):
g
=
nx
.
from_pandas_edgelist
(
data
,
edge_attr
=
'
weight
'
,
create_using
=
nx
.
Graph
())
elif
isinstance
(
data
,
nx
.
Graph
):
g
=
data
.
copy
()
else
:
print
(
"
data should be a panads dataframe or nx graph
"
)
return
for
u
,
v
,
w
in
g
.
edges
(
data
=
'
weight
'
):
g
[
u
][
v
][
'
p_value
'
]
=
min
(
compute_pvalue
(
g
,
v
,
w
),
compute_pvalue
(
g
,
u
,
w
))
return
Backbone
(
g
,
name
=
"
Locally Adaptive Network Sparsification Filter
"
,
column
=
"
p_value
"
,
ascending
=
True
,
filters
=
[
threshold_filter
,
fraction_filter
])
def
compute_pvalue
(
G
,
node
,
w
):
u_degree
=
G
.
degree
(
node
,
weight
=
'
weight
'
)
puv
=
w
/
u_degree
puv
=
w
/
u_degree
u_n
=
G
[
node
]
count
=
len
([
n
for
n
in
u_n
if
u_n
[
n
][
'
weight
'
]
/
u_degree
<=
puv
])
return
1
-
count
/
len
(
u_n
)
\ No newline at end of file
count
=
len
([
n
for
n
in
u_n
if
u_n
[
n
][
'
weight
'
]
/
u_degree
<=
puv
])
return
1
-
count
/
len
(
u_n
)
This diff is collapsed.
Click to expand it.
netbone/visualize.py
+
1
−
1
View file @
48a784c1
...
...
@@ -214,7 +214,7 @@ def plot_radar(graph_properties, title):
radar
.
use_legend
(
loc
=
'
center left
'
,
bbox_to_anchor
=
(
1.04
,
0.5
),
ncol
=
1
)
plt
.
show
()
fig
.
savefig
(
title
+
'
props
'
,
bbox_inches
=
'
tight
'
,
dpi
=
300
)
fig
.
savefig
(
title
+
'
prop
ertie
s
'
,
bbox_inches
=
'
tight
'
,
dpi
=
300
)
def
plot_distribution
(
df
,
title
):
...
...
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