Skip to content

Commit

Permalink
remove first_guess because don't use in these examples, not recently …
Browse files Browse the repository at this point in the history
…tested
  • Loading branch information
Bethany Lusch authored and Bethany Lusch committed Oct 13, 2019
1 parent 10e833a commit f06ad04
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 22 deletions.
7 changes: 0 additions & 7 deletions helperfns.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,13 +355,6 @@ def set_defaults(params):
print("setting default: biases in auxiliary net will be init. to default number")
params['dist_biases_omega'] = 0

if 'first_guess' not in params:
print("setting default: no first guess for main network")
params['first_guess'] = 0
if 'first_guess_omega' not in params:
print("setting default: no first guess for auxiliary net")
params['first_guess_omega'] = 0

if 'scale' not in params:
print("setting default: scale for weights in main net is 0.1 (applies to tn distribution)")
params['scale'] = 0.1
Expand Down
23 changes: 8 additions & 15 deletions networkarch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
import helperfns


def weight_variable(shape, var_name, distribution='tn', scale=0.1, first_guess=0):
def weight_variable(shape, var_name, distribution='tn', scale=0.1):
"""Create a variable for a weight matrix.
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 (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
Expand All @@ -23,7 +22,7 @@ def weight_variable(shape, var_name, distribution='tn', scale=0.1, first_guess=0
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
initial = tf.truncated_normal(shape, stddev=scale, dtype=tf.float64)
elif distribution == 'xavier':
scale = 4 * np.sqrt(6.0 / (shape[0] + shape[1]))
initial = tf.random_uniform(shape, minval=-scale, maxval=scale, dtype=tf.float64)
Expand Down Expand Up @@ -71,7 +70,7 @@ def bias_variable(shape, var_name, distribution=''):
return tf.Variable(initial, name=var_name)


def encoder(widths, dist_weights, dist_biases, scale, num_shifts_max, first_guess):
def encoder(widths, dist_weights, dist_biases, scale, num_shifts_max):
"""Create an encoder network: an input placeholder x, dictionary of weights, and dictionary of biases.
Arguments:
Expand All @@ -80,7 +79,6 @@ def encoder(widths, dist_weights, dist_biases, scale, num_shifts_max, first_gues
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
num_shifts_max -- number of shifts (time steps) that losses will use (max of num_shifts and num_shifts_middle)
first_guess -- (for tn dist. of weight matrices): array of first guess for weight matrix, added to tn dist.
Returns:
x -- placeholder for input
Expand All @@ -97,8 +95,7 @@ def encoder(widths, dist_weights, dist_biases, scale, num_shifts_max, first_gues

for i in np.arange(len(widths) - 1):
weights['WE%d' % (i + 1)] = weight_variable([widths[i], widths[i + 1]], var_name='WE%d' % (i + 1),
distribution=dist_weights[i], scale=scale,
first_guess=first_guess)
distribution=dist_weights[i], scale=scale)
# TODO: first guess for biases too (and different ones for different weights)
biases['bE%d' % (i + 1)] = bias_variable([widths[i + 1], ], var_name='bE%d' % (i + 1),
distribution=dist_biases[i])
Expand Down Expand Up @@ -172,7 +169,7 @@ def encoder_apply_one_shift(prev_layer, weights, biases, act_type, name='E', num
return final


def decoder(widths, dist_weights, dist_biases, scale, name='D', first_guess=0):
def decoder(widths, dist_weights, dist_biases, scale, name='D'):
"""Create a decoder network: a dictionary of weights and a dictionary of biases.
Arguments:
Expand All @@ -181,8 +178,6 @@ def decoder(widths, dist_weights, dist_biases, scale, name='D', first_guess=0):
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)
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 All @@ -196,8 +191,7 @@ def decoder(widths, dist_weights, dist_biases, scale, name='D', first_guess=0):
for i in np.arange(len(widths) - 1):
ind = i + 1
weights['W%s%d' % (name, ind)] = weight_variable([widths[i], widths[i + 1]], var_name='W%s%d' % (name, ind),
distribution=dist_weights[ind - 1], scale=scale,
first_guess=first_guess)
distribution=dist_weights[ind - 1], scale=scale)
biases['b%s%d' % (name, ind)] = bias_variable([widths[i + 1], ], var_name='b%s%d' % (name, ind),
distribution=dist_biases[ind - 1])
return weights, biases
Expand Down Expand Up @@ -355,8 +349,7 @@ def create_one_omega_net(params, temp_name, weights, biases, widths):
Updates weights and biases dictionaries
"""
weightsO, biasesO = decoder(widths, dist_weights=params['dist_weights_omega'],
dist_biases=params['dist_biases_omega'], scale=params['scale_omega'], name=temp_name,
first_guess=params['first_guess_omega'])
dist_biases=params['dist_biases_omega'], scale=params['scale_omega'], name=temp_name)
weights.update(weightsO)
biases.update(biasesO)

Expand Down Expand Up @@ -441,7 +434,7 @@ def create_koopman_net(params):
encoder_widths = params['widths'][0:depth + 2] # n ... k
x, weights, biases = encoder(encoder_widths, dist_weights=params['dist_weights'][0:depth + 1],
dist_biases=params['dist_biases'][0:depth + 1], scale=params['scale'],
num_shifts_max=max_shifts_to_stack, first_guess=params['first_guess'])
num_shifts_max=max_shifts_to_stack)
params['num_encoder_weights'] = len(weights)
g_list = encoder_apply(x, weights, biases, params['act_type'], shifts_middle=params['shifts_middle'],
num_encoder_weights=params['num_encoder_weights'])
Expand Down

0 comments on commit f06ad04

Please sign in to comment.