コード例 #1
0
ファイル: bnn.py プロジェクト: yiyg510/generativeSSL
def sampleCatBNN(weights, n_hid):
    """ return a sample from weights of a categorical BNN """
    wTilde = sampleBNN(weights, n_hid)
    meanW, meanB = weights['Wout_mean'], weights['bout_mean']
    logvarW, logvarB = weights['Wout_logvar'], weights['bout_logvar']
    wTilde['Wout'], wTilde['bout'] = tf.squeeze(
        dgm.sampleNormal(meanW, logvarW, 1),
        0), tf.squeeze(dgm.sampleNormal(meanB, logvarB, 1), 0)
    return wTilde
コード例 #2
0
ファイル: bnn.py プロジェクト: yiyg510/generativeSSL
def sampleBNN(weights, n_hid):
    """ sample weights from a variational approximation """
    wTilde = {}
    for layer in range(len(n_hid)):
        wName, bName = 'W' + str(layer), 'b' + str(layer)
        meanW, meanB = weights['W' + str(layer) +
                               '_mean'], weights['b' + str(layer) + '_mean']
        logvarW, logvarB = weights['W' + str(layer) +
                                   '_logvar'], weights['b' + str(layer) +
                                                       '_logvar']
        wTilde[wName], wTilde[bName] = tf.squeeze(
            dgm.sampleNormal(meanW, logvarW, 1),
            0), tf.squeeze(dgm.sampleNormal(meanB, logvarB, 1), 0)
    return wTilde
コード例 #3
0
 def sample_z(self, x, y, n_samples=None):
     if n_samples == None:
         n_samples = self.mc_samples
     l_qz_in = tf.concat([x, y], axis=-1)
     z_mean = dgm.forwardPass(self.q_z_xy_mean, l_qz_in)
     z_log_var = dgm.forwardPass(self.q_z_xy_log_var, l_qz_in)
     return z_mean, z_log_var, dgm.sampleNormal(z_mean, z_log_var,
                                                n_samples)
コード例 #4
0
 def sample_a(self, x, n_samples=None):
     if n_samples == None:
         n_samples = self.mc_samples
     l_qa_in = x
     a_mean = dgm.forwardPass(self.q_a_x_mean, l_qa_in)
     a_log_var = dgm.forwardPass(self.q_a_x_log_var, l_qa_in)
     return a_mean, a_log_var, dgm.sampleNormal(a_mean, a_log_var,
                                                n_samples)
コード例 #5
0
 def sample_z(self, x, y, a, n_samples=None):
     if n_samples == None:
         n_samples = 1
     l_qz_in = tf.reshape(tf.concat([x, y, a], axis=-1),
                          [-1, self.n_x + self.n_y + self.n_a])
     z_mean = dgm.forwardPass(self.q_z_axy_mean, l_qz_in)
     z_log_var = dgm.forwardPass(self.q_z_axy_log_var, l_qz_in)
     z = dgm.sampleNormal(z_mean, z_log_var, mc_samps=n_samples)
     z_mean, z_log_var = tf.reshape(
         z_mean, [self.mc_samples, -1, self.n_z]), tf.reshape(
             z_log_var, [self.mc_samples, -1, self.n_z])
     z = tf.reshape(z, [self.mc_samples, -1, self.n_z])
     return z_mean, z_log_var, z