Example #1
0
 def build_prior_KL(self):
     """
     We return the KL for all latent funtions
     """
     KL = 0
     for i in np.arange(self.rank):  # i is the group id.
         for j in np.arange(self.num_latent_list[i]):
             lat_id = np.sum(self.num_latent_list[:i],dtype = np.int64) + j #id of latent function
             if self.whiten_list[lat_id]:
                 if self.q_diag_list[lat_id]:
                     KL +=  kullback_leiblers.gauss_kl_white_diag(self.q_mu_list[lat_id], self.q_sqrt_list[lat_id], self.dim)#rotates the coordinate system to make it independent
                 else:
                     KL += kullback_leiblers.gauss_kl_white(self.q_mu_list[lat_id],self.q_sqrt_list[lat_id], self.dim)
             else:
                 K = self.kern_list[i].K(self.Z[lat_id]) + eye(self.num_inducing_list[lat_id]) * 1e-6 ## compute with the ith kernel
                 if self.q_diag_list[lat_id]:
                     KL += kullback_leiblers.gauss_kl_diag(self.q_mu_list[lat_id], self.q_sqrt_list[lat_id], K, self.dim)
                 else:
                     KL += kullback_leiblers.gauss_kl(self.q_mu_list[lat_id], self.q_sqrt_list[lat_id], K, self.dim)
     if self.tsk:
         for task_id in np.arange(self.num_tasks):
             lat_id = np.sum(self.num_latent_list,dtype = np.int64) + task_id#id of latent function
             if self.whiten_list[lat_id]:
                 if self.q_diag_list[lat_id]:
                     KL +=  kullback_leiblers.gauss_kl_white_diag(self.q_mu_list[lat_id], self.q_sqrt_list[lat_id], self.dim)
                         #rotates the coordinate system to make it independent
                 else:
                     KL += kullback_leiblers.gauss_kl_white(self.q_mu_list[lat_id],self.q_sqrt_list[lat_id], self.dim)
             else:
                 K = self.tskern_list[task_id].K(self.Z[lat_id]) + eye(self.num_inducing_list[lat_id]) * 1e-6 ## compute with the ith kernel
                 if self.q_diag_list[lat_id]:
                     KL += kullback_leiblers.gauss_kl_diag(self.q_mu_list[lat_id], self.q_sqrt_list[lat_id],K, self.dim)
                 else:
                     KL += kullback_leiblers.gauss_kl(self.q_mu_list[lat_id], self.q_sqrt_list[lat_id],K, self.dim)
     return KL
Example #2
0
 def build_prior_KL(self):
     """
     We return the KL for all latent funtions
     """
     KL = 0
     for q in np.arange(self.rank):  # q is the group id.
         for i in np.arange(self.num_latent_list[q]):
             lat_id = np.sum(self.num_latent_list[:q],dtype = np.int64) + i #id of latent function
             if self.whiten_list[lat_id]:
                 if self.q_diag_list[lat_id]:
                     KL +=  kullback_leiblers.gauss_kl_white_diag(self.q_mu_list[lat_id], self.q_sqrt_list[lat_id], self.dim)
                 else:
                     KL += kullback_leiblers.gauss_kl_white(self.q_mu_list[lat_id],self.q_sqrt_list[lat_id], self.dim)
             else:
                 K = self.kern_list[q].K(self.Z[lat_id]) + eye(self.num_inducing_list[lat_id]) * 1e-6 
                 if self.q_diag_list[lat_id]:
                     KL += kullback_leiblers.gauss_kl_diag(self.q_mu_list[lat_id], self.q_sqrt_list[lat_id], K, self.dim)
                 else:
                     KL += kullback_leiblers.gauss_kl(self.q_mu_list[lat_id], self.q_sqrt_list[lat_id], K, self.dim)
     if self.tsk:
         for d in np.arange(self.num_tasks):
             lat_id = np.sum(self.num_latent_list,dtype = np.int64) + d#id of latent function
             if self.whiten_list[lat_id]:
                 if self.q_diag_list[lat_id]:
                     KL +=  kullback_leiblers.gauss_kl_white_diag(self.q_mu_list[lat_id], self.q_sqrt_list[lat_id], self.dim)
                 else:
                     KL += kullback_leiblers.gauss_kl_white(self.q_mu_list[lat_id],self.q_sqrt_list[lat_id], self.dim)
             else:
                 K = self.tskern_list[d].K(self.Z[lat_id]) + eye(self.num_inducing_list[lat_id]) * 1e-6 ## compute with the ith kernel
                 if self.q_diag_list[lat_id]:
                     KL += kullback_leiblers.gauss_kl_diag(self.q_mu_list[lat_id], self.q_sqrt_list[lat_id],K, self.dim)
                 else:
                     KL += kullback_leiblers.gauss_kl(self.q_mu_list[lat_id], self.q_sqrt_list[lat_id],K, self.dim)
     return KL
