Пример #1
0
 def generate_posterior_predictive_hypercube(self, n_per_sample=1):
     postpred = np.empty((self.nSamp, n_per_sample, self.nCol))
     for n in range(self.nSamp):
         delta_new = choice(self.nMix, n_per_sample, p=self.samples.pi[n])
         zeta_new = self.samples.zeta[n, delta_new]
         postpred[n] = euclidean_to_simplex(
             gamma(shape=zeta_new, size=(n_per_sample, self.nCol)), )
     simplex = postpred.reshape(self.nSamp * n_per_sample, self.nCol)
     return euclidean_to_hypercube(simplex)
Пример #2
0
 def read_data(self, path):
     conn = sql.connect(path)
     self.V = pd.read_sql('select * from data;', conn).values
     self.S = data.euclidean_to_simplex(self.V)
     self.Yl = data.angular_to_euclidean(data.euclidean_to_angular(self.V))
     self.A = data.euclidean_to_angular(self.Yl)
     self.Vi = self.cast_to_cube(self.A)
     self.pVi = self.probit(self.Vi)
     conn.close()
     return
Пример #3
0
 def read_data(self, path):
     self.Z = pd.read_csv(path).values
     self.R = self.Z.max(axis=1)
     self.V = (self.Z.T / self.R).T
     self.S = data.euclidean_to_simplex(self.V)
     self.A = data.euclidean_to_angular(self.V)
     self.Yl = data.angular_to_euclidean(self.A)
     self.Vi = self.cast_to_cube(self.A)
     self.pVi = self.probit(self.Vi)
     self.I = (np.arange(self.Z.shape[0]), )
     return
Пример #4
0
 def generate_posterior_predictive_hypercube(self, n_per_sample=1, m=10):
     gammas = self.generate_posterior_predictive_gammas(n_per_sample, m)
     hypcube = euclidean_to_hypercube(gammas[:, :self.nCol])
     simplex = []
     cat_idx = np.where(self.sigma_unity)[0][1:]
     for i in range(cat_idx.shape[0]):
         cat_start = cat_idx[i]
         try:
             cat_end = cat_idx[i + 1]
         except IndexError:
             cat_end = self.sigma_unity.shape[0]
         simplex.append(euclidean_to_simplex(gammas[:, cat_start:cat_end]))
     return np.hstack([hypcube] + simplex)
Пример #5
0
 def generate_posterior_predictive_hypercube(self, n_per_sample=1, m=10):
     gammas = self.generate_posterior_predictive_gammas(n_per_sample, m)
     # hypercube transformation for real variates
     hypcube = euclidean_to_hypercube(gammas[:, :self.nCol])
     # simplex transformation for categ variates
     simplex_reverse = []
     indices = list(np.arange(self.nCol + self.nCat))
     # Foe each category, last first
     for i in list(range(self.cats.shape[0]))[::-1]:
         # identify the ending index (+1 to include boundary)
         cat_length = self.cats[i]
         cat_end = indices.pop() + 1
         # identify starting index
         for _ in range(cat_length - 1):
             cat_start = indices.pop()
         # transform gamma variates to simplex
         simplex_reverse.append(
             euclidean_to_simplex(gammas[:, cat_start:cat_end]))
     # stack hypercube and categorical variables side by side.
     return np.hstack([hypcube] + simplex_reverse[::-1])
Пример #6
0
 def energy_score_L1(self):
     predicted = self.L1(self.prediction())
     return energy_score_euclidean(predicted,
                                   euclidean_to_simplex(self.data.Yl))
Пример #7
0
 def posterior_predictive_loss_L1(self):
     predicted = self.L1(self.prediction())
     return self.__postpredloss(predicted,
                                euclidean_to_simplex(self.data.Yl))
Пример #8
0
 def generate_posterior_predictive_simplex(self, n_per_sample = 1):
     gammas = self.generate_posterior_predictive_gammas(n_per_sample)
     return euclidean_to_simplex(gammas)