Example #1
0
    def _new_params(self, n_new_features):
        new_H = np.zeros([self.D, n_new_features])
        new_Wn = np.zeros(n_new_features)
        shared_hyperprior = np.zeros(n_new_features)

        for k in range(n_new_features):
            hyp_prior = self.pSharedHyp.prior.rvs()
            # loop through the rows and assign samples
            new_Wn[k] = truncated_sampler(mu=0,
                                          std=1/np.sqrt(hyp_prior),
                                          lower_bound=self.trunc_low_bound,
                                          upper_bound=self.trunc_up_bound)
            shared_hyperprior[k] = hyp_prior
            for d in range(self.D):
                new_H[d,k] =  truncated_sampler(mu=0,
                                              std=1/np.sqrt(hyp_prior),
                                              lower_bound=self.trunc_low_bound,
                                              upper_bound=self.trunc_up_bound)
        return new_H, new_Wn, shared_hyperprior
Example #2
0
 def _add_new_W_hyperpriors(self, new_Wn, new_hyperpriors, k_new, n):
     self.pSharedHyp.add_new_features(new_hyperpriors, k_new)
     add_W = np.empty((k_new, self.N))
     for i, param in enumerate(new_hyperpriors):
         param = np.broadcast_to(param, self.N)
         add_W[i,:] = truncated_sampler(mu=0,
                                        std=1/np.sqrt(param),
                                        lower_bound=self.trunc_low_bound,
                                        upper_bound=self.trunc_up_bound)
     add_W[:,n] = new_Wn
     self.pW.add_new_features(add_W, k_new, n)
Example #3
0
 def _add_new_W_hyperpriors(self, new_Wn, new_hyperpriors, k_new, n):
     new_hyp_H, new_hyp_Wn = new_hyperpriors
     self.pHypH.add_new_features(new_hyp_H, k_new)
     add_W = np.empty((k_new, self.N))
     add_hyp_W = add_W.copy()
     for n in range(self.N):
         for k in range(k_new):
             hyp_prior = self.pHypW.prior.rvs()
             add_hyp_W[k,n] = hyp_prior
             add_W[k,n] = truncated_sampler(mu=0,
                                           std=1/np.sqrt(hyp_prior),
                                           lower_bound=self.trunc_low_bound,
                                           upper_bound=self.trunc_up_bound)
     add_hyp_W[:,n] = new_hyp_Wn
     add_W[:,n] = new_Wn
     self.pW.add_new_features(add_W, k_new, n)
     self.pHypW.add_new_features(add_hyp_W, k_new)