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
3ff5ede6
Commit
3ff5ede6
authored
Aug 3, 2021
by
Laura Christine Kühle
Browse files
Options
Downloads
Patches
Plain Diff
Removed Training_Data.py.
parent
6ffcc9f1
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
Training_Data.py
+0
-219
0 additions, 219 deletions
Training_Data.py
with
0 additions
and
219 deletions
Training_Data.py
deleted
100644 → 0
+
0
−
219
View file @
6ffcc9f1
# -*- coding: utf-8 -*-
"""
@author: Laura C. Kühle
TODO: Contemplate how y should look like
\
(number cells?, number entries in wavelet coeffs?)
TODO: Investigate how to set fixed input size
\
(Hesthaven
'
s method?, Each size seperatly?)
TODO: Create seperate files for different dofs
TODO: Investigate whether real TCs are correct
TODO: Contemplate giving the option to adjust fixed arguments -> No
TODO: Contemplate creating training set for each init_cond seperately
TODO: Adjust factor and x0 for argument check
TODO: Investigate what step_val means? step value?
"""
import
numpy
as
np
import
os
from
DG_Approximation
import
DGScheme
class
TrainingData
():
def
__init__
(
self
,
**
kwargs
):
self
.
_reset
()
self
.
list_init_cond
=
kwargs
.
pop
(
'
init_cond
'
,
[
1
])
# , 2, 3, 4, 5, 6])
self
.
list_num_grid_cell
=
kwargs
.
pop
(
'
num_grid_cells
'
,
[
4
,
8
,
16
,
32
,
64
])
self
.
list_wave_speed
=
kwargs
.
pop
(
'
wave_speed
'
,
[
5
])
# , 1, 0.5, -0.5, -1, -5])
self
.
list_factor
=
kwargs
.
pop
(
'
factor
'
,
[
0.5
,
1
,
2
,
25
])
self
.
list_x0s
=
kwargs
.
pop
(
'
x0
'
,
[
0
,
-
1
/
3
,
2
/
3
,
-
1
/
2
])
def
_reset
(
self
):
# Set fixed arguments for DG Scheme
self
.
detector_config
=
{}
# =============================================================================
# self.fold_len = 16
# self.whisker_len = 3
#
# self.detector_config['fold_len'] = self.fold_len
# self.detector_config['whisker_len'] = self.whisker_len
# =============================================================================
self
.
init_config
=
{}
# =============================================================================
# self.init_config['factor'] = 4
# self.init_config['left_factor'] = 3
# =============================================================================
self
.
limiter_config
=
{}
# =============================================================================
# self.limiter_config['mod_factor'] = 5
# =============================================================================
self
.
quadrature_config
=
{}
# =============================================================================
# self.quadrature_config['num_eval_points'] = 12
# =============================================================================
self
.
detector
=
'
NoDetection
'
self
.
stability_method
=
'
SSPRK3
'
self
.
init_cond
=
'
InitialCondition2
'
self
.
limiter
=
'
ModifiedMinMod
'
self
.
quadrature
=
'
Gauss
'
self
.
cfl_number
=
0.2
self
.
left_bound
=
-
1
self
.
right_bound
=
1
self
.
interval_len
=
self
.
right_bound
-
self
.
left_bound
# Set up necessary variables for creating training data
self
.
X_train
=
[]
self
.
y_train
=
[]
self
.
wave_speed
=
0
self
.
polynom_degree
=
2
self
.
num_grid_cells
=
0
self
.
final_time
=
0
self
.
list_init_cond
=
None
self
.
list_num_grid_cell
=
None
self
.
list_wave_speed
=
None
self
.
list_factor
=
None
self
.
list_x0s
=
None
self
.
troubled_cells
=
None
self
.
mesh
=
None
# Set path for plot files if not existing already
if
not
os
.
path
.
exists
(
'
data
'
):
os
.
makedirs
(
'
data
'
)
def
create_training_dataset
(
self
):
for
self
.
num_grid_cells
in
self
.
list_num_grid_cell
:
print
(
'
Check out the grid cell number:
'
+
str
(
self
.
num_grid_cells
))
for
self
.
init_cond
in
self
.
list_init_cond
:
print
(
'
Starting now with InitialCondition
'
+
str
(
self
.
init_cond
)
+
'
!
'
)
for
self
.
wave_speed
in
self
.
list_wave_speed
:
print
(
'
Let us also check the wave speed:
'
+
str
(
self
.
wave_speed
))
for
self
.
final_time
in
np
.
arange
(
0
,
5
,
2.5
):
# 0.25):
print
(
'
And the time:
'
+
str
(
self
.
final_time
))
if
self
.
list_factor
is
not
None
:
for
self
.
factor
in
self
.
list_factor
:
self
.
init_config
[
'
factor
'
]
=
self
.
factor
self
.
_add_datapoint
()
self
.
init_config
.
pop
(
'
factor
'
,
None
)
print
(
'
Check-in!
'
)
if
self
.
list_x0s
is
not
None
:
for
self
.
x0
in
self
.
list_x0s
:
self
.
init_config
[
'
x0
'
]
=
self
.
x0
self
.
_add_datapoint
()
self
.
init_config
.
pop
(
'
x0
'
,
None
)
print
(
'
Check-in!
'
)
if
((
self
.
list_factor
is
None
)
and
(
self
.
list_x0s
is
None
)):
self
.
_add_datapoint
()
self
.
X_train
=
np
.
array
(
self
.
X_train
)
self
.
y_train
=
np
.
array
(
self
.
y_train
)
print
(
self
.
X_train
.
shape
)
# print(self.X_train.reshape(16, -1).shape)
# val_X = self.X_train.copy()
# val_y = self.y_train.copy()
# =============================================================================
# for i in self.X_train:
# print(np.array(i).shape)
# # print(len(i[0]), i)
#
# =============================================================================
# print(np.array(self.X_train).shape)
# =============================================================================
# training_data = {
# 'X_train': np.array(self.X_train),
# 'y_train': np.array(self.y_train),
# 'X_val': np.array(val_X),
# 'y_val': np.array(val_y),
# }
# =============================================================================
# print(training_data)
np
.
savetxt
(
'
data/TrainingData_X_
'
+
str
(
self
.
num_grid_cells
)
+
'
_
'
+
str
(
self
.
polynom_degree
)
+
'
.csv
'
,
self
.
X_train
,
delimiter
=
'
,
'
)
np
.
savetxt
(
'
data/TrainingData_y_
'
+
str
(
self
.
num_grid_cells
)
+
'
_
'
+
str
(
self
.
polynom_degree
)
+
'
.csv
'
,
self
.
y_train
,
delimiter
=
'
,
'
)
self
.
X_train
=
[]
self
.
y_train
=
[]
return
# training_data
def
_add_datapoint
(
self
):
dg_scheme
=
DGScheme
(
self
.
detector
,
detector_config
=
self
.
detector_config
,
init_cond
=
'
InitialCondition
'
+
str
(
self
.
init_cond
),
init_config
=
self
.
init_config
,
limiter
=
self
.
limiter
,
limiter_config
=
self
.
limiter_config
,
quadrature
=
self
.
quadrature
,
quadrature_config
=
self
.
quadrature_config
,
stability_method
=
self
.
stability_method
,
wave_speed
=
self
.
wave_speed
,
polynom_degree
=
self
.
polynom_degree
,
cfl_number
=
self
.
cfl_number
,
num_grid_cells
=
self
.
num_grid_cells
,
final_time
=
self
.
final_time
,
show_plot
=
False
,
left_bound
=
self
.
left_bound
,
right_bound
=
self
.
right_bound
)
__
,
self
.
mesh
,
__
,
data
=
dg_scheme
.
approximate
()
# print(np.array(data).shape)
# data = np.array(data).reshape((3, -1))
# print(type(data), data)
# print(data.shape, data[0].shape)
# print(data[0])
self
.
troubled_cells
=
np
.
zeros_like
(
data
[
0
])
if
not
(((
self
.
init_cond
==
1
)
&
(
self
.
factor
!=
0.5
))
|
((
self
.
init_cond
==
3
)
&
(
self
.
factor
!=
1
))):
self
.
_set_troubled_cells
(
1
)
if
((
self
.
init_cond
==
5
)
|
(
self
.
init_cond
==
5
)):
self
.
_set_troubled_cells
(
0
)
if
(
self
.
init_cond
==
6
):
self
.
_set_troubled_cells
(
self
.
x0
)
# print(self.troubled_cells)
self
.
X_train
.
append
(
np
.
array
(
data
).
flatten
())
self
.
y_train
.
append
(
self
.
troubled_cells
)
def
_set_troubled_cells
(
self
,
real_troubled_cell
):
step_val
=
1
-
self
.
wave_speed
*
self
.
final_time
\
+
np
.
floor
(
self
.
wave_speed
*
self
.
final_time
/
self
.
interval_len
)
\
*
self
.
interval_len
pos
=
np
.
where
(
self
.
mesh
==
min
(
self
.
mesh
,
key
=
lambda
x
:
abs
(
real_troubled_cell
-
step_val
)))
pos
=
int
(
int
(
pos
[
0
])
/
2
)
if
step_val
in
self
.
mesh
:
self
.
troubled_cells
[
pos
-
1
]
=
1
self
.
troubled_cells
[
pos
]
=
1
print
(
'
Creating TrainingData instance...
'
)
trainer
=
TrainingData
()
print
(
'
Done!
'
)
print
(
'
Creating training data...
'
)
test_data
=
trainer
.
create_training_dataset
()
print
(
'
Done!
'
)
# print(np.array(test_data['X_train']).shape)
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