def test_interval_is_banned(self): """Check that calling `Categorical.interval` raises `RuntimeError`.""" categories = {'asdfa': 0.1, 2: 0.2, 3: 0.3, 4: 0.4} dim = Categorical('yolo', categories, shape=2) with pytest.raises(RuntimeError) as exc: dim.interval() assert 'not ordered' in str(exc.value)
def _(dim: Categorical): if dim.shape: raise NotImplementedError("Array of Categorical cannot be converted.") if len(set(dim.original_dimension.prior.pk)) != 1: raise NotImplementedError( "All categories in Categorical must have the same probability.") return ng.p.Choice(dim.interval())
def categorical_grid(dim: Categorical, num: int): """Build categorical grid, that is, all categories""" categories = dim.interval() if len(categories) != num: log.warning( f"Categorical dimension {dim.name} does not have {num} choices: {categories}. " "Will use {len(categories)} choices instead.") return categories
def test_interval(self): """Check that calling `Categorical.interval` raises `RuntimeError`.""" categories = {"asdfa": 0.1, 2: 0.2, 3: 0.3, 4: 0.4} dim = Categorical("yolo", categories, shape=2) assert dim.interval() == ("asdfa", 2, 3, 4)