Skip to content

Commit

Permalink
improve docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
BethanyL committed Apr 24, 2018
1 parent 61d7aea commit 2822370
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
7 changes: 7 additions & 0 deletions helperfns.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ def choose_optimizer(params, regularized_loss, trainable_var):
Side effects:
None
Raises ValueError if params['opt_alg'] is not 'adam', 'adadelta', 'adagrad', 'adagradDA', 'ftrl', 'proximalGD',
'proximalAdagrad', or 'RMS'
"""
if params['opt_alg'] == 'adam':
optimizer = tf.train.AdamOptimizer(params['learning_rate']).minimize(regularized_loss, var_list=trainable_var)
Expand Down Expand Up @@ -285,6 +288,10 @@ def set_defaults(params):
Side effects:
May update params dict
Raises KeyError if params is missing data_name, len_time, data_train_len, delta_t, widths, hidden_widths_omega,
num_evals, num_real, or num_complex_pairs
Raises ValueError if num_evals != 2 * num_complex_pairs + num_real
"""
# defaults related to dataset
if 'data_name' not in params:
Expand Down
23 changes: 14 additions & 9 deletions networkarch.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ def weight_variable(shape, var_name, distribution='tn', scale=0.1, first_guess=0
Arguments:
shape -- array giving shape of output weight variable
var_name -- string naming weight variable
distribution -- string for which distribution to use for random initialization
scale -- (for tn distribution): standard deviation of normal distribution before truncation
first_guess -- (for tn distribution): array of first guess for weight matrix, added to tn dist.
distribution -- string for which distribution to use for random initialization (default 'tn')
scale -- (for tn distribution): standard deviation of normal distribution before truncation (default 0.1)
first_guess -- (for tn distribution): array of first guess for weight matrix, added to tn dist. (default 0)
Returns:
a TensorFlow variable for a weight matrix
Side effects:
None
Raises ValueError if distribution is filename but shape of data in file does not match input shape
"""
if distribution == 'tn':
initial = tf.truncated_normal(shape, stddev=scale, dtype=tf.float64) + first_guess
Expand Down Expand Up @@ -54,7 +56,7 @@ def bias_variable(shape, var_name, distribution=''):
Arguments:
shape -- array giving shape of output bias variable
var_name -- string naming bias variable
distribution -- string for which distribution to use for random initialization (file name)
distribution -- string for which distribution to use for random initialization (file name) (default '')
Returns:
a TensorFlow variable for a bias vector
Expand Down Expand Up @@ -116,8 +118,8 @@ def encoder_apply(x, weights, biases, act_type, batch_flag, phase, shifts_middle
phase -- boolean placeholder for dropout: training phase or not training phase
shifts_middle -- number of shifts (steps) in x to apply encoder to for linearity loss
keep_prob -- probability that weight is kept during dropout
name -- string for prefix on weight matrices, default 'E' for encoder
num_encoder_weights -- number of weight matrices (layers) in encoder network, default 1
name -- string for prefix on weight matrices (default 'E' for encoder)
num_encoder_weights -- number of weight matrices (layers) in encoder network (default 1)
Returns:
y -- list, output of encoder network applied to each time shift in input x
Expand Down Expand Up @@ -154,8 +156,8 @@ def encoder_apply_one_shift(prev_layer, weights, biases, act_type, batch_flag, p
batch_flag -- 0 if no batch_normalization, 1 if batch_normalization
phase -- boolean placeholder for dropout: training phase or not training phase
keep_prob -- probability that weight is kept during dropout
name -- string for prefix on weight matrices, default 'E' (for "encoder")
num_encoder_weights -- number of weight matrices (layers) in encoder network, default 1
name -- string for prefix on weight matrices (default 'E' for encoder)
num_encoder_weights -- number of weight matrices (layers) in encoder network (default 1)
Returns:
final -- output of encoder network applied to input prev_layer (a particular time step / shift)
Expand Down Expand Up @@ -193,8 +195,9 @@ def decoder(widths, dist_weights, dist_biases, scale, name='D', first_guess=0):
dist_weights -- array or list of strings for distributions of weight matrices
dist_biases -- array or list of strings for distributions of bias vectors
scale -- (for tn distribution of weight matrices): standard deviation of normal distribution before truncation
name -- string for prefix on weight matrices, default 'D' (for "decoder")
name -- string for prefix on weight matrices (default 'D' for decoder)
first_guess -- (for tn dist. of weight matrices): array of first guess for weight matrix, added to tn dist.
(default 0)
Returns:
weights -- dictionary of weights
Expand Down Expand Up @@ -464,6 +467,8 @@ def create_koopman_net(phase, keep_prob, params):
Side effects:
Adds more entries to params dict: num_encoder_weights, num_omega_weights, num_decoder_weights
Raises ValueError if len(y) is not len(params['shifts']) + 1
"""
depth = int((params['d'] - 4) / 2)

Expand Down

0 comments on commit 2822370

Please sign in to comment.