Esempio n. 1
0
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)
Esempio n. 2
0
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)
Esempio n. 3
0
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)
Esempio n. 4
0
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)
Esempio n. 5
0
 def __init__(self):
     super(KL, self).__init__()
     self.c = msd.Categorical([0.7, 0.3], dtype=dtype.int32)
Esempio n. 6
0
 def __init__(self):
     super(Basics, self).__init__()
     self.c = msd.Categorical([0.2, 0.1, 0.7], dtype=dtype.int32)
Esempio n. 7
0
 def __init__(self):
     super(Sampling, self).__init__()
     self.c = msd.Categorical([0.2, 0.1, 0.7], dtype=dtype.int32)
     self.shape = (2, 3)
Esempio n. 8
0
def test_seed():
    with pytest.raises(TypeError):
        msd.Categorical([0.1], seed='seed')
Esempio n. 9
0
def test_name():
    with pytest.raises(TypeError):
        msd.Categorical([0.1], name=1.0)
Esempio n. 10
0
def test_type():
    with pytest.raises(TypeError):
        msd.Categorical([0.1], dtype=dtype.bool_)
Esempio n. 11
0
 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)
Esempio n. 12
0
 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)
Esempio n. 13
0
 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)
Esempio n. 14
0
 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)
Esempio n. 15
0
 def __init__(self):
     super(CategoricalProb1, self).__init__()
     self.c = msd.Categorical(dtype=dtype.int32)
Esempio n. 16
0
 def __init__(self, probs, seed=10, dtype=ms.int32, name='Categorical'):
     super().__init__()
     self.b = msd.Categorical(probs, seed, dtype, name)