Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ExplainGNNWithHighLevelConcepts
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ajay Umakanth
ExplainGNNWithHighLevelConcepts
Commits
b3333a2b
There was an error fetching the commit references. Please try again later.
Commit
b3333a2b
authored
6 months ago
by
AjUm-HEIDI
Browse files
Options
Downloads
Patches
Plain Diff
Update the summary file
parent
af9df659
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
structured_datasets_experiment.py
+47
-10
47 additions, 10 deletions
structured_datasets_experiment.py
with
47 additions
and
10 deletions
structured_datasets_experiment.py
+
47
−
10
View file @
b3333a2b
...
...
@@ -25,7 +25,7 @@ def explain_gnn(model, dataset, datasetName, run_dir, add_node_type, high_level_
generate_new_owl_file
=
True
,
ignore_nodes
=
False
,
high_level_concepts
=
high_level_concepts
,
create_high_level_concepts_as_boolean
=
Tru
e
,
create_high_level_concepts_as_boolean
=
Fals
e
,
add_node_type
=
add_node_type
)
...
...
@@ -134,9 +134,9 @@ def experiment(datasetName: str, add_node_type = True, iterations: int = 1):
for
row
in
cm
:
writer
.
writerow
(
row
)
#
#
Explain GNN before finding motifs
#
print("\nBefore finding motifs:")
#
explain_gnn(model, structuredDataset.dataset, datasetName, run_dir, add_node_type)
# Explain GNN before finding motifs
print
(
"
\n
Before finding motifs:
"
)
explain_gnn
(
model
,
structuredDataset
.
dataset
,
datasetName
,
run_dir
,
add_node_type
)
print
(
"
\n
Detecting motifs...
"
)
patterns
,
presence_matrix
=
structuredDataset
.
detect_motifs
(
visualizationPath
=
run_dir
)
...
...
@@ -145,8 +145,7 @@ def experiment(datasetName: str, add_node_type = True, iterations: int = 1):
print
(
"
\n
Detected motifs...
"
)
structuredDataset
.
visualize_patterns
()
graph_indices_to_visualize
=
[
1
,
2
,
5
,
7
,
9
,
# Label 0
10
,
11
,
12
,
14
,
15
]
# Label 1
graph_indices_to_visualize
=
[
1
,
2
,
5
,
7
,
9
,
10
,
11
,
12
,
14
,
15
]
print
(
f
"
Visualizing graphs:
{
graph_indices_to_visualize
}
"
)
graph_visualization_dir
=
structuredDataset
.
visualize_graphs
(
graph_indices_to_visualize
)
if
graph_visualization_dir
:
...
...
@@ -178,23 +177,61 @@ def experiment(datasetName: str, add_node_type = True, iterations: int = 1):
"
Label
"
:
label
,
"
MotifsAdded
"
:
motif_added
,
"
BestHypothesis
"
:
row
[
"
BestHypothesis
"
],
"
Quality
"
:
float
(
row
[
"
Quality
"
]),
"
Length
"
:
int
(
row
[
"
Length
"
]),
"
F1
"
:
float
(
row
[
"
F1
"
]),
"
Accuracy
"
:
float
(
row
[
"
Accuracy
"
]),
"
Recall
"
:
float
(
row
[
"
Recall
"
]),
"
Precision
"
:
float
(
row
[
"
Precision
"
])
}
# Update if current result is better
key
=
(
label
,
motif_added
)
if
key
not
in
best_results
or
current_result
[
"
Quality
"
]
>
best_results
[
key
][
"
Quality
"
]:
if
key
not
in
best_results
or
current_result
[
"
F1
"
]
>
best_results
[
key
][
"
F1
"
]:
best_results
[
key
]
=
current_result
print
(
f
"
Results for iteration
{
iteration
+
1
}
saved in
{
run_dir
}
"
)
# Write the best results for each label and motif combination to the parent directory
with
open
(
results
/
f
"
best_results_by_label_and_motif.csv
"
,
"
w
"
,
newline
=
""
)
as
f
:
writer
=
csv
.
DictWriter
(
f
,
fieldnames
=
[
"
Label
"
,
"
MotifsAdded
"
,
"
Iteration
"
,
"
BestHypothesis
"
,
"
Quality
"
,
"
Length
"
])
fieldnames
=
[
"
Label
"
,
"
MotifsAdded
"
,
"
Iteration
"
,
"
Best F1 Score
"
,
"
Length at Best F1
"
,
"
Average F1 Score
"
,
"
Best Accuracy
"
,
"
Average Accuracy
"
,
"
Average Length
"
,
"
Best Hypothesis
"
]
writer
=
csv
.
DictWriter
(
f
,
fieldnames
=
fieldnames
)
writer
.
writeheader
()
# Compute aggregated metrics for each label and motif combination
for
(
label
,
motif_added
),
result
in
best_results
.
items
():
if
result
is
not
None
:
writer
.
writerow
(
result
)
# Identify all results for this label/motif combination
all_results
=
[
r
for
(
lbl
,
mot
),
r
in
best_results
.
items
()
if
lbl
==
label
and
mot
==
motif_added
]
# Compute averages
avg_f1
=
sum
(
r
[
"
F1
"
]
for
r
in
all_results
)
/
len
(
all_results
)
avg_accuracy
=
sum
(
r
[
"
Accuracy
"
]
for
r
in
all_results
)
/
len
(
all_results
)
avg_length
=
sum
(
r
[
"
Length
"
]
for
r
in
all_results
)
/
len
(
all_results
)
# Determine the result with the highest F1 score
best_result
=
max
(
all_results
,
key
=
lambda
r
:
r
[
"
F1
"
])
# Write the best result to the CSV
writer
.
writerow
({
"
Label
"
:
label
,
"
MotifsAdded
"
:
motif_added
,
"
Iteration
"
:
best_result
[
"
Iteration
"
],
"
Best F1 Score
"
:
best_result
[
"
F1
"
],
"
Length at Best F1
"
:
best_result
[
"
Length
"
],
"
Average F1 Score
"
:
avg_f1
,
"
Best Accuracy
"
:
best_result
[
"
Accuracy
"
],
"
Average Accuracy
"
:
avg_accuracy
,
"
Average Length
"
:
avg_length
,
"
Best Hypothesis
"
:
best_result
[
"
BestHypothesis
"
],
})
print
(
f
"
All iterations for
{
datasetName
}
completed. Best results saved in
{
results
/
'
best_results_by_label_and_motif.csv
'
}
"
)
...
...
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