coopihc.base.Space.Numeric
- class Numeric(low=array([- 1]), high=array([1]), seed=None, dtype=None, contains='numpy')[source]
- Bases: - coopihc.base.Space.BaseSpace- An interval that defines the space for a StateElement. - You can define an Numeric by specifying the lower and upper bounds: - s = Numeric( low=-numpy.ones((2, 2), dtype=numpy.float32), high=numpy.ones((2, 2), dtype=numpy.float32), ) assert s.dtype == numpy.float32 assert (s.high == numpy.ones((2, 2))).all() assert (s.low == -numpy.ones((2, 2))).all() assert s.shape == (2, 2) - 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 - BaseSpacefor more information.- Note - lower and upper bounds must be valid numpy objects. For example, to specify a 0-D space, you should do: - Numeric(low = -numpy.float64(1), high = numpy.float64(1))- Parameters
- low (numpy.ndarray, optional) – lower bound, defaults to -numpy.array([1]) 
- high (numpy.ndarray, optional) – upper bound, defaults to numpy.array([1]) 
 
 - Methods - Generate values by sampling from the interval. - serialize to JSON - Attributes - N- array- Determines the numpy dtype of data contained in the space. - Returns the numpy shape of the bounds. - spacetype- property dtype
- Determines the numpy dtype of data contained in the space. - Note - If you input two different integer dtypes, the result will be a numpy.float64, per https://numpy.org/doc/stable/reference/generated/numpy.common_type.html - Returns
- _description_ 
- Return type
- _type_ 
 
 - sample()[source]
- Generate values by sampling from the interval. If the interval represents integers, sampling is uniform. Otherwise, sampling is Gaussian. You can set the seed to sample, see keyword arguments at init. - s = Numeric(low=-numpy.ones((2, 2)), high=numpy.ones((2, 2)), seed=123) q = Numeric(low=-numpy.ones((2, 2)), high=numpy.ones((2, 2)), seed=123) r = Numeric(low=-numpy.ones((2, 2)), high=numpy.ones((2, 2)), 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).all() assert (_s != _r).any() 
 - property shape
- Returns the numpy shape of the bounds.