def evaluate_random_numbers(model, split, n_marginals=5): """ Evaluates the model by looking at the distribution of the random numbers for some data split. The more gaussian it look, the better the model fits the data. :param model: the model :param split: the data split, must be 'trn', 'val', or 'tst' :param n_marginals: number of marginal histograms of random numbers to plot """ assert is_data_loaded(), 'Dataset hasn\'t been loaded' # choose which data split to use data_split = getattr(data, split, None) if data_split is None: raise ValueError('Invalid data split') # determine whether model is conditional if is_conditional(model): x = [data_split.y, data_split.x] else: x = data_split.x # calculate random numbers u = model.calc_random_numbers(x) # estimate kl to unit gaussian q = pdfs.fit_gaussian(u) p = pdfs.Gaussian(m=np.zeros(data.n_dims), S=np.eye(data.n_dims)) print('KL(q||p) = {0:.2f}'.format(q.kl(p))) # plot some marginals util.plot_hist_marginals(u[:, :n_marginals]) plt.show()
def show_histograms(self, split): data_split = getattr(self, split, None) if data_split is None: raise ValueError('Invalid data split') util.plot_hist_marginals(data_split.x) plt.show()