models package

Submodules

models.BNN module

class models.BNN.BNN(params)

Bases: object

Neural network models which model aleatoric uncertainty (and possibly epistemic uncertainty with ensembling).

Parameters:params (DotMap) –

A dotmap of model parameters. .name (str):

Model name, used for logging/use in variable scopes. Warning: Models with the same name will overwrite each other.
.num_networks (int): (optional)
The number of networks in the ensemble. Defaults to 1. Ignored if model is being loaded.
.model_dir (str/None): (optional)
Path to directory from which model will be loaded, and saved by default. Defaults to None.
.load_model (bxool): (optional)
If True, model will be loaded from the model directory, assuming that the files are generated by a model of the same name. Defaults to False.
.sess (tf.Session/None):
The session that this model will use. If None, creates a session with its own associated graph. Defaults to None.
add(layer)

Adds a new layer to the network.

Parameters:layer – (layer) The new layer to be added to the network. If this is the first layer, the input dimension of the layer must be set.

Returns: None.

create_prediction_tensors(inputs, factored=False, *args, **kwargs)

See predict() for documentation.

finalize(optimizer, optimizer_args=None, *args, **kwargs)

Finalizes the network.

Parameters:
  • optimizer – (tf.train.Optimizer) An optimizer class from those available at tf.train.Optimizer.
  • optimizer_args – (dict) A dictionary of arguments for the __init__ method of the chosen optimizer.

Returns: None

is_probabilistic

Returns True

is_tf_model

Returns True

pop()

Removes and returns the most recently added layer to the network.

Returns: (layer) The removed layer.

predict(inputs, factored=False, *args, **kwargs)

Returns the distribution predicted by the model for each input vector in inputs. Behavior is affected by the dimensionality of inputs and factored as follows:

inputs is 2D, factored=True:
Each row is treated as an input vector. Returns a mean of shape [ensemble_size, batch_size, output_dim] and variance of shape [ensemble_size, batch_size, output_dim], where N(mean[i, j, :], diag([i, j, :])) is the predicted output distribution by the ith model in the ensemble on input vector j.
inputs is 2D, factored=False:
Each row is treated as an input vector. Returns a mean of shape [batch_size, output_dim] and variance of shape [batch_size, output_dim], where aggregation is performed as described in the paper.
inputs is 3D, factored=True/False:
Each row in the last dimension is treated as an input vector. Returns a mean of shape [ensemble_size, batch_size, output_dim] and variance of sha [ensemble_size, batch_size, output_dim], where N(mean[i, j, :], diag([i, j, :])) is the predicted output distribution by the ith model in the ensemble on input vector [i, j].
Parameters:
  • inputs (np.ndarray) – An array of input vectors in rows. See above for behavior.
  • factored (bool) – See above for behavior.
save(savedir=None)

Saves all information required to recreate this model in two files in savedir (or self.model_dir if savedir is None), one containing the model structure and the other containing all variables in the network.

savedir (str, Optional): Path to which files will be saved. If not provided, self.model_dir (the directory provided at initialization) will be used.

sess

Returns the TensorFlow session used by this class.

train(inputs, targets, batch_size=32, epochs=100, hide_progress=False, holdout_ratio=0.0, max_logging=5000)

Trains/Continues network training

Parameters:
  • inputs (np.ndarray) – Network inputs in the training dataset in rows.
  • targets (np.ndarray) – Network target outputs in the training dataset in rows corresponding to the rows in inputs.
  • batch_size (int) – The minibatch size to be used for training.
  • epochs (int) – Number of epochs (full network passes that will be done.
  • hide_progress (bool) – If True, hides the progress bar shown at the beginning of training.

Returns: None

models.BNN.loadPickle(name)

Loads and returns a pickled object.

Parameters:name (str) – Path to pickled object.
Returns:pickled object
models.BNN.savePickle(name, data)

Saves a picked object to a file.

Parameters:
  • name (str) – Path to file.
  • data – Object to be pickled.

Module contents