Onyx logo

Previous topic

onyx.util.collate – Tools for simple collation tasks.

Next topic

onyx.util.dotdisplay – Tools and mix-in classes for DOT-based graphical display.

This Page

onyx.util.discrete – Tools for working with discrete spaces.

A discrete space is a sequence of sequences of immutable items. It is often called a feature space.

class onyx.util.discrete.DiscreteScalarModel(range1, range2=None)

Bases: object

>>> dsm = DiscreteScalarModel(256)
>>> for i in xrange(23, 33): dsm.sample(i)
>>> for i in xrange(23, 43): dsm.sample(i)
>>> dsm.score(23)
28
>>> dsm.score(33)
29
sample(value)
score(value)
onyx.util.discrete.iterspace(features, sortem=False)

Returns a generator that yields each of the points defined by the discrete space ‘features’. The ‘rightmost’ feature is iterated most rapidly. There is no requirement that the items in a feature be mutually unique.

If optional ‘sortem’ is True, the items in each feature will be sorted before the space is enumerated.

>>> features = (('b', 'a'), (1, 2, 1), ('p', 'n'))
>>> tuple(iterspace(features))
(('b', 1, 'p'), ('b', 1, 'n'), ('b', 2, 'p'), ('b', 2, 'n'), ('b', 1, 'p'), ('b', 1, 'n'), ('a', 1, 'p'), ('a', 1, 'n'), ('a', 2, 'p'), ('a', 2, 'n'), ('a', 1, 'p'), ('a', 1, 'n'))
>>> tuple(iterspace(((3, 1, 2), ('z', 'a')), True))
((1, 'a'), (1, 'z'), (2, 'a'), (2, 'z'), (3, 'a'), (3, 'z'))