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
1d1344ca
Commit
1d1344ca
authored
3 years ago
by
Laura Christine Kühle
Browse files
Options
Downloads
Patches
Plain Diff
Improved documentation of 'Plotting'.
parent
39ed488b
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Plotting.py
+67
-47
67 additions, 47 deletions
Plotting.py
with
67 additions
and
47 deletions
Plotting.py
+
67
−
47
View file @
1d1344ca
...
...
@@ -3,16 +3,22 @@
@author: Laura C. Kühle
TODO: Give option to select plotting color
TODO: Add documentation to plot_boxplot()
TODO: Adjust documentation for plot_classification_accuracy()
TODO: Add documentation to plot_boxplot()
-> Done
TODO: Adjust documentation for plot_classification_accuracy()
-> Done
"""
from
typing
import
Tuple
import
numpy
as
np
import
matplotlib
from
matplotlib
import
pyplot
as
plt
import
seaborn
as
sns
from
numpy
import
ndarray
from
sympy
import
Symbol
from
Quadrature
import
Quadrature
from
Initial_Condition
import
InitialCondition
matplotlib
.
use
(
'
Agg
'
)
x
=
Symbol
(
'
x
'
)
...
...
@@ -20,16 +26,17 @@ z = Symbol('z')
sns
.
set
()
def
plot_solution_and_approx
(
grid
,
exact
,
approx
,
color_exact
,
color_approx
):
""""
Plots approximate and exact solution against each other.
def
plot_solution_and_approx
(
grid
:
ndarray
,
exact
:
ndarray
,
approx
:
ndarray
,
color_exact
:
str
,
color_approx
:
str
)
->
None
:
"""
Plots approximate and exact solution against each other.
Parameters
----------
grid : n
p.
array
grid : n
d
array
List of mesh evaluation points.
exact : n
p.
array
exact : n
d
array
Array containing exact evaluation of a function.
approx : n
p.
array
approx : n
d
array
Array containing approximate evaluation of a function.
color_exact : str
String describing color to plot exact solution.
...
...
@@ -46,14 +53,14 @@ def plot_solution_and_approx(grid, exact, approx, color_exact, color_approx):
plt
.
title
(
'
Solution and Approximation
'
)
def
plot_semilog_error
(
grid
,
pointwise_error
)
:
"""
"
Plots semi-logarithmic error between approximate and exact solution.
def
plot_semilog_error
(
grid
:
ndarray
,
pointwise_error
:
ndarray
)
->
None
:
"""
Plots semi-logarithmic error between approximate and exact solution.
Parameters
----------
grid : n
p.
array
grid : n
d
array
List of mesh evaluation points.
pointwise_error : n
p.
array
pointwise_error : n
d
array
Array containing pointwise difference between exact and approximate solution.
"""
...
...
@@ -64,16 +71,16 @@ def plot_semilog_error(grid, pointwise_error):
plt
.
title
(
'
Semilog Error plotted at Evaluation points
'
)
def
plot_error
(
grid
,
exact
,
approx
)
:
"""
"
Plots error between approximate and exact solution.
def
plot_error
(
grid
:
ndarray
,
exact
:
ndarray
,
approx
:
ndarray
)
->
None
:
"""
Plots error between approximate and exact solution.
Parameters
----------
grid : n
p.
array
grid : n
d
array
List of mesh evaluation points.
exact : n
p.
array
exact : n
d
array
Array containing exact evaluation of a function.
approx : n
p.
array
approx : n
d
array
Array containing approximate evaluation of a function.
"""
...
...
@@ -84,8 +91,8 @@ def plot_error(grid, exact, approx):
plt
.
title
(
'
Errors
'
)
def
plot_shock_tube
(
num_grid_cells
,
troubled_cell_history
,
time_history
)
:
"""
"
Plots shock tube.
def
plot_shock_tube
(
num_grid_cells
:
int
,
troubled_cell_history
:
list
,
time_history
:
list
)
->
None
:
"""
Plots shock tube.
Plots detected troubled cells over time to depict the evolution of shocks as shock tubes.
...
...
@@ -95,7 +102,7 @@ def plot_shock_tube(num_grid_cells, troubled_cell_history, time_history):
Number of cells in the mesh. Usually exponential of 2.
troubled_cell_history : list
List of detected troubled cells for each time step.
time_history:
time_history:
list
List of value of each time step.
"""
...
...
@@ -110,21 +117,22 @@ def plot_shock_tube(num_grid_cells, troubled_cell_history, time_history):
plt
.
title
(
'
Shock Tubes
'
)
def
plot_details
(
fine_projection
,
fine_mesh
,
coarse_projection
,
basis
,
wavelet
,
multiwavelet_coeffs
,
num_coarse_grid_cells
,
polynomial_degree
):
""""
Plots details of projection to coarser mesh..
def
plot_details
(
fine_projection
:
ndarray
,
fine_mesh
:
ndarray
,
coarse_projection
:
ndarray
,
basis
:
ndarray
,
wavelet
:
ndarray
,
multiwavelet_coeffs
:
ndarray
,
num_coarse_grid_cells
:
int
,
polynomial_degree
:
int
)
->
None
:
"""
Plots details of projection to coarser mesh.
Parameters
----------
fine_projection, coarse_projection : n
p.
array
fine_projection, coarse_projection : n
d
array
Matrix of projection for each polynomial degree.
fine_mesh : n
p.
array
fine_mesh : n
d
array
List of evaluation points for fine mesh.
basis : n
p.
array
basis : n
d
array
Basis vector for calculation.
wavelet : n
p.
array
wavelet : n
d
array
Wavelet vector for calculation.
multiwavelet_coeffs : n
p.
array
multiwavelet_coeffs : n
d
array
Matrix of multiwavelet coefficients.
num_coarse_grid_cells : int
Number of cells in the coarse mesh (half the cells of the fine mesh).
...
...
@@ -157,23 +165,24 @@ def plot_details(fine_projection, fine_mesh, coarse_projection, basis, wavelet,
plt
.
title
(
'
Wavelet Coefficients
'
)
def
calculate_approximate_solution
(
projection
,
points
,
polynomial_degree
,
basis
):
def
calculate_approximate_solution
(
projection
:
ndarray
,
points
:
ndarray
,
polynomial_degree
:
int
,
basis
:
ndarray
)
->
ndarray
:
"""
Calculates approximate solution.
Parameters
----------
projection : n
p.
array
projection : n
d
array
Matrix of projection for each polynomial degree.
points : n
p.
array
points : n
d
array
List of evaluation points for mesh.
polynomial_degree : int
Polynomial degree.
basis : n
p.
array
basis : n
d
array
Basis vector for calculation.
Returns
-------
n
p.
array
n
d
array
Array containing approximate evaluation of a function.
"""
...
...
@@ -190,13 +199,14 @@ def calculate_approximate_solution(projection, points, polynomial_degree, basis)
return
np
.
reshape
(
np
.
array
(
approx
),
(
1
,
len
(
approx
)
*
num_points
))
def
calculate_exact_solution
(
mesh
,
cell_len
,
wave_speed
,
final_time
,
interval_len
,
quadrature
,
init_cond
):
def
calculate_exact_solution
(
mesh
:
ndarray
,
cell_len
:
float
,
wave_speed
:
float
,
final_time
:
float
,
interval_len
:
float
,
quadrature
:
Quadrature
,
init_cond
:
InitialCondition
)
->
Tuple
[
ndarray
,
ndarray
]:
"""
Calculates exact solution.
Parameters
----------
mesh : array
mesh :
nd
array
List of mesh valuation points.
cell_len : float
Length of a cell in mesh.
...
...
@@ -213,7 +223,9 @@ def calculate_exact_solution(mesh, cell_len, wave_speed, final_time, interval_le
Returns
-------
np.array
grid: ndarray
Array containing evaluation grid for a function.
exact: ndarray
Array containing exact evaluation of a function.
"""
...
...
@@ -239,21 +251,17 @@ def calculate_exact_solution(mesh, cell_len, wave_speed, final_time, interval_le
return
grid
,
exact
def
plot_classification_accuracy
(
evaluation_dict
,
colors
)
:
def
plot_classification_accuracy
(
evaluation_
dict
:
dict
,
colors
:
dict
)
->
None
:
"""
Plots classification accuracy.
Plots
the accuracy, precision, and recall in a bar plot
.
Plots
given evaluation measures in a bar plot for each model
.
Parameters
----------
precision : float
Precision of classification.
recall : float
Recall of classification.
accuracy : float
Accuracy of classification.
xlabels : list
List of strings for x-axis labels.
evaluation_dict: dict
Dictionary containing classification evaluation data.
colors: dict
Dictionary containing plotting colors.
"""
model_names
=
evaluation_dict
[
list
(
colors
.
keys
())[
0
]].
keys
()
...
...
@@ -277,7 +285,19 @@ def plot_classification_accuracy(evaluation_dict, colors):
ax
.
legend
(
loc
=
'
upper right
'
)
def
plot_boxplot
(
evaluation_dict
,
colors
):
def
plot_boxplot
(
evaluation_dict
:
dict
,
colors
:
dict
)
->
None
:
"""
Plots classification accuracy.
Plots given evaluation measures in a boxplot for each model.
Parameters
----------
evaluation_dict: dict
Dictionary containing classification evaluation data.
colors: dict
Dictionary containing plotting colors.
"""
model_names
=
evaluation_dict
[
list
(
colors
.
keys
())[
0
]].
keys
()
font_size
=
16
-
(
len
(
max
(
model_names
,
key
=
len
))
//
3
)
fig
=
plt
.
figure
(
'
boxplot_accuracy
'
)
...
...
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