Beispiel #1
0
def test_rand_gaussian():
    X = np.empty((4000, 1000), dtype=np.float32)
    Y = op.rand_gaussian_like(X)
    rtol = 1e-3
    assert (Y.mean() - 0.0) < rtol, "mean: %f" % Y.mean()
    assert Y.std() - 1.0 < rtol, "std: %f" % Y.std()

    Y = op.rand_gaussian_like(X, mu=5.0, sigma=2.0)
    rtol = 1e-3
    assert (Y.mean() - 5.0) < rtol, "mean: %f" % Y.mean()
    assert Y.std() - 2.0 < rtol, "std: %f" % Y.std()

    Xd = op.to_gpu(X)
    Yd = gpuarray.empty_like(Xd)
    Y = op.to_cpu(op.rand_gaussian_like(Xd))
    rtol = 1e-2
    assert (Y.mean() - 0.0) < rtol, "mean: %f" % Y.mean()
    assert Y.std() - 1.0 < rtol, "std: %f" % Y.std()

    Y = op.to_cpu(op.rand_gaussian_like(Xd, mu=5.0, sigma=2.0))
    rtol = 1e-2
    assert (Y.mean() - 5.0) < rtol, "mean: %f" % Y.mean()
    assert Y.std() - 2.0 < rtol, "std: %f" % Y.std()
Beispiel #2
0
def test_rand_gaussian():
    X = np.empty((4000, 1000), dtype=np.float32)
    Y = op.rand_gaussian_like(X)
    rtol = 1e-3
    assert (Y.mean() - 0.0) < rtol, "mean: %f" % Y.mean()
    assert Y.std() - 1.0 < rtol, "std: %f" % Y.std()

    Y = op.rand_gaussian_like(X, mu=5.0, sigma=2.0)
    rtol = 1e-3
    assert (Y.mean() - 5.0) < rtol, "mean: %f" % Y.mean()
    assert Y.std() - 2.0 < rtol, "std: %f" % Y.std()

    Xd = op.to_gpu(X)
    Yd = gpuarray.empty_like(Xd)
    Y = op.to_cpu(op.rand_gaussian_like(Xd))
    rtol = 1e-2
    assert (Y.mean() - 0.0) < rtol, "mean: %f" % Y.mean()
    assert Y.std() - 1.0 < rtol, "std: %f" % Y.std()

    Y = op.to_cpu(op.rand_gaussian_like(Xd, mu=5.0, sigma=2.0))
    rtol = 1e-2
    assert (Y.mean() - 5.0) < rtol, "mean: %f" % Y.mean()
    assert Y.std() - 2.0 < rtol, "std: %f" % Y.std()
Beispiel #3
0
    def _sample_visibles(self, h):
        """Sample from the distribution P(v|h).

        Parameters
        ----------
        h : array-like, shape (n_samples, n_components)
            Values of the hidden layer to sample from.

        Returns
        -------
        v : array-like, shape (n_samples, n_features)
            Values of the visible layer.
        """
        p = self._mean_visibles(h)
        return p + op.rand_gaussian_like(p)
Beispiel #4
0
    def _sample_visibles(self, h):
        """Sample from the distribution P(v|h).

        Parameters
        ----------
        h : array-like, shape (n_samples, n_components)
            Values of the hidden layer to sample from.

        Returns
        -------
        v : array-like, shape (n_samples, n_features)
            Values of the visible layer.
        """
        p = self._mean_visibles(h)
        return p + op.rand_gaussian_like(p)