def plot_data_and_prediction(data, means, stds, numos, ax=None, bins=None, n_curves=50, group='x'): assert ax is not None ax.hist(data, bins=bins, rwidth=0.5, facecolor='r', edgecolor='none', normed=True) if bins is not None: if hasattr(bins, '__len__'): xmin = bins[0] xmax = bins[-1] else: xmin = np.min(data) xmax = np.max(data) n_samps = len(means) idxs = map(int, np.round(np.random.uniform(size=n_curves) * n_samps)) x = np.linspace(xmin, xmax, 100) ax.set_xlabel('y') ax.set_ylabel('p(y)') for i in idxs: m = means[i] s = stds[i] lam = 1 / s**2 numo = numos[i] nu = numo + 1 v = np.exp([noncentral_t_like(xi, m, lam, nu) for xi in x]) ax.plot(x, v, color=pretty_blue, zorder=-10) ax.text(0.8, 0.95, '$\mathrm{N}_{%s}=%d$' % ( group, len(data), ), transform=ax.transAxes, horizontalalignment='left', verticalalignment='top') ax.xaxis.set_major_locator(mticker.MaxNLocator(nbins=4)) ax.yaxis.set_major_locator(mticker.MaxNLocator(nbins=4)) ax.set_title('Data Group %s w. Post. Pred.' % (group, ))
def draw_distribution(self, group, x, i): """Draw the ith sample distribution from the model, and compute its values for each element of x. :param string group: specify group, control or variant :param numpy.array x: linspace vector, for which to compute probabilities :param int i: index of the distribution to compute :return: values of the model for the ith distribution :rtype: numpy.array """ m = self.stochastics[group + '_mean'].trace()[i] s = self.stochastics[group + '_sigma'].trace()[i] nu = self.stochastics[group + '_nu_minus_one'].trace()[i] + 1 lam = 1 / s**2 return np.exp([noncentral_t_like(xi, m, lam, nu) for xi in x])
def plot_data_and_prediction( data, means, stds, numos, ax=None, bins=None, n_curves=50, group='x'): assert ax is not None ax.hist( data, bins=bins, rwidth=0.5, facecolor='r', edgecolor='none', normed=True ) if bins is not None: if hasattr(bins,'__len__'): xmin = bins[0] xmax = bins[-1] else: xmin = np.min(data) xmax = np.max(data) n_samps = len(means) idxs = map(int,np.round( np.random.uniform(size=n_curves)*n_samps )) x = np.linspace(xmin, xmax, 100) ax.set_xlabel('y') ax.set_ylabel('p(y)') for i in idxs: m = means[i] s = stds[i] lam = 1/s**2 numo = numos[i] nu = numo+1 v = np.exp([noncentral_t_like(xi,m,lam,nu) for xi in x]) ax.plot(x,v, color=pretty_blue, zorder=-10) ax.text(0.8,0.95,'$\mathrm{N}_{%s}=%d$'%( group, len(data), ), transform=ax.transAxes, horizontalalignment='left', verticalalignment='top' ) ax.xaxis.set_major_locator( mticker.MaxNLocator(nbins=4) ) ax.yaxis.set_major_locator( mticker.MaxNLocator(nbins=4) ) ax.set_title('Data Group %s w. Post. Pred.'%(group,))
def plot_data_and_prediction( data, means, stds, numos, ax, bins = None, n_curves = 50, group = 'x', name = '', colour = 'red', plot_y = False ): if colour == 'red': # for colour plots with data in red use: light_blue = '#89d1ea' red = '#FF0000' elif colour == 'blue': # for colour plots with data in blue use: light_blue = '#FF0000' red = '#89d1ea' else: # for greyscale plots use: light_blue = '#909090' red = '#101010' # plot histogram of data ax.hist(data, bins = bins, rwidth = 0.7, facecolor = red, edgecolor = 'none', normed = True) if bins is not None: if hasattr(bins,'__len__'): xmin = bins[0] xmax = bins[-1] else: xmin = np.min(data) xmax = np.max(data) n_samps = len(means) idxs = map(int, np.round(np.random.uniform(size = n_curves)*n_samps)) x = np.linspace(xmin, xmax, 100) if plot_y: ax.set_xlabel('y', verticalalignment = 'center') ax.set_ylabel('p(y)') for i in idxs: m = means[i] s = stds[i] lam = 1/s**2 numo = numos[i] nu = numo+1 v = np.exp([noncentral_t_like(xi, m, lam, nu) for xi in x]) ax.plot(x, v, color = light_blue, zorder = -10) ax.text(0.99,0.95,'$\mathrm{N}_{%s}= %d$' % (group, len(data),), transform = ax.transAxes, horizontalalignment = 'right', verticalalignment = 'top' ) ax.xaxis.set_major_locator(mticker.MaxNLocator(nbins = 4)) ax.yaxis.set_major_locator(mticker.MaxNLocator(nbins = 4)) ax.set_title(name + ' data \nwith Predicted Posteriors', size = 12, weight = 'bold')