コード例 #1
0
def test_gaussian_sample():
    del_shared()
    random_state = np.random.RandomState(1999)
    mu = linear([X_sym], [X.shape[1]],
                proj_dim=100,
                name='mu',
                random_state=random_state)
    sigma = softplus([X_sym], [X.shape[1]],
                     proj_dim=100,
                     name='sigma',
                     random_state=random_state)
    random_state = np.random.RandomState(1999)
    r1 = gaussian_sample([mu], [sigma],
                         name="samp1",
                         random_state=random_state)
    random_state = np.random.RandomState(1999)
    r2 = gaussian_sample([mu], [sigma],
                         name="samp2",
                         random_state=random_state)
    random_state = np.random.RandomState(42)
    r3 = gaussian_sample([mu], [sigma],
                         name="samp3",
                         random_state=random_state)
    sample_function = theano.function([X_sym], [r1, r2, r3],
                                      mode="FAST_COMPILE")
    s_r1, s_r2, s_r3 = sample_function(X[:100])

    assert_almost_equal(s_r1, s_r2)
    assert_raises(AssertionError, assert_almost_equal, s_r1, s_r3)

    ss_r1, ss_r2, ss_r3 = sample_function(X[:100])
    assert_raises(AssertionError, assert_almost_equal, s_r1, ss_r1)
コード例 #2
0
def test_gaussian_sample():
    del_shared()
    random_state = np.random.RandomState(1999)
    mu = linear([X_sym], [X.shape[1]], proj_dim=100, name='mu',
                random_state=random_state)
    sigma = softplus([X_sym], [X.shape[1]], proj_dim=100, name='sigma',
                     random_state=random_state)
    random_state = np.random.RandomState(1999)
    r1 = gaussian_sample([mu], [sigma], name="samp1", random_state=random_state)
    random_state = np.random.RandomState(1999)
    r2 = gaussian_sample([mu], [sigma], name="samp2", random_state=random_state)
    random_state = np.random.RandomState(42)
    r3 = gaussian_sample([mu], [sigma], name="samp3", random_state=random_state)
    sample_function = theano.function([X_sym], [r1, r2, r3],
                                      mode="FAST_COMPILE")
    s_r1, s_r2, s_r3 = sample_function(X[:100])

    assert_almost_equal(s_r1, s_r2)
    assert_raises(AssertionError, assert_almost_equal, s_r1, s_r3)

    ss_r1, ss_r2, ss_r3 = sample_function(X[:100])
    assert_raises(AssertionError, assert_almost_equal, s_r1, ss_r1)
コード例 #3
0
ファイル: mnist_vae.py プロジェクト: kastnerkyle/dagbldr
X = mnist["data"].astype("float32")
X_sym = tensor.fmatrix()

# random state so script is deterministic
random_state = np.random.RandomState(1999)

minibatch_size = 100
n_code = 100
n_hid = 200
width = 28
height = 28
n_input = width * height

# encode path aka q
l1_enc = softplus([X_sym], [X.shape[1]], proj_dim=n_hid, name='l1_enc',
                  random_state=random_state)
l2_enc = softplus([l1_enc], [n_hid], proj_dim=n_hid, name='l2_enc',
                  random_state=random_state)
code_mu = linear([l2_enc], [n_hid], proj_dim=n_code, name='code_mu',
                 random_state=random_state)
code_log_sigma = linear([l2_enc], [n_hid], proj_dim=n_code,
                        name='code_log_sigma', random_state=random_state)
kl = gaussian_log_kl([code_mu], [code_log_sigma]).mean()
sample_state = np.random.RandomState(2177)
samp = gaussian_log_sample([code_mu], [code_log_sigma], name='samp',
                           random_state=sample_state)

# decode path aka p
l1_dec = softplus([samp], [n_code], proj_dim=n_hid, name='l1_dec',
                  random_state=random_state)
l2_dec = softplus([l1_dec], [n_hid], proj_dim=n_hid, name='l2_dec',
コード例 #4
0
X = mnist["data"].astype("float32")
X_sym = tensor.fmatrix()

# random state so script is deterministic
random_state = np.random.RandomState(1999)

minibatch_size = 100
n_code = 100
n_hid = 200
width = 28
height = 28
n_input = width * height

# encode path aka q
l1_enc = softplus([X_sym], [X.shape[1]],
                  proj_dim=n_hid,
                  name='l1_enc',
                  random_state=random_state)
l2_enc = softplus([l1_enc], [n_hid],
                  proj_dim=n_hid,
                  name='l2_enc',
                  random_state=random_state)
code_mu = linear([l2_enc], [n_hid],
                 proj_dim=n_code,
                 name='code_mu',
                 random_state=random_state)
code_log_sigma = linear([l2_enc], [n_hid],
                        proj_dim=n_code,
                        name='code_log_sigma',
                        random_state=random_state)
kl = gaussian_log_kl([code_mu], [code_log_sigma]).mean()
sample_state = np.random.RandomState(2177)