示例#1
0
 def build_model(self):
     """ Define model components and variables """
     self.create_placeholders()
     self.initialize_networks()
     ## model variables and relations ##
     # infernce #
     self.y_ = dgm.forwardPassCatLogits(self.x,
                                        self.qy_x,
                                        self.n_hid,
                                        self.nonlinearity,
                                        self.bn,
                                        scope='qy_x',
                                        reuse=False)
     self.qz_in = tf.concat([self.x, self.y], axis=-1)
     self.qz_mean, self.qz_lv, self.z_ = dgm.samplePassGauss(
         self.qz_in,
         self.qz_xy,
         self.n_hid,
         self.nonlinearity,
         self.bn,
         scope='qz_xy',
         reuse=False)
     # generative #
     self.z_prior = tf.random_normal([100, self.n_z])
     if self.x_dist == 'Gaussian':
         self.px_mean, self.px_lv, self.x_ = dgm.samplePassGauss(
             self.z_prior,
             self.px_z,
             self.n_hid,
             self.nonlinearity,
             self.bn,
             scope='px_z',
             reuse=False)
     elif self.x_dist == 'Bernoulli':
         self.x_ = dgm.forwardPassBernoulli(self.z_prior,
                                            self.px_z,
                                            self.n_hid,
                                            self.nonlinearity,
                                            self.bn,
                                            scope='px_z',
                                            reuse=False)
     self.py_in = tf.concat([self.x_, self.z_prior], axis=-1)
     self.py_ = dgm.forwardPassCat(self.py_in,
                                   self.py_xz,
                                   self.n_hid,
                                   self.nonlinearity,
                                   self.bn,
                                   scope='py_xz',
                                   reuse=False)
     self.predictions = self.predict(self.x)
示例#2
0
    def build_model(self):
	""" Define model components and variables """
	self.create_placeholders()
	self.initialize_networks()
	## model variables and relations ##
	# infernce #
        self.qc_mean, self.qc_lv, self.c_ = dgm.samplePassStatistic(self.x, self.qc_x, self.n_hid, self.nonlinearity, self.bn, self.mc_samples, scope='qc_x', reuse=False)
	self.c_ = tf.reshape(self.c_, [-1, self.n_c])
	self.qz_in = tf.concat([self.x, tf.tile(self.c_, [tf.shape(self.x)[0], 1])], axis=-1) 
	self.qz_mean, self.qz_lv, self.qz_ = dgm.samplePassGauss(self.qz_in, self.qz_xc, self.n_hid, self.nonlinearity, self.bn, scope='qz_xc', reuse=False)
	# generative #
	self.c_prior = tf.random_normal([1, self.n_c])
	self.pz_mean, self.pz_lv, self.pz_ = self.sample_pz(self.c_prior, 200, reuse=False)
	self.pz_ = tf.reshape(self.pz_, [-1, self.n_z])
	if self.x_dist == 'Gaussian':
	    self.px_mean, self.px_lv, self.px_ = dgm.samplePassGauss(self.pz_, self.px_z, self.n_hid, self.nonlinearity, self.bn, scope='px_z', reuse=False)
	elif self.x_dist == 'Bernoulli':
	   self.px_ = dgm.forwardPassBernoulli(self.pz_, self.px_z, self.n_hid, self.nonlinearity, self.bn, scope='px_z', reuse=False)	
示例#3
0
    def build_model(self):
	""" Define model components and variables """
	self.create_placeholders()
	self.initialize_networks()
	## model variables and relations ##
	# inference #
        self.y_ = dgm.forwardPassCatLogits(self.x, self.qy_x, self.n_hid, self.nonlinearity, self.bn, scope='qy_x', reuse=False)
	self.qz_in = tf.concat([self.x, self.y], axis=-1) 	
	self.qz_mean, self.qz_lv, self.z_ = dgm.samplePassGauss(self.qz_in, self.qz_xy, self.n_hid, self.nonlinearity, self.bn, scope='qz_xy', reuse=False)
	# generative #
	self.z_prior = tf.random_normal([tf.shape(self.y)[0], self.n_z])
	self.px_in = tf.concat([self.y, self.z_prior], axis=-1)
	if self.x_dist == 'Gaussian':
	    self.px_mean, self.px_lv, self.x_ = dgm.samplePassGauss(self.px_in, self.px_yz, self.n_hid, self.nonlinearity, self.bn, scope='px_yz', reuse=False)
	    self.x_ = tf.reshape(self.x_, [-1, self.n_x])
	elif self.x_dist == 'Bernoulli':
	    self.x_ = dgm.forwardPassBernoulli(self.px_in, self.px_yz, self.n_hid, self.nonlinearity, self.bn, scope='px_yz', reuse=False)
	self.W = bnn.sampleCatBNN(self.py_x, self.n_hid)
	self.py = dgm.forwardPassCat(self.x_, self.W, self.n_hid, self.nonlinearity, self.bn, scope='py_x', reuse=False)
	self.predictions = self.predict(self.x, n_samps=50, training=False)