Example #3
0
 def build_prior_KL(self):
     KL = None
     
     for d in xrange(self.X.shape[1]):
         q_mu_d = self.__getattribute__('q_mu_%d' % d)
         q_sqrt_d = self.__getattribute__('q_sqrt_%d' % d)
         Z_d = self.__getattribute__('Z_%d' % d)
         
         if self.whiten:
             if self.q_diag:
                 KL_d = kullback_leiblers.gauss_kl_white_diag(q_mu_d, q_sqrt_d, self.num_latent)
             else:
                 KL_d = kullback_leiblers.gauss_kl_white(q_mu_d, q_sqrt_d, self.num_latent)
         else:
             K = self.kern[d].K(Z_d) + eye(self.num_inducing[d]) * 1e-6
             if self.q_diag:
                 KL_d = kullback_leiblers.gauss_kl_diag(q_mu_d, q_sqrt_d, K, self.num_latent)
             else:
                 KL_d = kullback_leiblers.gauss_kl(q_mu_d, q_sqrt_d, K, self.num_latent)
                 
         # add things up, we were too lazy to check the type of KL_d
         if KL is None:
             KL = KL_d
         else:
             KL += KL_d
             
     return KL
Example #4
0
 def build_prior_KL(self):
     if self.whiten:
         if self.q_diag:
             KL = kullback_leiblers.gauss_kl_white_diag(self.q_mu, self.q_sqrt, self.num_latent)
         else:
             KL = kullback_leiblers.gauss_kl_white(self.q_mu, self.q_sqrt, self.num_latent)
     else:
         K = self.kern.K(self.Z) + eye(self.num_inducing) * 1e-6
         if self.q_diag:
             KL = kullback_leiblers.gauss_kl_diag(self.q_mu, self.q_sqrt, K, self.num_latent)
         else:
             KL = kullback_leiblers.gauss_kl(self.q_mu, self.q_sqrt, K, self.num_latent)
     return KL
Example #5
0
 def build_prior_KL(self):
     if self.whiten:
         if self.q_diag:
             KL = kullback_leiblers.gauss_kl_white_diag(
                 self.q_mu, self.q_sqrt)
         else:
             KL = kullback_leiblers.gauss_kl_white(self.q_mu, self.q_sqrt)
     else:
         K = self.kern.K(self.Z) + tf.eye(
             self.num_inducing,
             dtype=_settings.tf_float) * _settings.jitter_level
         if self.q_diag:
             KL = kullback_leiblers.gauss_kl_diag(self.q_mu, self.q_sqrt, K)
         else:
             KL = kullback_leiblers.gauss_kl(self.q_mu, self.q_sqrt, K)
     return KL
Example #6
0
    def build_prior_KL(self):

        KL = tf.Variable(0, name='KL', trainable=False, dtype=float_type)
        for i in range(self.D):
            if self.whiten:
                if self.q_diag:
                    KL += gauss_kl_white_diag(self.q_mu[i], self.q_sqrt[i])
                else:
                    KL += gauss_kl_white(self.q_mu[i], self.q_sqrt[i])
            else:
                K = self.kerns[i].K(self.Zs[self.f_indices[i]]) + eye(
                    self.num_inducing[i]) * jitter_level
                if self.q_diag:
                    KL += gauss_kl_diag(self.q_mu[i], self.q_sqrt[i], K)
                else:
                    KL += gauss_kl(self.q_mu[i], self.q_sqrt[i], K)
        return KL
Example #7
0
 def build_prior_KL(self):
     if self.whiten:
         if self.q_diag:
             KL = kullback_leiblers.gauss_kl_white_diag(
                 self.q_mu, self.q_sqrt, self.num_latent)
         else:
             KL = kullback_leiblers.gauss_kl_white(self.q_mu, self.q_sqrt,
                                                   self.num_latent)
     else:
         K = self.kern.K(self.Z) + eye(self.num_inducing) * 1e-6
         if self.q_diag:
             KL = kullback_leiblers.gauss_kl_diag(self.q_mu, self.q_sqrt, K,
                                                  self.num_latent)
         else:
             KL = kullback_leiblers.gauss_kl(self.q_mu, self.q_sqrt, K,
                                             self.num_latent)
     return KL