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
70dd7b5e
Commit
70dd7b5e
authored
3 years ago
by
Laura Christine Kühle
Browse files
Options
Downloads
Patches
Plain Diff
Restructured '_generate_cell_data()' and improved comments for it.
parent
8d5bdee9
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
ANN_Data_Generator.py
+19
-28
19 additions, 28 deletions
ANN_Data_Generator.py
with
19 additions
and
28 deletions
ANN_Data_Generator.py
+
19
−
28
View file @
70dd7b5e
...
...
@@ -2,7 +2,7 @@
"""
@author: Soraya Terrab (sorayaterrab), Laura C. Kühle
TODO: Improve
'
_generate_cell_data
'
TODO: Improve
'
_generate_cell_data
'
-> Done
TODO: Extract normalization (Combine smooth and troubled before normalizing) -> Done
TODO: Adapt code to generate both normalized and non-normalized data -> Done
TODO: Improve verbose output -> Done
...
...
@@ -91,59 +91,50 @@ class TrainingDataGenerator(object):
input_data
=
np
.
zeros
((
num_samples
,
self
.
_stencil_length
+
2
))
num_init_cond
=
len
(
initial_conditions
)
count
=
0
for
i
in
range
(
num_samples
):
#
Pick a Function here
#
Select and initialize initial condition
function_id
=
i
%
num_init_cond
initial_condition
=
initial_conditions
[
function_id
][
'
function
'
]
initial_condition
.
randomize
(
initial_conditions
[
function_id
][
'
config
'
])
# Create basis_coefficients for function mapped onto stencil
polynomial_degree
=
np
.
random
.
randint
(
1
,
high
=
5
)
# Calculating Cell centers for a given 1D domain with n elements, and
# Calculating Corresponding Legendre Basis Coefficients for given polynomial_degree
# Create stencil and basis_coefficients for smooth_function mapped onto stencil
interval
,
centers
,
h
=
self
.
_build_stencil
()
# Build random stencil of given length
interval
,
centers
,
spacing
=
self
.
_build_stencil
()
left_bound
,
right_bound
=
interval
centers
=
[
center
[
0
]
for
center
in
centers
]
initial_condition
.
induce_adjustment
(
-
h
[
0
]
/
3
)
# Induce adjustment to capture troubled cells
adjustment
=
0
if
initial_condition
.
is_smooth
else
centers
[
self
.
_stencil_length
//
2
]
initial_condition
.
induce_adjustment
(
-
spacing
[
0
]
/
3
)
left_bound
,
right_bound
=
interval
# Calculate basis coefficients for stencil
polynomial_degree
=
np
.
random
.
randint
(
1
,
high
=
5
)
dg_scheme
=
DG_Approximation
.
DGScheme
(
'
NoDetection
'
,
polynomial_degree
=
polynomial_degree
,
num_grid_cells
=
self
.
_stencil_length
,
left_bound
=
left_bound
,
right_bound
=
right_bound
,
quadrature
=
'
Gauss
'
,
quadrature_config
=
{
'
num_eval_points
'
:
polynomial_degree
+
1
})
if
initial_condition
.
is_smooth
():
input_data
[
i
]
=
dg_scheme
.
build_training_data
(
0
,
self
.
_stencil_length
,
initial_condition
)
else
:
input_data
[
i
]
=
dg_scheme
.
build_training_data
(
centers
[
self
.
_stencil_length
//
2
],
self
.
_stencil_length
,
initial_condition
)
input_data
[
i
]
=
dg_scheme
.
build_training_data
(
adjustment
,
initial_condition
)
count
+=
1
if
count
%
100
==
0
:
if
count
%
100
0
==
0
:
print
(
str
(
count
)
+
'
samples completed.
'
)
toc
=
timeit
.
default_timer
()
print
(
'
Finished calculating data
'
+
troubled_indicator
+
'
troubled cells!
'
)
print
(
'
Calculation time:
'
,
toc
-
tic
,
'
\n
'
)
# Shuffle input data
order
=
np
.
random
.
permutation
(
num_samples
)
input_data
=
input_data
[
order
]
# Set output data
output_data
=
np
.
zeros
((
num_samples
,
2
))
if
is_smooth
:
output_data
[:,
1
]
=
np
.
ones
(
num_samples
)
else
:
output_data
[:,
0
]
=
np
.
ones
(
num_samples
)
output_index
=
1
if
is_smooth
else
0
output_data
[:,
output_index
]
=
np
.
ones
(
num_samples
)
return
input_data
,
output_data
def
_build_stencil
(
self
):
# Calculating Cell centers for a given 1D domain with n elements, and
# Calculating Corresponding Legendre Basis Coefficients for given polynomial_degree
# Create stencil and basis_coefficients for smooth_function mapped onto stencil
# Determining grid_spacing
grid_spacing
=
2
/
(
2
**
np
.
random
.
randint
(
3
,
high
=
9
,
size
=
1
))
...
...
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