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() >>> xp array([ 1.00000000e+00, 1.00000000e+00, 1.00000000e15])

aboleth.util.
predict_expected
(predictor, feed_dict, n_groups=1, session=None)¶ Help to get the expected value from a predictor.
Parameters:  predictor (Tensor) – a tensor that outputs a shape (n_samples, N, tasks) where
n_samples
are the random samples from the predictor (e.g. the output ofNet
),N
is the size of the query dataset, andtasks
the number of prediction tasks.  feed_dict (dict) – The data with
{tf.placeholder: data}
entries.  n_groups (int) – The number of times to evaluate the
predictor
and concatenate the samples.  session (Session) – the session to be used to evaluate the predictor.
Returns: pred – expected value of the prediction with shape (N, tasks).
n_samples * n_groups
samples go into evaluating this expectation.Return type: ndarray
Note
This has to be called in an active tensorflow session!
 predictor (Tensor) – a tensor that outputs a shape (n_samples, N, tasks) where

aboleth.util.
predict_samples
(predictor, feed_dict, n_groups=1, session=None)¶ Help to get samples from a predictor.
Parameters:  predictor (Tensor) – a tensor that outputs a shape (n_samples, N, tasks) where
n_samples
are the random samples from the predictor (e.g. the output ofNet
),N
is the size of the query dataset, andtasks
the number of prediction tasks.  feed_dict (dict) – The data with
{tf.placeholder: data}
entries.  n_groups (int) – The number of times to evaluate the
predictor
and concatenate the samples.  session (Session) – the session to be used to evaluate the predictor.
Returns: pred – prediction samples of shape (n_samples * n_groups, N, tasks).
Return type: ndarray
Note
This has to be called in an active tensorflow session!
 predictor (Tensor) – a tensor that outputs a shape (n_samples, N, tasks) where