예제 #1
0
    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)
예제 #2
0
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())
예제 #3
0
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
예제 #4
0
    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)