Esempio n. 1
0
File: OptVAE.py Progetto: yyht/igr
 def __init__(self, model, optimizer, hyper):
     super().__init__(model=model, optimizer=optimizer, hyper=hyper)
     self.temp = tf.constant(value=hyper['temp'], dtype=tf.float32)
     self.prior_file = hyper['prior_file']
     self.mu_0 = tf.constant(value=0., dtype=tf.float32, shape=(1, 1, 1, 1))
     self.xi_0 = tf.constant(value=0., dtype=tf.float32, shape=(1, 1, 1, 1))
     self.ng = GaussianSoftmaxDist(mu=self.mu_0, xi=self.xi_0)
     self.load_prior_values()
Esempio n. 2
0
File: OptVAE.py Progetto: yyht/igr
 def reparameterize(self, params_broad):
     mu, xi = params_broad
     self.ng = GaussianSoftmaxDist(mu=mu,
                                   xi=xi,
                                   temp=self.temp,
                                   sample_size=self.sample_size)
     self.ng.do_reparameterization_trick()
     z_discrete = [self.ng.log_psi]
     return z_discrete
Esempio n. 3
0
def determine_distribution(model_type, params, temp, samples_n):
    if model_type == 'GSMDis':
        dist = GaussianSoftmaxDist(mu=params[0],
                                   xi=params[1],
                                   sample_size=samples_n,
                                   temp=temp)
    elif model_type == 'ExpGSDis':
        dist = ExpGSDist(log_pi=params[0], sample_size=samples_n, temp=temp)
    else:
        raise RuntimeError
    return dist
Esempio n. 4
0
File: OptVAE.py Progetto: yyht/igr
 def reparameterize(self, params_broad):
     mean, log_var, mu, xi = params_broad
     z_norm = sample_normal(mean=mean, log_var=log_var)
     self.ng = GaussianSoftmaxDist(mu=mu,
                                   xi=xi,
                                   temp=self.temp,
                                   sample_size=self.sample_size)
     self.ng.do_reparameterization_trick()
     z_discrete = self.ng.psi
     self.n_required = z_discrete.shape[1]
     z = [z_norm, z_discrete]
     return z
Esempio n. 5
0
File: OptVAE.py Progetto: yyht/igr
 def reparameterize(self, params_broad):
     mu, xi = params_broad
     epsilon = tf.random.normal(shape=mu.shape)
     self.ng = GaussianSoftmaxDist(mu=mu,
                                   xi=xi,
                                   temp=self.temp,
                                   sample_size=self.sample_size)
     sigma = tf.math.exp(xi)
     self.ng.lam = self.model.planar_flow(mu + sigma * epsilon)
     self.ng.log_psi = self.ng.lam - tf.math.reduce_logsumexp(
         self.ng.lam, axis=1, keepdims=True)
     # psi = tf.math.softmax(lam / self.temp, axis=1)
     z_discrete = [self.ng.log_psi]
     return z_discrete