utilities – Simple but useful Utility Functions

Tools for binary encodings

pybrain.utilities.one_to_n(val, maxval)
Returns a 1-in-n binary encoding of a non-negative integer.
Returns the reverse of a 1-in-n binary encoding.
Returns the value of an integer in Gray encoding.
Produces a string from an integer’s binary representation. (preceding zeros removed).

Tools for sets

pybrain.utilities.reachable(stepFunction, start, destinations)
Determines the subset of destinations that can be reached from a set of starting positions, while using stepFunction (which produces a list of neighbor states) to navigate. Uses breadth-first search.
pybrain.utilities.crossproduct(ss, row=None, level=0)
Returns the cross-product of the sets given in ss.

Matrix tools

Flattens an upper triangular matrix, returning a vector of the non-zero elements.
pybrain.utilities.flat2triu(a, dim)
Produces an upper triangular matrix of dimension dim from the elements of the given vector.
Converts a list of matrices into a corresponding big block-diagonal one.
Produce a matrix from a list of lists of its components.

Stochastic index choices

pybrain.utilities.drawIndex(probs, tolerant=False)

Draws an index given an array of probabilities.

Key tolerant:if set to True, the array is normalized to sum to 1.
pybrain.utilities.drawGibbs(vals, temperature=1.0)
Return the index of the sample drawn by a softmax (Gibbs).

Previous topic

tools – Some Useful Tools and Macros

Next topic

nearoptimal – Near Optimal Locality Sensitive Hashing

This Page