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

Adapted docstring to uniform standard.

parent bea05f67
Branches
No related tags found
No related merge requests found
......@@ -13,7 +13,7 @@ import DG_Approximation
class TrainingDataGenerator(object):
"""Class for training data generator.
Generate random training data for given initial conditions.
Generates random training data for given initial conditions.
Attributes
----------
......@@ -26,7 +26,7 @@ class TrainingDataGenerator(object):
Methods
-------
build_training_data()
build_training_data(num_samples)
Builds random training data.
"""
......@@ -151,14 +151,14 @@ class TrainingDataGenerator(object):
Number of training data samples to generate.
initial_conditions : list
List of names of initial conditions for training.
is_smooth : boolean
is_smooth : bool
Flag whether initial conditions are smooth.
Returns
-------
input_data : np.array
input_data : ndarray
Array containing input data.
output_data : np.array
output_data : ndarray
Array containing output data.
"""
......@@ -215,9 +215,9 @@ class TrainingDataGenerator(object):
Returns
-------
interval : np.array
interval : ndarray
List containing left and right bound of interval.
stencil : np.array
stencil : ndarray
List of cell centers in stencil.
grid_spacing : float
Length of cell in grid.
......@@ -244,16 +244,16 @@ class TrainingDataGenerator(object):
@staticmethod
def _normalize_data(input_data):
"""Normalize data.
"""Normalizes data.
Parameters
----------
input_data : np.array
input_data : ndarray
Array containing input data.
Returns
-------
np.array
ndarray
Array containing normalized input data.
"""
......
......@@ -28,6 +28,13 @@ class ThreeLayerReLu(torch.nn.Module):
output_layer : torch.nn.Module
Activation layer for output calculation.
Methods
-------
forward(input_data)
Executes forward propagation.
get_name()
Returns string of model name.
"""
def __init__(self, config):
"""Initializes ThreeLayerReLu.
......
......@@ -12,7 +12,8 @@ TODO: Write-protect all data and models
TODO: Put legend outside plot (bbox_to_anchor)
TODO: Put plotting into separate function
TODO: Reduce number of testing epochs to 50
TODO: Adapt docstring to uniform standard
TODO: Adapt docstring to uniform standard -> Done
TODO: Change maximal line length to 79 (as advised by PEP8)
"""
import numpy as np
......@@ -50,11 +51,11 @@ class ModelTrainer(object):
Methods
-------
epoch_training()
epoch_training(dataset, num_epochs, verbose)
Trains model for a given number of epochs.
test_model()
test_model(training_set, test_set)
Evaluates predictions of a model.
save_model()
save_model(directory, model_name)
Saves state and validation loss of a model.
"""
......@@ -121,7 +122,7 @@ class ModelTrainer(object):
dataset : torch.utils.data.dataset.TensorDataset
Training dataset.
num_epochs : int, optional
Number of epochs for training. If None, set to instance value. Default: None.
Number of epochs for training. Default: None (i.e. instance variable).
verbose : bool, optional
Flag whether commentary in console is wanted. Default: False.
......
......@@ -17,9 +17,9 @@ class Vector(object):
Attributes
----------
basis : np.array
basis : ndarray
Array of basis.
wavelet : np.array
wavelet : ndarray
Array of wavelet.
Methods
......@@ -61,7 +61,7 @@ class Vector(object):
Returns
-------
np.array
ndarray
Vector containing basis evaluated at evaluation point.
"""
......@@ -81,7 +81,7 @@ class Vector(object):
Returns
-------
np.array
ndarray
Vector containing wavelet evaluated at evaluation point.
"""
......@@ -108,7 +108,7 @@ class Legendre(Vector):
Returns
-------
np.array
ndarray
Vector containing basis evaluated at evaluation point.
"""
......@@ -124,7 +124,7 @@ class Legendre(Vector):
Returns
-------
np.array
ndarray
Vector containing Legendre polynomial evaluated at evaluation point.
"""
......@@ -163,7 +163,7 @@ class OrthonormalLegendre(Legendre):
Returns
-------
np.array
ndarray
Vector containing basis evaluated at evaluation point.
"""
......@@ -181,7 +181,7 @@ class OrthonormalLegendre(Legendre):
Returns
-------
np.array
ndarray
Vector containing wavelet evaluated at evaluation point.
Notes
......@@ -227,7 +227,7 @@ class OrthonormalLegendre(Legendre):
Returns
-------
np.array
ndarray
Array containing the basis projection based on the integrals of the product
of two basis vectors for each degree combination.
......@@ -248,7 +248,7 @@ class OrthonormalLegendre(Legendre):
Returns
-------
np.array
ndarray
Matrix containing the integral of basis products.
"""
......@@ -268,7 +268,7 @@ class OrthonormalLegendre(Legendre):
Returns
-------
np.array
ndarray
Array containing the multiwavelet projection based on the integrals of the product
of a basis vector and a wavelet vector for each degree combination.
......@@ -286,12 +286,12 @@ class OrthonormalLegendre(Legendre):
First parameter.
second_param : float
Second parameter.
is_left_matrix : boolean
is_left_matrix : bool
Flag whether the left matrix is calculated.
Returns
-------
np.array
ndarray
Matrix containing the integral of products of a basis and a wavelet vector.
"""
......
......@@ -25,6 +25,7 @@ TODO: Add way of saving data (np.savez('data/' + name,
TODO: Outsource scripts into separate directory
TODO: Allow comparison between ANN training datasets
TODO: Add a default model state
TODO: Add type annotations to function heads
"""
import os
......@@ -59,9 +60,9 @@ class DGScheme(object):
Length of a cell in mesh.
basis : Basis object
Basis for calculation.
mesh : array
mesh : ndarray
List of mesh valuation points.
inv_mass : np.array
inv_mass : ndarray
Inverse mass matrix.
Methods
......@@ -98,8 +99,8 @@ class DGScheme(object):
Left boundary of interval. Default: -1.
right_bound : float, optional
Right boundary of interval. Default: 1.
verbose : boolean, optional
Flag whether commentary in console is wanted. Default: False
verbose : bool, optional
Flag whether commentary in console is wanted. Default: False.
plot_dir : str, optional
Path to directory in which plots are saved. Default: 'test'.
history_threshold : float, optional
......@@ -218,6 +219,11 @@ class DGScheme(object):
Sets plot directory, if not already existing, and saves plots generated during the last
approximation.
Parameters
----------
plot_name : str
Name of plot.
"""
# Set paths for plot files if not existing already
if not os.path.exists(self._plot_dir):
......@@ -273,7 +279,7 @@ class DGScheme(object):
Returns
-------
np.array
ndarray
Matrix containing projection of size (N+2, p+1) with N being the number of grid cells
and p being the polynomial degree.
......@@ -323,7 +329,7 @@ class DGScheme(object):
Returns
-------
np.array
ndarray
Matrix containing cell averages and reconstructions for initial projection.
"""
......
......@@ -2,8 +2,6 @@
"""
@author: Laura C. Kühle
TODO: Add is_smooth() to DiscontinuousConstant class -> Done
"""
import numpy as np
......
......@@ -47,14 +47,14 @@ class Limiter(object):
Parameters
----------
projection : np.array
projection : ndarray
Matrix of projection for each polynomial degree.
cell
cell: int
Index of cell.
Returns
-------
np.array
ndarray
Matrix of updated projection for each polynomial degree.
"""
......@@ -117,14 +117,14 @@ class MinMod(Limiter):
Parameters
----------
projection : np.array
projection : ndarray
Matrix of projection for each polynomial degree.
cell : int
Index of cell.
Returns
-------
adapted_projection : np.array
adapted_projection : ndarray
Matrix of updated projection for each polynomial degree.
"""
......@@ -145,7 +145,7 @@ class MinMod(Limiter):
Parameters
----------
projection : np.array
projection : ndarray
Matrix of projection for each polynomial degree.
cell : int
Index of cell.
......@@ -154,7 +154,7 @@ class MinMod(Limiter):
Returns
-------
boolean
bool
Flag whether cell should be adjusted.
"""
......@@ -170,7 +170,7 @@ class MinMod(Limiter):
Parameters
----------
projection : np.array
projection : ndarray
Matrix of projection for each polynomial degree.
cell : int
Index of cell.
......@@ -237,7 +237,7 @@ class ModifiedMinMod(MinMod):
Parameters
----------
projection : np.array
projection : ndarray
Matrix of projection for each polynomial degree.
cell : int
Index of cell.
......@@ -246,7 +246,7 @@ class ModifiedMinMod(MinMod):
Returns
-------
boolean
bool
Flag whether cell should be adjusted.
"""
......
......@@ -15,9 +15,9 @@ class Quadrature(object):
----------
num_eval_points : int
Number of evaluation points per cell used for approximation.
eval_points : np.array
eval_points : ndarray
Evaluation points per cell used for approximation.
weights : np.array
weights : ndarray
Weights used for approximation calculation.
Methods
......@@ -80,9 +80,9 @@ class Gauss(Quadrature):
----------
num_eval_points : int
Number of evaluation points per cell used for approximation.
eval_points : np.array
eval_points : ndarray
Evaluation points per cell used for approximation.
weights : np.array
weights : ndarray
Weights used for approximation calculation.
Methods
......
......@@ -53,7 +53,7 @@ class TroubledCellDetector(object):
Parameters
----------
mesh : array
mesh : ndarray
List of mesh valuation points.
wave_speed : float
Speed of wave in rightward direction.
......@@ -123,7 +123,7 @@ class TroubledCellDetector(object):
Parameters
----------
projection : np.array
projection : ndarray
Matrix of projection for each polynomial degree.
"""
......@@ -137,14 +137,14 @@ class TroubledCellDetector(object):
Parameters
----------
projection : np.array
projection : ndarray
Matrix of projection for each polynomial degree.
stencil_length : int
Size of data array.
Returns
-------
np.array
ndarray
Matrix containing cell averages and reconstructions for initial projection.
"""
......@@ -164,11 +164,11 @@ class TroubledCellDetector(object):
Parameters
----------
projection : np.array
projection : ndarray
Matrix of projection for each polynomial degree.
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.
"""
......@@ -184,12 +184,12 @@ class TroubledCellDetector(object):
Parameters
----------
projection : np.array
projection : ndarray
Matrix of projection for each polynomial degree.
Returns
-------
max_error
max_error : float
Maximum error between exact and approximate solution.
"""
......@@ -225,9 +225,14 @@ class NoDetection(TroubledCellDetector):
Parameters
----------
projection : np.array
projection : ndarray
Matrix of projection for each polynomial degree.
Returns
-------
list
List of indices for all detected troubled cells.
"""
return []
......@@ -239,7 +244,7 @@ class ArtificialNeuralNetwork(TroubledCellDetector):
----------
stencil_length : int
Size of input data array.
model : ANNModel object
model : torch.nn.Model
ANN model instance for evaluation.
Methods
......@@ -280,7 +285,7 @@ class ArtificialNeuralNetwork(TroubledCellDetector):
Parameters
----------
projection : np.array
projection : ndarray
Matrix of projection for each polynomial degree.
Returns
......@@ -345,7 +350,7 @@ class WaveletDetector(TroubledCellDetector):
Parameters
----------
projection : np.array
projection : ndarray
Matrix of projection for each polynomial degree.
Returns
......@@ -362,12 +367,12 @@ class WaveletDetector(TroubledCellDetector):
Parameters
----------
projection : np.array
projection : ndarray
Matrix of projection for each polynomial degree.
Returns
-------
np.array
ndarray
Matrix of wavelet coefficients.
"""
......@@ -383,9 +388,9 @@ class WaveletDetector(TroubledCellDetector):
Parameters
----------
multiwavelet_coeffs : np.array
multiwavelet_coeffs : ndarray
Matrix of multiwavelet coefficients.
projection : np.array
projection : ndarray
Matrix of projection for each polynomial degree.
Returns
......@@ -403,11 +408,11 @@ class WaveletDetector(TroubledCellDetector):
Parameters
----------
projection : np.array
projection : ndarray
Matrix of projection for each polynomial degree.
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.
"""
......@@ -424,12 +429,12 @@ class WaveletDetector(TroubledCellDetector):
Parameters
----------
projection : np.array
projection : ndarray
Matrix of projection for each polynomial degree.
Returns
-------
np.array
ndarray
Matrix of projection on coarse grid for each polynomial degree.
"""
......@@ -453,12 +458,12 @@ class WaveletDetector(TroubledCellDetector):
Parameters
----------
projection : np.array
projection : ndarray
Matrix of projection for each polynomial degree.
Returns
-------
max_error
max_error : float
Maximum error between exact and approximate solution.
"""
......@@ -487,7 +492,7 @@ class WaveletDetector(TroubledCellDetector):
Parameters
----------
projection : np.array
projection : ndarray
Matrix of projection for each polynomial degree.
"""
......@@ -540,9 +545,9 @@ class Boxplot(WaveletDetector):
Parameters
----------
multiwavelet_coeffs : np.array
multiwavelet_coeffs : ndarray
Matrix of multiwavelet coefficients.
projection : np.array
projection : ndarray
Matrix of projection for each polynomial degree.
Returns
......@@ -619,9 +624,9 @@ class Theoretical(WaveletDetector):
Parameters
----------
multiwavelet_coeffs : np.array
multiwavelet_coeffs : ndarray
Matrix of multiwavelet coefficients.
projection : np.array
projection : ndarray
Matrix of projection for each polynomial degree.
Returns
......@@ -645,16 +650,16 @@ class Theoretical(WaveletDetector):
Parameters
----------
multiwavelet_coeffs : np.array
multiwavelet_coeffs : ndarray
Matrix of multiwavelet coefficients.
cell : int
Index of cell.
max_avg
max_avg : float
Maximum average of projection.
Returns
-------
boolean
bool
Flag whether cell is troubled.
"""
......
......@@ -16,9 +16,9 @@ class UpdateScheme(object):
Attributes
----------
stiffness_matrix : np.array
stiffness_matrix : ndarray
Matrix
boundary_matrix : np.array
boundary_matrix : ndarray
Matrix
Methods
......@@ -85,14 +85,14 @@ class UpdateScheme(object):
Parameters
----------
projection : np.array
projection : ndarray
Matrix of projection for each polynomial degree.
cfl_number : float
CFL number to ensure stability.
Returns
-------
current_projection : np.array
current_projection : ndarray
Matrix of projection of current update step for each polynomial degree.
troubled_cells : list
List of indices for all detected troubled cells.
......@@ -107,14 +107,14 @@ class UpdateScheme(object):
Parameters
----------
projection : np.array
projection : ndarray
Matrix of projection for each polynomial degree.
cfl_number : float
CFL number to ensure stability.
Returns
-------
current_projection : np.array
current_projection : ndarray
Matrix of projection of current update step for each polynomial degree.
troubled_cells : list
List of indices for all detected troubled cells.
......@@ -127,12 +127,12 @@ class UpdateScheme(object):
Parameters
----------
current_projection : np.array
current_projection : ndarray
Matrix of projection of current update step for each polynomial degree.
Returns
-------
new_projection : np.array
new_projection : ndarray
Matrix of updated projection for each polynomial degree.
troubled_cells : list
List of indices for all detected troubled cells.
......@@ -153,12 +153,12 @@ class UpdateScheme(object):
Parameters
----------
current_projection : np.array
current_projection : ndarray
Matrix of projection of current update step for each polynomial degree.
Returns
-------
current_projection : np.array
current_projection : ndarray
Matrix of projection of current update step for each polynomial degree.
"""
......@@ -181,14 +181,14 @@ class SSPRK3(UpdateScheme):
Parameters
----------
projection : np.array
projection : ndarray
Matrix of projection for each polynomial degree.
cfl_number : float
CFL number to ensure stability.
Returns
-------
current_projection : np.array
current_projection : ndarray
Matrix of projection of current update step for each polynomial degree.
troubled_cells : list
List of indices for all detected troubled cells.
......@@ -213,18 +213,18 @@ class SSPRK3(UpdateScheme):
return current_projection, troubled_cells
def _apply_first_step(self, original_projection, cfl_number):
"""Apply first step of SSPRK3.
"""Applies first step of SSPRK3.
Parameters
----------
original_projection : np.array
original_projection : ndarray
Matrix of original projection for each polynomial degree.
cfl_number : float
CFL number to ensure stability.
Returns
-------
np.array
ndarray
Matrix of updated projection for each polynomial degree.
"""
......@@ -232,20 +232,20 @@ class SSPRK3(UpdateScheme):
return original_projection + (cfl_number*right_hand_side)
def _apply_second_step(self, original_projection, current_projection, cfl_number):
"""Apply second step of SSPRK3.
"""Applies second step of SSPRK3.
Parameters
----------
original_projection : np.array
original_projection : ndarray
Matrix of original projection for each polynomial degree.
current_projection : np.array
current_projection : ndarray
Matrix of projection of current update step for each polynomial degree.
cfl_number : float
CFL number to ensure stability.
Returns
-------
np.array
ndarray
Matrix of updated projection for each polynomial degree.
"""
......@@ -253,20 +253,20 @@ class SSPRK3(UpdateScheme):
return 1/4 * (3*original_projection + (current_projection + cfl_number*right_hand_side))
def _apply_third_step(self, original_projection, current_projection, cfl_number):
"""Apply third step of SSPRK3.
"""Applies third step of SSPRK3.
Parameter
---------
original_projection : np.array
original_projection : ndarray
Matrix of original projection for each polynomial degree.
current_projection : np.array
current_projection : ndarray
Matrix of projection of current update step for each polynomial degree.
cfl_number : float
CFL number to ensure stability.
Returns
-------
np.array
ndarray
Matrix of updated projection for each polynomial degree.
"""
......@@ -274,16 +274,16 @@ class SSPRK3(UpdateScheme):
return 1/3 * (original_projection + 2*(current_projection + cfl_number*right_hand_side))
def _update_right_hand_side(self, current_projection):
"""Update right-hand side.
"""Updates right-hand side.
Parameter
---------
current_projection : np.array
current_projection : ndarray
Matrix of projection of current update step for each polynomial degree.
Returns
-------
np.array
ndarray
Matrix of right-hand side.
"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment