Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Hit-Girl
code
Commits
7cf9b239
Commit
7cf9b239
authored
Feb 02, 2022
by
Jerome Wuerf
Browse files
Add graph analyzation
parent
7582599c
Changes
2
Hide whitespace changes
Inline
Side-by-side
notebooks/analyze_graphs.py
View file @
7cf9b239
# %%
import
pandas
as
pd
import
pickle
import
numpy
as
np
import
matplotlib
as
mpl
import
matplotlib.pyplot
as
plt
import
networkx
as
nx
...
...
@@ -15,43 +17,64 @@ argument_edges = pd.Series(
fig
,
(
ax1
,
ax2
)
=
plt
.
subplots
(
1
,
2
,
gridspec_kw
=
{
'width_ratios'
:
[
4
,
1
]},
figsize
=
(
10
,
5
))
fig
.
suptitle
(
'Argument Edges'
)
ax1
.
bar
(
argument_edges
.
index
,
argument_edges
)
ax1
.
set_xlabel
(
'Topic number'
)
ax1
.
set_ylabel
(
'# Edges'
)
ax2
.
boxplot
(
argument_edges
)
ax2
.
yaxis
.
set_ticklabels
([])
ax2
.
xaxis
.
set_ticklabels
([])
plt
.
savefig
(
'argument_edges.png'
)
# %%
fig
,
(
ax1
,
ax2
)
=
plt
.
subplots
(
1
,
2
,
gridspec_kw
=
{
'width_ratios'
:
[
4
,
1
]},
figsize
=
(
10
,
5
))
fig
.
suptitle
(
'Argument Nodes'
)
ax1
.
bar
(
argument_nodes
.
index
,
argument_nodes
)
ax2
.
boxplot
(
argument_nodes
)
ax1
.
set_xlabel
(
'Topic number'
)
ax1
.
set_ylabel
(
'# Nodes'
)
ax2
.
yaxis
.
set_ticklabels
([])
ax2
.
xaxis
.
set_ticklabels
([])
plt
.
savefig
(
'argument_nodes.png'
)
# %%
fig
,
axis
=
plt
.
subplots
(
5
,
10
,
figsize
=
(
15
,
10
))
for
ax
,
elem
in
zip
(
axis
.
flatten
(),
graphs
.
items
()):
fig
,
axis
=
plt
.
subplots
(
1
,
5
,
figsize
=
(
13
,
5
))
fig
.
suptitle
(
'Argument Graphs per Topic'
)
half_graphs
=
list
(
graphs
.
items
())[:
5
]
for
ax
,
elem
in
zip
(
axis
.
flatten
(),
half_graphs
):
topic_nrb
=
elem
[
0
]
g
=
elem
[
1
]
f
=
nx
.
Graph
()
fedges
=
filter
(
lambda
x
:
g
.
degree
()[
x
[
0
]]
>
0
and
g
.
degree
()[
x
[
1
]]
>
0
,
g
.
edges
())
f
.
add_edges_from
(
fedges
)
nx
.
draw
(
f
,
node_size
=
10
,
ax
=
ax
)
ax
.
set_title
(
topic_nrb
)
g
=
elem
[
1
].
to_undirected
()
Gcc
=
g
.
subgraph
(
sorted
(
nx
.
connected_components
(
g
),
key
=
len
,
reverse
=
True
)[
0
])
pos
=
nx
.
spring_layout
(
Gcc
,
seed
=
10396953
)
nx
.
draw_networkx_nodes
(
Gcc
,
pos
,
ax
=
ax
,
node_size
=
20
)
nx
.
draw_networkx_edges
(
Gcc
,
pos
,
ax
=
ax
,
alpha
=
0.4
)
plt
.
savefig
(
'argument_graphs.png'
)
# %%
len
(
graphs
)
# %%
ax
# %%
# %%
fig
,
axis
=
plt
.
subplots
(
5
,
10
,
figsize
=
(
20
,
10
))
fig
,
axis
=
plt
.
subplots
(
5
,
10
,
figsize
=
(
20
,
15
))
for
ax
,
elem
in
zip
(
axis
.
flatten
(),
graphs
.
items
()):
topic_nrb
=
elem
[
0
]
ax
.
set_title
(
topic_nrb
)
g
=
elem
[
1
]
f
=
nx
.
Graph
()
fedges
=
filter
(
lambda
x
:
g
.
degree
()[
x
[
0
]]
>
1
and
g
.
degree
()[
x
[
1
]]
>
1
,
g
.
edges
())
f
.
add_edges_from
(
fedges
)
ax
.
hist
(
nx
.
pagerank
(
f
).
values
())
# %%
degree_list
=
[
g
.
degree
()
for
g
in
graphs
.
values
()]
degree_list
=
[
item
[
1
]
for
sublist
in
degree_list
for
item
in
sublist
]
fig
,
ax
=
plt
.
subplots
()
ax
.
set_title
(
'Degrees Histogramm of Argument Graphs (all Topics)'
)
ax
.
set_yscale
(
'log'
)
ax
.
set_xlabel
(
"Degree"
)
ax
.
set_ylabel
(
"# of Nodes"
)
ax
.
hist
(
degree_list
)
plt
.
savefig
(
'degree_histogramm.png'
)
# %%
python/src/prototype/retrieval/argument_graph.py
View file @
7cf9b239
...
...
@@ -35,6 +35,8 @@ class ArgumentGraph:
premise_argument_id
=
premise
[
"_id"
].
split
(
'_'
)[
0
]
if
premise_argument_id
not
in
graph
:
graph
.
add_node
(
premise_argument_id
)
else
:
graph
.
nodes
[
premise_argument_id
][
'premises'
]
for
conc_idx
in
range
(
len
(
premises_per_conclusions
)):
sim
=
sim_matrices
[
conc_idx
][
prem_idx
]
if
sim
>=
self
.
threshold
:
...
...
Write
Preview
Supports
Markdown
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