Example #1
0
    def test_sample(self):
        sys.stdout.write('RectBinaryRBM -> Performing sample test ...')
        numx.random.seed(420)
        input_dim = 8
        hidden_dim = 10
        batchsize = 3
        rbm = Model.RectBinaryRBM(input_dim, hidden_dim)

        data = numx.random.rand(batchsize, input_dim)
        h = rbm.probability_h_given_v(data)
        assert numx.all(h >= 0.0)
        assert numx.all(h <= 1.0)
        assert numx.all(h.shape == (batchsize, hidden_dim))
        h = rbm.sample_h(h)
        assert numx.all(h >= 0.0)
        assert numx.all(h <= 1.0)
        assert numx.all(h.shape == (batchsize, hidden_dim))
        v = rbm.probability_v_given_h(h)
        assert numx.all(v >= 0.0)
        assert numx.all(v.shape == (batchsize, input_dim))
        v = rbm.sample_v(v)
        assert numx.all(v >= 0.0)
        assert numx.all(v <= rbm.max_act)
        assert numx.all(v.shape == (batchsize, input_dim))
        sys.stdout.flush()
        print(' successfully passed!')
        sys.stdout.flush()
        pass
Example #2
0
    def test___init__(self):
        sys.stdout.write('RectBinaryRBM -> Performing init test ...')

        numx.random.seed(42)
        input_dim = 8
        hidden_dim = 10
        batchsize = 3
        rbm = Model.RectBinaryRBM(input_dim, hidden_dim)
        assert numx.all(rbm.w.shape == (input_dim, hidden_dim))
        assert numx.all(rbm.bv.shape == (1, input_dim))
        assert numx.all(rbm.bh.shape == (1, hidden_dim))
        assert numx.all(rbm.input_dim == input_dim)
        assert numx.all(rbm.output_dim == hidden_dim)
        sys.stdout.flush()
        print(' successfully passed!')
        sys.stdout.flush()
        pass