我们从Python开源项目中,提取了以下22个代码示例,用于说明如何使用pylab.ioff()。
def add_images_section(self): style = "width:65%" import pylab pylab.ioff() def plotter1(filename): self.bam.plot_bar_flags(logy=True, filename=filename) html1 = self.create_embedded_png(plotter1, "filename", style=style) def plotter2(filename): self.bam.plot_bar_flags(logy=False, filename=filename) html2 = self.create_embedded_png(plotter2, "filename", style=style) def plotter3(filename): self.bam.plot_bar_mapq(filename=filename) html3 = self.create_embedded_png(plotter3, "filename", style=style) self.sections.append({ "name": "Image", "anchor": "table", "content": html1 + html2 + html3 })
def plotdata(obsmode,spectrum,val,odict,sdict, instr,fieldname,outdir,outname): isetting=P.isinteractive() P.ioff() P.clf() P.plot(obsmode,val,'.') P.ylabel('(pysyn-syn)/syn') P.xlabel('obsmode') P.title("%s: %s"%(instr,fieldname)) P.savefig(os.path.join(outdir,outname+'_obsmode.ps')) P.clf() P.plot(spectrum,val,'.') P.ylabel('(pysyn-syn)/syn') P.xlabel('spectrum') P.title("%s: %s"%(instr,fieldname)) P.savefig(os.path.join(outdir,outname+'_spectrum.ps')) matplotlib.interactive(isetting)
def plotstuff(): X__ = np.load("tm_X.npy") S_pred = np.load("tm_S_pred.npy") E_pred = np.load("tm_E_pred.npy") M = np.load("tm_M.npy") pl.ioff() pl.suptitle("mode: %s (X: FM input, state pred: FM output)" % ("bluib")) pl.subplot(511) pl.title("X[goals]") pl.plot(X__[10:,0:4], "-x") pl.subplot(512) pl.title("X[prediction error]") pl.plot(X__[10:,4:], "-x") pl.subplot(513) pl.title("state pred") pl.plot(S_pred) pl.subplot(514) pl.title("error state - goal") pl.plot(E_pred) pl.subplot(515) pl.title("state") pl.plot(M) pl.show()
def rh_e2p_fit(self): """Initial fit of e2p map with a batch of data""" # 2. now we learn e2p mapping (conditional joint density model for dealing with ambiguity) # ## prepare data if not self.attr_check(["logs", "e2p"]): return # print self.logs["EP"].shape, self.logs["X_"].shape # pl.ioff() # pl.plot(self.logs["X_"]) # pl.show() # print "self.logs['X_']", self.logs["X_"] print("%s.rh_e2p_fit batch fitting of e2p (%s)" % (self.__class__.__name__, self.mm.__class__.__name__)) self.mm.fit(np.asarray(self.e2p.X_)[10:], np.asarray(self.e2p.y_)[10:]) # # fit gmm # self.cen_lst, self.cov_lst, self.p_k, self.logL = gmm.em_gm(self.logs["EP"], K = 10, max_iter = 1000,\ # verbose = False, iter_call = None) # print "rh_e2p_fit gmm: Log likelihood (how well the data fits the model) = ", self.logL # # print "rh_e2p_fit gmm:", np.array(self.cen_lst).shape, np.array(self.cov_lst).shape, self.p_k.shape
def plot_scattermatrix(df, title = "plot_scattermatrix"): """plot a scattermatrix of dataframe df""" if df is None: print "plot_scattermatrix: no data passed" return from pandas.tools.plotting import scatter_matrix # df = pd.DataFrame(X, columns=['x1_t', 'x2_t', 'x1_tptau', 'x2_tptau', 'u_t']) # scatter_data_raw = np.hstack((np.array(Xs), np.array(Ys))) # scatter_data_raw = np.hstack((Xs, Ys)) # print "scatter_data_raw", scatter_data_raw.shape pl.ioff() # df = pd.DataFrame(scatter_data_raw, columns=["x_%d" % i for i in range(scatter_data_raw.shape[1])]) sm = scatter_matrix(df, alpha=0.2, figsize=(10, 10), diagonal='hist') fig = sm[0,0].get_figure() fig.suptitle(title) if SAVEPLOTS: fig.savefig("fig_%03d_scattermatrix.pdf" % (fig.number), dpi=300) fig.show() # pl.show()
def add_image(self): import pylab def plotter(filename): pylab.ioff() self.data.hist() pylab.savefig(filename) html = self.create_embedded_png(plotter, "filename", style='width:65%') self.sections.append({ "name": "Image", "anchor": "table", "content": html }) # Let us create some data.
def show(X, C, centroids, keep = False): import time time.sleep(0.5) plt.cla() plt.plot(X[C == 0, 0], X[C == 0, 1], '*b', X[C == 1, 0], X[C == 1, 1], '*r', X[C == 2, 0], X[C == 2, 1], '*g') plt.plot(centroids[:,0],centroids[:,1],'*m',markersize=20) plt.draw() if keep : plt.ioff() plt.show() # generate 3 cluster data # data = np.genfromtxt('data1.csv', delimiter=',')
def make_panel_of_intensity_slices(fn, c_n=9): M.rcParams.update({'font.size': 13}) intensList = read.extract_arr_from_h5(fn, "/history/intensities", n=c_n) quatList = read.extract_arr_from_h5(fn, "/history/quaternion", n=-1) P.ioff() intens_len = len(intensList) sqrt_len = int(N.sqrt(intens_len)) intens_sh = intensList[0].shape iter_labels = read.create_interval_labels(len(quatList), c_n)[:intens_len] to_plot = intensList[:intens_len] quat_label = quatList[N.array(iter_labels)-1][:intens_len] plot_titles = ["iter_%d, quat_%d"%(ii,jj) for ii,jj in zip(iter_labels, quat_label)] fig, ax = P.subplots(sqrt_len, sqrt_len, sharex=True, sharey=True, figsize=(1.8*sqrt_len, 2.*sqrt_len)) plt_counter = 0 for r in range(sqrt_len): for c in range(sqrt_len): ax[r,c].set_title(plot_titles[plt_counter]) curr_slice = to_plot[plt_counter][intens_sh[0]/2] curr_slice = curr_slice*(curr_slice>0.) + 1.E-8*(curr_slice<=0.) ax[r,c].set_title(plot_titles[plt_counter], fontsize=11.5) im = ax[r,c].imshow(N.log10(curr_slice), vmin=-6.5, vmax=-3.5, aspect='auto', cmap=P.cm.coolwarm) plt_counter += 1 fig.subplots_adjust(wspace=0.01) (shx, shy) = curr_slice.shape (h_shx, h_shy) = (shx/2, shy/2) xt = N.linspace(0.5*h_shx, shx-.5*h_shx-1, 3).astype('int') xt_l = N.linspace(-0.5*h_shx, 0.5*h_shx, 3).astype('int') yt = N.linspace(0, shy-1, 3).astype('int') yt_l = N.linspace(-1*h_shy, h_shy, 3).astype('int') P.setp(ax, xticks=xt, xticklabels=xt_l, yticks=yt, yticklabels=yt_l) cbar_ax = fig.add_axes([0.9, 0.1, 0.025, 0.8]) fig.colorbar(im, cax=cbar_ax, label="log10(intensities)") img_name = "recon_series.pdf" P.savefig(img_name, bbox_inches='tight') print("Image has been saved as %s" % img_name) P.close(fig)
def make_error_time_plot(fn): M.rcParams.update({'font.size': 12}) errList = read.extract_arr_from_h5(fn, "/history/error", n=-1) timesList = read.extract_arr_from_h5(fn, "/history/time", n=-1) quatList = read.extract_arr_from_h5(fn, "/history/quaternion", n=-1) quatSwitchPos = N.where(quatList[:-1]-quatList[1:] != 0)[0] + 1 P.ioff() fig, ax = P.subplots(2, 1, sharex=True, figsize=(6,6)) fig.subplots_adjust(hspace=0.1) iters = range(1, len(errList)+1) ax[0].set_title("model change vs iterations") #ax[0].set_xlabel("iteration") ax[0].set_ylabel("log10(rms diffraction \nvolume change per voxel)") err_to_plot = N.log10(errList) ax[0].plot(iters, err_to_plot, 'k-') ax[0].plot(iters, err_to_plot, 'ko') (e_min, e_max) = (err_to_plot.min()-0.3, err_to_plot.max()) e_int = 0.1*(e_max-e_min) ax[0].plot([1, 1], [e_min, e_max + e_int], 'k-') ax[0].text(2, e_max+e_int, "quat%d"%quatList[0], size=8, rotation=-0, ha='left', va='center', color='w', bbox=dict(boxstyle="larrow,pad=0.1",facecolor='0.1') ) for n,qs in enumerate(quatSwitchPos): ax[0].plot([qs+1, qs+1], [e_min, e_max + e_int], 'k-') ax[0].text(qs, e_max+(1-n)*e_int, "quat%d"%quatList[qs], size=8, rotation=-0, ha='right', va='center', color='w', bbox=dict(boxstyle="rarrow,pad=0.1",facecolor='0.1') ) ax[1].set_xlabel("iteration") ax[1].set_ylabel("time per iteration (s)") ax[1].plot(iters, timesList, 'k-') ax[1].plot(iters, timesList, 'ko') (t_min, t_max) = (timesList.min()-100, timesList.max()) t_int = 0.1*(t_max-t_min) ax[1].plot([1, 1], [t_min, t_max + t_int], 'k-') ax[1].text(2, t_max+t_int, "quat%d"%quatList[0], size=8, rotation=-0, ha='left', va='center', color='w', bbox=dict(boxstyle="larrow,pad=0.1",facecolor='0.1') ) for n,qs in enumerate(quatSwitchPos): ax[1].plot([qs+1, qs+1], [t_min, t_max+t_int], 'k-') ax[1].text(qs+0.5, t_min, "quat%d"%quatList[qs], size=8, rotation=45, ha='right', va='center', color='w', bbox=dict(boxstyle="rarrow,pad=0.1",facecolor='0.1')) img_name = "time_and_error_plot.pdf" P.savefig(img_name, bbox_inches='tight') print("Image has been saved as %s" % img_name) P.close(fig)
def wave_plotting(sonic, block=False): if isinstance(sonic.wave_bin_data, list): bin_buffer = bytearray() for data in sonic.wave_bin_data: bin_buffer.extend(data) sonic.wave_bin_data = bytes(bin_buffer) elif not isinstance(sonic.wave_bin_data, bytes): raise Exception("Type of bin_data need bytes!") #????????????????????????????????????? wave_data = numpy.fromstring(sonic.wave_bin_data, dtype=number_type.get(sonic.sample_width)) #???????wave_data??????short??????????????????????? # ??????????????????LRLRLRLR....LR?L??????????R????????????wave_data?sharp wave_data.shape = (sonic.sample_length, sonic.channels) wave_data = wave_data.T time = numpy.arange(0, sonic.sample_length) * (1.0 / sonic.sample_frequency) # ???? colors = ['b', 'g', 'r', 'c', 'm', 'y', 'k'] pylab.figure() for index in range(0, sonic.channels): pylab.subplot(sonic.channels, 1, index + 1) pylab.plot(time, wave_data[index], colors[index % len(colors)]) pylab.ylabel("quantization") pylab.xlabel("time (seconds)") pylab.ion() if block: pylab.ioff() pylab.show()
def hinton(W, bg='grey', facecolors=('w', 'k')): """Draw a hinton diagram of the matrix W on the current pylab axis Hinton diagrams are a way of visualizing numerical values in a matrix/vector, popular in the neural networks and machine learning literature. The area occupied by a square is proportional to a value's magnitude, and the colour indicates its sign (positive/negative). Example usage: R = np.random.normal(0, 1, (2,1000)) h, ex, ey = np.histogram2d(R[0], R[1], bins=15) hh = h - h.T hinton.hinton(hh) """ M, N = W.shape square_x = np.array([-.5, .5, .5, -.5]) square_y = np.array([-.5, -.5, .5, .5]) ioff = False if plt.isinteractive(): plt.ioff() ioff = True plt.fill([-.5, N - .5, N - .5, - .5], [-.5, -.5, M - .5, M - .5], bg) Wmax = np.abs(W).max() for m, Wrow in enumerate(W): for n, w in enumerate(Wrow): c = plt.signbit(w) and facecolors[1] or facecolors[0] plt.fill(square_x * w / Wmax + n, square_y * w / Wmax + m, c, edgecolor=c) plt.ylim(-0.5, M - 0.5) plt.xlim(-0.5, M - 0.5) if ioff is True: plt.ion() plt.draw_if_interactive()
def plot_checked(self): import pylab as pl pl.ioff() from statistics import expectation exp = [] # The expectation plotter if len(self._stored_t) != 0: pl.figure(2) pl.title(" Method %s"%("OFSP")) pl.xlabel("Time, t") pl.ylabel("Expectation") for i in range(len(self._stored_t)): exp.append(expectation((self._stored_domain_states[i],self._stored_p[i]))) EXP = np.array(exp).T for i in range(EXP.shape[0]): pl.plot(self._stored_t,EXP[i,:],'x-',label=self.model.species[i]) pl.legend() # The probability plotter if len(self._probed_t) != 0: pl.figure(3) pl.title(" Method %s | Probing States over Time "%("OFSP")) pl.xlabel("Time, t") pl.ylabel("Probability") probs = np.array(self._probed_probs).T for i in range(probs.shape[0]): pl.plot(self._probed_t,probs[i,:],'x-',label=str(self._probed_states[0][:,i])) pl.legend() pl.show()
def plot_checked(self): """ plot_checked plots the expectations of the data check pointed. """ import pylab as pl pl.ioff() if len(self._stored_t) != 0: pl.figure(2) pl.title(" Method %s"%(self.model_name)) pl.xlabel("Time,t") pl.ylabel("Expectation") exp = [] for i in range(len(self._stored_t)): exp.append(np.sum(np.multiply(self._stored_X[i],self._stored_w[i]),axis=1)) EXP = np.array(exp).T for i in range(EXP.shape[0]): pl.plot(self._stored_t,EXP[i,:],'x-',label=self.model.species[i]) pl.legend() # The probability plotter if len(self._probed_t) != 0: pl.figure(3) pl.title(" Method %s | Probing States over Time "%(self.model_name)) pl.xlabel("Time, t") pl.ylabel("Marginal Probability") probs = np.array(self._probed_probs).T for i in range(probs.shape[0]): pl.plot(self._probed_t,probs[i,:],'x-',label=str(self._probed_states[0][self.stoc_vector,i])) pl.legend() pl.show()
def rh_e2p_sample_plot(self): # intro checks if not self.attr_check(["y_samples"]): return pl.ioff() # 2a. plot sampling results pl.suptitle("%s step 1 + 2: learning proprio, then learning e2p" % (self.mode,)) ax = pl.subplot(211) pl.title("Exteroceptive state S_e, extero to proprio mapping p2e") self.S_ext = ax.plot(self.logs["S_ext"], "k-", alpha=0.8, label="S_e") p2e = ax.plot(self.logs["P2E_pred"], "r-", alpha=0.8, label="p2e") handles, labels = ax.get_legend_handles_labels() ax.legend(handles=[handles[i] for i in [0, 2]], labels=[labels[i] for i in [0, 2]]) ax2 = pl.subplot(212) pl.title("Proprioceptive state S_p, proprio to extero mapping e2p") ax2.plot(self.logs["M_prop_pred"], "k-", label="S_p") # pl.plot(self.logs["E2P_pred"], "y-", label="E2P knn") ax2.plot(self.y_samples, "g-", label="E2P gmm cond", alpha=0.8, linewidth=2) ax2.plot(self.logs["X__"][:,:3], "r-", label="goal goal") for _ in self.y_samples_: plausibility = _ - self.logs["X__"][:,:3] # print "_.shape = %s, plausibility.shape = %s, %d" % (_.shape, plausibility.shape, 0) # print "_", np.sum(_), _ - self.logs["X__"][:,:3] plausibility_norm = np.linalg.norm(plausibility, 2, axis=1) print "plausibility = %f" % (np.mean(plausibility_norm)) if np.mean(plausibility_norm) < 0.8: # FIXME: what is that for, for thinning out the number of samples? ax2.plot(_, "b.", label="E2P gmm samples", alpha=0.2) handles, labels = ax2.get_legend_handles_labels() print "handles, labels", handles, labels legidx = slice(0, 12, 3) ax2.legend(handles[legidx], labels[legidx]) # ax.legend(handles=[handles[i] for i in [0, 2]], # labels=[labels[i] for i in [0, 2]]) pl.show()
def plot_scattermatrix_reduced(df, title = "plot_scattermatrix_reduced"): input_cols = [i for i in df.columns if i.startswith("X")] output_cols = [i for i in df.columns if i.startswith("Y")] Xs = df[input_cols] Ys = df[output_cols] numsamples = df.shape[0] print "plot_scattermatrix_reduced: numsamples = %d" % numsamples # numplots = Xs.shape[1] * Ys.shape[1] # print "numplots = %d" % numplots gs = gridspec.GridSpec(Ys.shape[1], Xs.shape[1]) pl.ioff() fig = pl.figure() fig.suptitle(title) # alpha = 1.0 / np.power(numsamples, 1.0/(Xs.shape[1] - 0)) alpha = 0.2 print "alpha", alpha cols = ["k", "b", "r", "g", "c", "m", "y"] for i in range(Xs.shape[1]): for j in range(Ys.shape[1]): # print "i, j", i, j, Xs, Ys ax = fig.add_subplot(gs[j, i]) ax.plot(Xs.as_matrix()[:,i], Ys.as_matrix()[:,j], "ko", alpha = alpha) ax.set_xlabel(input_cols[i]) ax.set_ylabel(output_cols[j]) if SAVEPLOTS: fig.savefig("fig_%03d_scattermatrix_reduced.pdf" % (fig.number), dpi=300) fig.show()
def main(args): # seed PRNG np.random.seed(args.seed) pl.ion() if args.mode.startswith("test_"): test_models(args) else: idim = None # if args.mode.startswith("type03_1"): # idim = 3 # print "args.goal_sample_interval", args.goal_sample_interval # initialize experiment inf = ActiveInferenceExperiment( args.mode, args.model, args.numsteps, idim = idim, environment_str = args.environment, goal_sample_interval = args.goal_sample_interval, e2pmodel = args.e2pmodel, saveplots = SAVEPLOTS) # run experiment inf.run() # wait for plots to be closed pl.ioff() pl.show()
def main(): from argparse import ArgumentParser p = ArgumentParser() p.add_argument('--grammar', choices=('both', 'medium', 'big')) p.add_argument('--rollout', choices=('CP', 'DP')) args = p.parse_args() CP = ('evalb_avg', 'pops') DP = ('expected_recall_avg', 'mask') GRAMMARS = ['medium', 'big'] if args.grammar == 'both' else [args.grammar] ACC, RUN = DP if args.rollout == 'DP' else CP pl.ion() fig1, ax1 = pl.subplots(nrows=3, #sharex=True, ncols=2, figsize=(10,10)) for i in range(3): for j in range(2): ax1[i,j].grid(False) fig2, ax2 = pl.subplots(nrows=1, #sharex=True, ncols=2, figsize=(10,5)) for i, GRAMMAR in enumerate(GRAMMARS): plot(GRAMMAR, ACC, RUN, ax=ax1[:,i], col=i) plot2(GRAMMAR, ACC, RUN, ax=ax2[i], col=i) fig1.tight_layout() fig2.tight_layout() pl.ioff() pl.show()
def main(): from argparse import ArgumentParser p = ArgumentParser() p.add_argument('--minlength', type=int, default=5) p.add_argument('--maxlength', type=int, default=30) p.add_argument('--examples', type=int, required=True) p.add_argument('--seed', type=int, default=None) p.add_argument('--profile', action='store_true') p.add_argument('--grammar', choices=('medium','big'), default='medium') p.add_argument('--aggressive', type=float, default=0, help='Pruning rate (zero=no pruning, one=lots of pruning).') args = p.parse_args() if args.profile: profile_run(examples = args.examples, grammar = args.grammar, maxlength = args.maxlength, minlength = args.minlength, aggressive = args.aggressive, seed = args.seed) else: d = run(examples = args.examples, grammar = args.grammar, maxlength = args.maxlength, minlength = args.minlength, aggressive = args.aggressive, seed = args.seed) filename_base = 'tmp/cp-analysis-' + '-'.join('%s_%s' % (k,v) for k,v in sorted(args.__dict__.items())) d.to_csv('%s.csv' % filename_base) p = sns.jointplot('ratio', 'speedup', d, kind='reg') p.savefig('%s.png' % filename_base) print '[info] wrote %s.csv' % filename_base print '== DONE ==' pl.ioff() pl.show()
def make_mutual_info_plot(fn): M.rcParams.update({'font.size': 11}) angleList = N.array([f/f.max() for f in read.extract_arr_from_h5(fn, "/history/angle", n=-1)]) mutualInfoList = read.extract_arr_from_h5(fn, "/history/mutual_info", n=-1) quatList = read.extract_arr_from_h5(fn, "/history/quaternion", n=-1) quatSwitchPos = N.where(quatList[:-1]-quatList[1:] != 0)[0] + 1 angsort = N.argsort(angleList[-1]) misort = N.argsort(mutualInfoList.mean(axis=0)) blkPositions = [0] + list(quatSwitchPos) + [-1] for bp in range(len(blkPositions)-1): (start, end) = (blkPositions[bp], blkPositions[bp+1]) curr_blk = angleList[start:end] curr_blk2 = mutualInfoList[start:end] / N.log(quatSize[quatList[0]]) # curr_blk2 = mutualInfoList[start:end] / N.log(quatSize[quatList[bp]]) if len(curr_blk) == 0: pass else: angsort = N.argsort(curr_blk[-1]) angleList[start:end] = curr_blk[:,angsort] for n,l in enumerate(curr_blk2): misort = N.argsort(l) mutualInfoList[start+n] = l[misort] P.ioff() fig, ax = P.subplots(2, 1, sharex=True, figsize=(7, 10)) fig.subplots_adjust(hspace=0.1) im0 = ax[0].imshow(angleList.transpose(), aspect='auto', interpolation=None, cmap=P.cm.OrRd) ax[0].set_xlabel("iteration") ax[0].set_ylabel("each pattern's most likely orientation\n(sorted by final orientation in each block)") (e_min, e_max) = (1, len(angleList[0])) e_int = 0.1*(e_max-e_min) ax[0].plot([0, 0], [e_min, e_max], 'k-') ax[0].text(1, e_max-e_int, "quat%d"%quatList[0], size=8, rotation=-0, ha='left', va='center', color='w', bbox=dict(boxstyle="larrow,pad=0.1",facecolor='0.1') ) for n,qs in enumerate(quatSwitchPos): ax[0].plot([qs, qs], [e_min, e_max], 'k-') ax[0].text(qs-1, e_max+(-n-1)*e_int, "quat%d"%quatList[qs], size=8, rotation=-0, ha='right', va='center', color='w', bbox=dict(boxstyle="rarrow,pad=0.1",facecolor='0.1') ) div0 = make_axes_locatable(ax[0]) cax0 = div0.append_axes("right", size="5%", pad=0.05) cbar0 = P.colorbar(im0, cax=cax0) ax[0].set_ylim(e_min, e_max) ax[0].set_xlim(0, len(angleList)-1) (e_min, e_max) = (1, len(mutualInfoList[0])) e_int = 0.1*(e_max-e_min) im1 = ax[1].imshow(mutualInfoList.transpose(), vmax=.2, aspect='auto', cmap=P.cm.YlGnBu) ax[1].set_xlabel("iteration") ax[1].set_ylabel("average mutual-information per dataset\n(sorted by average information)") ax[1].plot([0, 0], [e_min, e_max], 'k-') ax[1].text(1, e_max-e_int, "quat%d"%quatList[0], size=8, rotation=-0, ha='left', va='center', color='w', bbox=dict(boxstyle="larrow,pad=0.1",facecolor='0.1') ) for n,qs in enumerate(quatSwitchPos): ax[1].plot([qs, qs], [e_min, e_max], 'k-') ax[1].text(qs-1, e_max+(-n-1)*e_int, "quat%d"%quatList[qs], size=8, rotation=-0, ha='right', va='center', color='w', bbox=dict(boxstyle="rarrow,pad=0.1",facecolor='0.1') ) div1 = make_axes_locatable(ax[1]) cax1 = div1.append_axes("right", size="5%", pad=0.05) cbar1 = P.colorbar(im1, cax=cax1) ax[1].set_ylim(e_min, e_max) ax[1].set_xlim(0, len(mutualInfoList)-1) img_name = "mutual_info_plot.pdf" P.savefig(img_name, bbox_inches='tight') print("Image has been saved as %s" % img_name) P.close(fig)
def check_matplotlib_backends(): # from http://stackoverflow.com/questions/5091993/list-of-all-available-matplotlib-backends # get the directory where the backends live backends_dir = os.path.dirname(matplotlib.backends.__file__) # filter all files in that directory to identify all files which provide a backend backend_fnames = filter(is_backend_module, os.listdir(backends_dir)) backends = [backend_fname_formatter(fname) for fname in backend_fnames] print("supported backends: \t" + str(backends)) # validate backends backends_valid = [] for b in backends: try: plt.switch_backend(b) backends_valid += [b] except: continue print("valid backends: \t" + str(backends_valid)) # try backends performance for b in backends_valid: pylab.ion() try: plt.switch_backend(b) pylab.clf() tstart = time.time() # for profiling x = range(0,2*pylab.pi,0.01) # x-array line, = pylab.plot(x,pylab.sin(x)) for i in range(1,200): line.set_ydata(pylab.sin(x+i/10.0)) # update the data pylab.draw() # redraw the canvas print(b + ' FPS: \t' , 200/(time.time()-tstart)) pylab.ioff() except: print(b + " error :(")
def learning_curve_handler(_args, args, log, jobid): # Note: iterations appear to start at 1. show_each = _args.show_each if show_each: ax1 = ax2 = pl.figure().add_subplot(111) [[ro],[acc],[run]] = [np.unique(args['args_roll_out']), np.unique(args['args_accuracy']), np.unique(args['args_runtime'])] ax1.set_title('jobid: %s. ro/acc/run %s/%s/%s' % (jobid, ro, acc, run)) else: if 0: ax1 = AX['trainlc'] ax2 = AX['devlc'] ax1.set_title('lc train') ax2.set_title('lc dev') else: # group learning curves by regularizer col = 'args_C' ax1 = AX['trainlc-%s' % args.get(col)] ax2 = AX['devlc-%s' % args.get(col)] ax1.set_title('lc train %s' % args.get(col)) ax2.set_title('lc dev %s' % args.get(col)) # Pick x-axis time or iterations. #X = log.iteration X = log['elapsed'] ax1.set_xlabel('days') ax2.set_xlabel('days') if log.get('train_accuracy') is not None: #ax1.plot(log.iteration, log.train_accuracy - log.tradeoff * log.train_runtime, alpha=1, c='b') ax1.plot(X, log.train_new_policy_reward, alpha=1, c='b') maxes = running_max(list(X), list(log.train_new_policy_reward)) ax1.scatter(maxes[:,0], maxes[:,1], lw=0) if log.get('dev_accuracy') is not None: #ax2.plot(X, log.dev_accuracy - log.tradeoff * log.dev_runtime, alpha=1, c='r') #patience(log, ax2) ax2.plot(X, log.dev_new_policy_reward, alpha=1, c='r') maxes = running_max(list(X), list(log.dev_new_policy_reward)) ax2.scatter(maxes[:,0], maxes[:,1], lw=0) if show_each: pl.ioff() pl.show() if _args.kill_mode: if raw_input('kill?').startswith('y'): KILL.append(jobid) print 'KILL', ' '.join(KILL)
def main(): "Command-line interface for running test cases." from argparse import ArgumentParser p = ArgumentParser() p.add_argument('--boolean', action='store_true') p.add_argument('--minlength', type=int, default=5) p.add_argument('--maxlength', type=int, default=30) p.add_argument('--examples', type=int, required=True) p.add_argument('--seed', type=int, default=None) p.add_argument('--grammar', choices=('medium','big'), default='medium') p.add_argument('--aggressive', type=float, default=0.5, help='Pruning rate (zero=no pruning, one=lots of pruning).') args = p.parse_args() np.random.seed(args.seed) s = Setup(train=args.examples, grammar=args.grammar, maxlength=args.maxlength, minlength=args.minlength, features=False) test = _test_correctness_boolean if args.boolean else _test_correctness for i, example in enumerate(s.train): print colors.yellow % '==============================================================' print 'example: %s length: %s' % (i, example.N) test(example, s.grammar, args.aggressive) print colors.green % '==============================================================' print colors.green % 'DONE' print if 0: from arsenal.debug import ip; ip() else: pl.ioff() pl.show()