def test_categorical_sum(): """ Invaild probabilities. """ with pytest.raises(ValueError): msd.Categorical([[0.1, 0.2], [0.4, 0.6]], dtype=dtype.int32) with pytest.raises(ValueError): msd.Categorical([[0.5, 0.7], [0.6, 0.6]], dtype=dtype.int32)
def test_arguments(): """ Args passing during initialization. """ c = msd.Categorical() assert isinstance(c, msd.Distribution) c = msd.Categorical([0.1, 0.9], dtype=dtype.int32) assert isinstance(c, msd.Distribution)
def rank(): """ Rank dimenshion less than 1. """ with pytest.raises(ValueError): msd.Categorical(0.2, dtype=dtype.int32) with pytest.raises(ValueError): msd.Categorical(np.array(0.3).astype(np.float32), dtype=dtype.int32) with pytest.raises(ValueError): msd.Categorical(Tensor(np.array(0.3).astype(np.float32)), dtype=dtype.int32)
def test_prob(): """ Invalid probability. """ with pytest.raises(ValueError): msd.Categorical([-0.1], dtype=dtype.int32) with pytest.raises(ValueError): msd.Categorical([1.1], dtype=dtype.int32) with pytest.raises(ValueError): msd.Categorical([0.0], dtype=dtype.int32) with pytest.raises(ValueError): msd.Categorical([1.0], dtype=dtype.int32)
def __init__(self): super(KL, self).__init__() self.c = msd.Categorical([0.7, 0.3], dtype=dtype.int32)
def __init__(self): super(Basics, self).__init__() self.c = msd.Categorical([0.2, 0.1, 0.7], dtype=dtype.int32)
def __init__(self): super(Sampling, self).__init__() self.c = msd.Categorical([0.2, 0.1, 0.7], dtype=dtype.int32) self.shape = (2, 3)
def test_seed(): with pytest.raises(TypeError): msd.Categorical([0.1], seed='seed')
def test_name(): with pytest.raises(TypeError): msd.Categorical([0.1], name=1.0)
def test_type(): with pytest.raises(TypeError): msd.Categorical([0.1], dtype=dtype.bool_)
def __init__(self): super(CategoricalBasics, self).__init__() self.c = msd.Categorical([0.2, 0.7, 0.1], dtype=dtype.int32) self.c1 = msd.Categorical(dtype=dtype.int32)
def __init__(self): super(CategoricalConstruct, self).__init__() self.c = msd.Categorical([0.1, 0.8, 0.1], dtype=dtype.int32) self.c1 = msd.Categorical(dtype=dtype.int32)
def __init__(self): super(CategoricalCrossEntropy, self).__init__() self.c1 = msd.Categorical([0.1, 0.7, 0.2], dtype=dtype.int32) self.c2 = msd.Categorical(dtype=dtype.int32)
def __init__(self): super(CategoricalKl, self).__init__() self.c1 = msd.Categorical([0.2, 0.2, 0.6], dtype=dtype.int32) self.c2 = msd.Categorical(dtype=dtype.int32)
def __init__(self): super(CategoricalProb1, self).__init__() self.c = msd.Categorical(dtype=dtype.int32)
def __init__(self, probs, seed=10, dtype=ms.int32, name='Categorical'): super().__init__() self.b = msd.Categorical(probs, seed, dtype, name)