Пример #1
0
    def test_basic_log_prob(self):
        n_samples = self.n_samples
        layer = self.layer

        X, X_ = testing.fmatrix((n_samples, layer.n_X), name="X")
        Y, Y_ = testing.fmatrix((n_samples, layer.n_Y), name="H")

        log_prob = layer.log_prob(X, Y)
        do_log_prob = theano.function([X, Y], log_prob, name="log_prob")

        log_prob_ = do_log_prob(X_, Y_)
        assert log_prob_.shape == (n_samples, )
        assert not np.isnan(log_prob_).any()
Пример #2
0
    def test_basic_log_prob(self):
        n_samples = self.n_samples
        layer = self.layer

        X, X_ = testing.fmatrix((n_samples, layer.n_X), name="X")
        Y, Y_ = testing.fmatrix((n_samples, layer.n_Y), name="H")

        log_prob = layer.log_prob(X, Y)
        do_log_prob = theano.function([X, Y], log_prob, name="log_prob")

        log_prob_ = do_log_prob(X_, Y_)
        assert log_prob_.shape == (n_samples,)
        assert not np.isnan(log_prob_).any()
Пример #3
0
    def test_log_likelihood(self):
        batch_size = 20
        stack = self.stack

        X, X_ = testing.fmatrix((batch_size, self.n_vis), 'X')
        n_samples, n_samples_ = testing.iscalar('n_samples')
        n_samples_ = self.n_samples

        log_PX, w, log_P, log_Q, KL, Hp, Hq = stack.log_likelihood(
            X, n_samples=n_samples)
        do_log_likelihood = theano.function([X, n_samples],
                                            [log_PX, log_P, log_Q, w])

        log_PX_, log_P_, log_Q_, w_ = do_log_likelihood(X_, n_samples_)

        print "log_P.shape", log_P_.shape
        print "log_Q.shape", log_Q_.shape
        print "log_PX.shape", log_PX_.shape
        print "w.shape", w_.shape

        assert log_PX_.shape == (batch_size, )
        assert log_P_.shape == (batch_size, n_samples_)
        assert log_Q_.shape == (batch_size, n_samples_)
        assert w_.shape == (batch_size, n_samples_)

        n_layers = len(stack.p_layers)

        assert len(KL) == n_layers
        assert len(Hp) == n_layers
        assert len(Hq) == n_layers
Пример #4
0
    def test_log_likelihood(self):
        batch_size = 20
        stack = self.stack

        X, X_ = testing.fmatrix((batch_size, self.n_vis), "X")
        n_samples, n_samples_ = testing.iscalar("n_samples")
        n_samples_ = self.n_samples

        log_PX, w, log_P, log_Q, KL, Hp, Hq = stack.log_likelihood(X, n_samples=n_samples)
        do_log_likelihood = theano.function([X, n_samples], [log_PX, log_P, log_Q, w])

        log_PX_, log_P_, log_Q_, w_ = do_log_likelihood(X_, n_samples_)

        print "log_P.shape", log_P_.shape
        print "log_Q.shape", log_Q_.shape
        print "log_PX.shape", log_PX_.shape
        print "w.shape", w_.shape

        assert log_PX_.shape == (batch_size,)
        assert log_P_.shape == (batch_size, n_samples_)
        assert log_Q_.shape == (batch_size, n_samples_)
        assert w_.shape == (batch_size, n_samples_)

        n_layers = len(stack.p_layers)

        assert len(KL) == n_layers
        assert len(Hp) == n_layers
        assert len(Hq) == n_layers
Пример #5
0
    def test_basic_sample(self):
        n_samples = self.n_samples
        layer = self.layer

        Y, Y_ = testing.fmatrix((n_samples, layer.n_Y), name="Y")

        X, log_prob = layer.sample(Y)
        do_sample_p = theano.function([Y], [X, log_prob], name="sample")

        X_, log_prob_ = do_sample_p(Y_)
        assert X_.shape == (n_samples, layer.n_X)
        assert log_prob_.shape == (n_samples, )
        assert not np.isnan(log_prob_).any()
Пример #6
0
    def test_basic_sample(self):
        n_samples = self.n_samples
        layer = self.layer

        Y, Y_ = testing.fmatrix((n_samples, layer.n_Y), name="Y")

        X, log_prob = layer.sample(Y)
        do_sample_p = theano.function([Y], [X, log_prob], name="sample")

        X_, log_prob_ = do_sample_p(Y_)
        assert X_.shape == (n_samples, layer.n_X)
        assert log_prob_.shape == (n_samples,)
        assert not np.isnan(log_prob_).any()
Пример #7
0
    def test_gradients(self):
        batch_size = 20
        stack = self.stack
        n_layers = len(stack.p_layers)

        X, X_ = testing.fmatrix((batch_size, self.n_vis), "X")
        n_samples, n_samples_ = testing.iscalar("n_samples")
        n_samples_ = self.n_samples

        lr_p = np.ones(n_layers)
        lr_q = np.ones(n_layers)

        log_PX, gradients = stack.get_gradients(X, None, lr_p=lr_p, lr_q=lr_q, n_samples=n_samples_)
Пример #8
0
    def test_sample_expected(self):
        n_samples = self.n_samples
        layer = self.layer

        if getattr(layer, "sample_expected", None) is None:
            raise unittest.SkipTest("sample_expected not implemented")

        Y, Y_ = testing.fmatrix((n_samples, layer.n_Y), name="Y")

        X, log_prob = layer.sample(Y)
        do_sample_p = theano.function([Y], [X, log_prob], name="sample")

        X_, log_prob_ = do_sample_p(Y_)
        assert X_.shape == (n_samples, layer.n_X)
        assert log_prob_.shape == (n_samples, )
        assert not np.isnan(log_prob_).any()
Пример #9
0
    def test_sample_expected(self):
        n_samples = self.n_samples
        layer = self.layer

        if getattr(layer, "sample_expected", None) is None:
            raise unittest.SkipTest("sample_expected not implemented")

        Y, Y_ = testing.fmatrix((n_samples, layer.n_Y), name="Y")

        X, log_prob = layer.sample(Y)
        do_sample_p = theano.function([Y], [X, log_prob], name="sample")

        X_, log_prob_ = do_sample_p(Y_)
        assert X_.shape == (n_samples, layer.n_X)
        assert log_prob_.shape == (n_samples,)
        assert not np.isnan(log_prob_).any()
Пример #10
0
    def test_gradients(self):
        batch_size = 20
        stack = self.stack
        n_layers = len(stack.p_layers)

        X, X_ = testing.fmatrix((batch_size, self.n_vis), 'X')
        n_samples, n_samples_ = testing.iscalar('n_samples')
        n_samples_ = self.n_samples

        lr_p = np.ones(n_layers)
        lr_q = np.ones(n_layers)

        log_PX, gradients = stack.get_gradients(X,
                                                None,
                                                lr_p=lr_p,
                                                lr_q=lr_q,
                                                n_samples=n_samples_)