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.
pybrain.utilities.n_to_one(arr)
Returns the reverse of a 1-in-n binary encoding.
pybrain.utilities.int2gray(i)
Returns the value of an integer in Gray encoding.
pybrain.utilities.asBinary(i)
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

pybrain.utilities.triu2flat(m)
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.
pybrain.utilities.blockList2Matrix(l)
Converts a list of matrices into a corresponding big block-diagonal one.
pybrain.utilities.blockCombine(l)
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