Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Troubled Cell Detection
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Laura Christine Kühle
Troubled Cell Detection
Commits
36a09681
Commit
36a09681
authored
Dec 7, 2021
by
Laura Christine Kühle
Browse files
Options
Downloads
Patches
Plain Diff
Added option to select colors for classification plots.
parent
36f233b4
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
ANN_Training.py
+9
-8
9 additions, 8 deletions
ANN_Training.py
Plotting.py
+8
-8
8 additions, 8 deletions
Plotting.py
Snakefile
+3
-1
3 additions, 1 deletion
Snakefile
config.yaml
+7
-1
7 additions, 1 deletion
config.yaml
with
27 additions
and
18 deletions
ANN_Training.py
+
9
−
8
View file @
36a09681
...
...
@@ -156,11 +156,12 @@ def read_training_data(directory):
return
TensorDataset
(
*
map
(
torch
.
tensor
,
(
np
.
load
(
input_file
),
np
.
load
(
output_file
))))
def
evaluate_models
(
models
,
directory
,
num_iterations
=
100
,
measures
=
None
):
if
measures
is
None
:
measures
=
[
'
Accuracy
'
,
'
Precision
'
,
'
Recall
'
,
'
F-Score
'
,
'
AUROC
'
]
def
evaluate_models
(
models
,
directory
,
num_iterations
=
100
,
colors
=
None
):
if
colors
is
None
:
colors
=
{
'
Accuracy
'
:
'
red
'
,
'
Precision
'
:
'
yellow
'
,
'
Recall
'
:
'
blue
'
,
'
F-Score
'
:
'
green
'
,
'
AUROC
'
:
'
purple
'
}
dataset
=
read_training_data
(
directory
)
classification_stats
=
{
measure
:
{
model
:
[]
for
model
in
models
}
for
measure
in
measure
s
}
classification_stats
=
{
measure
:
{
model
:
[]
for
model
in
models
}
for
measure
in
color
s
}
for
iteration
in
range
(
num_iterations
):
for
train_index
,
test_index
in
KFold
(
n_splits
=
5
,
shuffle
=
True
).
split
(
dataset
):
# print("TRAIN:", train_index, "TEST:", test_index)
...
...
@@ -169,13 +170,13 @@ def evaluate_models(models, directory, num_iterations=100, measures=None):
for
model
in
models
:
result
=
models
[
model
].
test_model
(
training_set
,
test_set
)
for
measure
in
measure
s
:
for
measure
in
color
s
:
classification_stats
[
measure
][
model
].
append
(
result
[
measure
])
plot_boxplot
(
models
.
keys
(),
classification_stats
)
plot_boxplot
(
classification_stats
,
colors
)
classification_stats
=
{
measure
:
{
model
:
np
.
array
(
classification_stats
[
measure
][
model
]).
mean
()
for
model
in
models
}
for
measure
in
measure
s
}
plot_classification_accuracy
(
models
.
keys
(),
classification_stats
)
for
model
in
models
}
for
measure
in
color
s
}
plot_classification_accuracy
(
classification_stats
,
colors
)
# Set paths for plot files if not existing already
plot_dir
=
directory
+
'
/model evaluation
'
...
...
This diff is collapsed.
Click to expand it.
Plotting.py
+
8
−
8
View file @
36a09681
...
...
@@ -4,6 +4,7 @@
TODO: Give option to select plotting color
TODO: Improve classification plotting -> Done
TODO: Give option to select classification color -> Done
TODO: Add documentation to plot_boxplot()
"""
...
...
@@ -190,7 +191,7 @@ def calculate_approximate_solution(projection, points, polynomial_degree, basis)
def
calculate_exact_solution
(
mesh
,
cell_len
,
wave_speed
,
final_time
,
interval_len
,
quadrature
,
init_cond
):
"""
"
Calculates exact solution.
"""
Calculates exact solution.
Parameters
----------
...
...
@@ -237,7 +238,7 @@ def calculate_exact_solution(mesh, cell_len, wave_speed, final_time, interval_le
return
grid
,
exact
def
plot_classification_accuracy
(
model_names
,
evaluation_dict
):
def
plot_classification_accuracy
(
evaluation_dict
,
colors
):
"""
Plots classification accuracy.
Plots the accuracy, precision, and recall in a bar plot.
...
...
@@ -254,6 +255,7 @@ def plot_classification_accuracy(model_names, evaluation_dict):
List of strings for x-axis labels.
"""
model_names
=
evaluation_dict
[
list
(
colors
.
keys
())[
0
]].
keys
()
pos
=
np
.
arange
(
len
(
model_names
))
width
=
1
/
(
3
*
len
(
model_names
))
fig
=
plt
.
figure
(
'
classification_accuracy
'
)
...
...
@@ -262,7 +264,7 @@ def plot_classification_accuracy(model_names, evaluation_dict):
adjustment
=
-
(
len
(
model_names
)
//
2
)
*
step_len
for
measure
in
evaluation_dict
:
model_eval
=
[
evaluation_dict
[
measure
][
model
]
for
model
in
evaluation_dict
[
measure
]]
ax
.
bar
(
pos
+
adjustment
*
width
,
model_eval
,
width
,
label
=
measure
)
ax
.
bar
(
pos
+
adjustment
*
width
,
model_eval
,
width
,
label
=
measure
,
color
=
colors
[
measure
]
)
adjustment
+=
step_len
ax
.
set_xticks
(
pos
)
ax
.
set_xticklabels
(
model_names
)
...
...
@@ -274,7 +276,8 @@ def plot_classification_accuracy(model_names, evaluation_dict):
# fig.tight_layout()
def
plot_boxplot
(
model_names
,
evaluation_dict
):
def
plot_boxplot
(
evaluation_dict
,
colors
):
model_names
=
evaluation_dict
[
list
(
colors
.
keys
())[
0
]].
keys
()
fig
=
plt
.
figure
(
'
boxplot_accuracy
'
)
ax
=
fig
.
add_axes
([
0.15
,
0.1
,
0.75
,
0.8
])
step_len
=
1.5
...
...
@@ -282,16 +285,13 @@ def plot_boxplot(model_names, evaluation_dict):
adjustment
=
-
(
len
(
model_names
)
//
2
)
*
step_len
pos
=
np
.
arange
(
len
(
model_names
))
width
=
1
/
(
5
*
len
(
model_names
))
colors
=
[
'
red
'
,
'
yellow
'
,
'
blue
'
,
'
tan
'
,
'
green
'
]
count
=
0
for
measure
in
evaluation_dict
:
model_eval
=
[
evaluation_dict
[
measure
][
model
]
for
model
in
evaluation_dict
[
measure
]]
boxplot
=
ax
.
boxplot
(
model_eval
,
positions
=
pos
+
adjustment
*
width
,
widths
=
width
,
meanline
=
True
,
showmeans
=
True
,
patch_artist
=
True
)
for
patch
in
boxplot
[
'
boxes
'
]:
patch
.
set
(
facecolor
=
colors
[
count
])
patch
.
set
(
facecolor
=
colors
[
measure
])
boxplots
.
append
(
boxplot
)
count
+=
1
adjustment
+=
step_len
ax
.
set_xticks
(
pos
)
...
...
This diff is collapsed.
Click to expand it.
Snakefile
+
3
−
1
View file @
36a09681
...
...
@@ -25,13 +25,15 @@ rule test_model:
DIR+'/log/test_model.log'
output:
DIR+'/model evaluation/classification_accuracy/' + '_'.join(MODELS.keys()) + '.pdf'
params:
colors = config['classification_colors']
run:
models = {}
for model in MODELS:
trainer= ANN_Training.ModelTrainer({'model_name': model, 'dir': DIR,
'model_dir': DIR, **MODELS[model]})
models[model] = trainer
evaluate_models(models, DIR, 2)
evaluate_models(models, DIR, 2
, params.colors
)
rule generate_data:
output:
...
...
This diff is collapsed.
Click to expand it.
config.yaml
+
7
−
1
View file @
36a09681
...
...
@@ -23,7 +23,13 @@ functions:
HeavisideTwoSided
:
adjustment
:
0
# Parameter for Model Training
# Parameter for Model Training and Evaluation
classification_colors
:
Accuracy
:
'
magenta'
Precision
:
'
red'
Recall
:
'
tan'
F-Score
:
'
green'
AUROC
:
'
yellow'
models
:
Adam
:
num_epochs
:
1000
...
...
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