def get_tr_kernel(self, sstats_list): self.N_tr = sstats_list[0].reshape((-1, self.D)).shape[0] # Initialise train kernel. tr_kernel = np.zeros((self.N_tr, self.N_tr)) # Initialise normalization constants. self.Zx = np.zeros(self.N_tr) for ii, sstats in enumerate(sstats_list): self._append_data( *standardize(FVModel.sstats_to_features(sstats, self.gmm))) self.xx[ii] = power_normalize(self.xx[ii], 0.5) self.Zx += compute_L2_normalization(self.xx[ii]) tr_kernel += np.dot(self.xx[ii], self.xx[ii].T) # Normalize kernel. tr_kernel /= np.sqrt( self.Zx[:, np.newaxis] * self.Zx[np.newaxis]) return tr_kernel
def get_te_kernel(self, sstats_list): self.N_te = sstats_list[0].reshape((-1, self.D)).shape[0] # Initialise train kernel. te_kernel = np.zeros((self.N_te, self.N_tr)) # Initialise normalization constants. self.Zy = np.zeros(self.N_te) for ii, sstats in enumerate(sstats_list): yy = standardize( FVModel.sstats_to_features(sstats, self.gmm), self.mu[ii], self.sigma[ii])[0] yy = power_normalize(yy, 0.5) self.Zy += compute_L2_normalization(yy) te_kernel += np.dot(yy, self.xx[ii].T) # Normalize kernel. te_kernel /= np.sqrt( self.Zy[:, np.newaxis] * self.Zx[np.newaxis]) return te_kernel
def test_standardize_one_dimensional(self): yy, mu, sigma = utils.standardize(np.random.rand(self.D))