coopihc.base.Space.CatSet

class CatSet(array=None, seed=None, dtype=None, contains='numpy')[source]

Bases: coopihc.base.Space.BaseSpace

Categorical Set

A categorical set defined explicitly. Use this for data where traditional distance is meaningless i.e. when 1 is not closer to 0 then to 5. Performance of this object for large dimensions may be bad, because the whole array is stored in memory.

s = space(array=numpy.array([1, 2, 3], dtype=numpy.int16))
assert s.dtype == numpy.int16
assert s.N == 3
assert s.shape == ()

You can further set the seed of the space (useful when sampling from the space), force the dtype of the space and specify how membership to the space is checked via the keyword arguments. See BaseSpace for more information.

Parameters

array (numpy.ndarray, optional) – set of values, defaults to None

Methods

sample

Generate values by sampling uniformly from the set.

serialize

Attributes

N

Cardinality of the set

dtype

numpy.dtype of data

high

low

shape

numpy shape of the data that belongs to the set

spacetype

property N

Cardinality of the set

property dtype

numpy.dtype of data

sample()[source]

Generate values by sampling uniformly from the set. You can set the seed to the rng, see keyword arguments at init.

s = CatSet(array=numpy.arange(1000), seed=123)
q = CatSet(array=numpy.arange(1000), seed=123)
r = CatSet(array=numpy.arange(1000), seed=12)
_s, _q, _r = s.sample(), q.sample(), r.sample()
assert _s in s
assert _q in q
assert _r in r
assert _s == _q
assert _s != _r
property shape

numpy shape of the data that belongs to the set