ab.util¶
Package helper utilities.

aboleth.util.
batch
(feed_dict, batch_size, n_iter=10000, N_=None)¶ Create random batches for Stochastic gradients.
Feed dict data generator for SGD that will yeild random batches for a a defined number of iterations, which can be infinite. This generator makes consecutive passes through the data, drawing without replacement on each pass.
Parameters:  feed_dict (dict of ndarrays) – The data with
{tf.placeholder: data}
entries. This assumes all items have the same length!  batch_size (int) – number of data points in each batch.
 n_iter (int, optional) – The number of iterations
 N (tf.placeholder (int), optional) – Place holder for the size of the dataset. This will be fed to an algorithm.
Yields: dict – with each element an array length
batch_size
, i.e. a subset of data, and an element forN_
. Use this as your feeddict when evaluating a loss, training, etc. feed_dict (dict of ndarrays) – The data with

aboleth.util.
batch_prediction
(feed_dict, batch_size)¶ Split the data in a feed_dict into contiguous batches for prediction.
Parameters:  feed_dict (dict of ndarrays) – The data with
{tf.placeholder: data}
entries. This assumes all items have the same length!  batch_size (int) – number of data points in each batch.
Yields:  ndarray – an array of shape approximately (
batch_size
,) of indices into the original data for the current batch  dict – with each element an array length
batch_size
, i.e. a subset of data. Use this as your feeddict when evaluating a model, prediction, etc.
Note
The exact size of the batch may not be
batch_size
, but the nearest size that splits the size of the data most evenly. feed_dict (dict of ndarrays) – The data with

aboleth.util.
pos
(X, minval=1e15)¶ Constrain a
tf.Variable
to be positive only.At the moment this is implemented as:
\(\max(\mathbf{X}, \text{minval})\)This is fast and does not result in vanishing gradients, but will lead to nonsmooth gradients and more local minima. In practice we haven’t noticed this being a problem.
Parameters:  X (Tensor) – any Tensor in which all elements will be made positive.
 minval (float) – the minimum “positive” value the resulting tensor will have.
Returns: X – a tensor the same shape as the input
X
but positively constrained.Return type: Tensor
Examples
>>> X = tf.constant(np.array([1.0, 1.0, 0.0])) >>> Xp = pos(X) >>> with tf.Session(): ... xp = Xp.eval() >>> all(xp == np.array([1., 1., 1.e15])) True

aboleth.util.
summary_histogram
(values)¶ Add a summary histogram to TensorBoard.
This will add a summary histogram with name
variable.name + "_hist"
.Parameters: values (tf.Variable, tf.Tensor) – the Tensor to add to the summaries.