Skip to content
Snippets Groups Projects
Commit 70dd7b5e authored by Laura Christine Kühle's avatar Laura Christine Kühle
Browse files

Restructured '_generate_cell_data()' and improved comments for it.

parent 8d5bdee9
No related branches found
No related tags found
No related merge requests found
......@@ -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 % 1000 == 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))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment