def plot_weights_network(model, folder_images): # weights = model.linear1.weight.detach().numpy() biases = model.linear1.bias.detach().numpy().reshape(-1, 1) neurons = np.concatenate((weights, biases), axis=1) weights2 = model.W2.detach().numpy() biases2 = model.b2.detach().numpy().reshape(-1, 1) neurons2 = np.concatenate((weights2, biases2), axis=0).T gl.init_figure() ax1 = gl.subplot2grid((1, 4), (0, 0), rowspan=1, colspan=2) ax2 = gl.subplot2grid((1, 4), (0, 3), rowspan=1, colspan=4) cmap = cm.get_cmap('coolwarm', 30) cax = ax1.imshow(neurons, interpolation="nearest", cmap=cmap) cax2 = ax2.imshow(neurons2, interpolation="nearest", cmap=cmap) # plt.xticks(range(data_df_train.shape[1]), data_df_train.columns, rotation='vertical') # plt.yticks(range(data_df_train.shape[1]), data_df_train.columns, rotation='horizontal') plt.colorbar(cax) # plt.colorbar(cax2) # ax1.set_xticks(data_df_train.columns) # , rotation='vertical' # ax1.grid(True) plt.title('Weights ') # labels=[str(x) for x in range(Nshow )] # ax1.set_xticklabels(labels,fontsize=20) # ax1.set_yticklabels(labels,fontsize=20) # Add colorbar, make sure to specify tick locations to match desired ticklabels plt.show() gl.savefig(folder_images + 'Weights.png', dpi=100, sizeInches=[2 * 8, 2 * 2])
def create_image_training_epoch(X_data_tr, Y_data_tr, X_data_val, Y_data_val, tr_loss, val_loss, x_grid, y_grid, cf_a, video_fotograms_folder, epoch_i): """ Creates the image of the training and validation accuracy """ gl.init_figure(); ax1 = gl.subplot2grid((2,1), (0,0), rowspan=1, colspan=1) ax2 = gl.subplot2grid((2,1), (1,0), rowspan=1, colspan=1) plt.title("Training") ## First plot with the data and predictions !!! ax1 = gl.scatter(X_data_tr, Y_data_tr, ax = ax1, lw = 3,legend = ["tr points"], labels = ["Analysis of training", "X","Y"]) gl.scatter(X_data_val, Y_data_val, lw = 3,legend = ["val points"]) gl.plot (x_grid, y_grid, legend = ["Prediction function"]) gl.set_zoom(xlimPad = [0.2, 0.2], ylimPad = [0.2,0.2], X = X_data_tr, Y = Y_data_tr) ## Second plot with the evolution of parameters !!! ax2 = gl.plot([], tr_loss, ax = ax2, lw = 3, labels = ["RMSE. lr: %.3f"%cf_a.lr, "epoch","RMSE"], legend = ["train"]) gl.plot([], val_loss, lw = 3, legend = ["validation"], loc = 3) gl.set_fontSizes(ax = [ax1,ax2], title = 20, xlabel = 20, ylabel = 20, legend = 20, xticks = 12, yticks = 12) # Set final properties and save figure gl.subplots_adjust(left=.09, bottom=.10, right=.90, top=.95, wspace=.30, hspace=0.30) gl.savefig(video_fotograms_folder +'%i.png'%epoch_i, dpi = 100, sizeInches = [14, 10], close = True, bbox_inches = None)
def plot_weights_network(model, folder_images): # weights = model.linear1.weight.detach().numpy() biases = model.linear1.bias.detach().numpy().reshape(-1,1) neurons = np.concatenate((weights, biases), axis = 1) weights2 = model.W2.detach().numpy() biases2 = model.b2.detach().numpy().reshape(-1,1) neurons2 = np.concatenate((weights2, biases2), axis =0).T gl.init_figure(); ax1 = gl.subplot2grid((1,4), (0,0), rowspan=1, colspan=2) ax2 = gl.subplot2grid((1,4), (0,3), rowspan=1, colspan=4) cmap = cm.get_cmap('coolwarm', 30) cax = ax1.imshow(neurons, interpolation="nearest", cmap=cmap) cax2 = ax2.imshow(neurons2, interpolation="nearest", cmap=cmap) # plt.xticks(range(data_df_train.shape[1]), data_df_train.columns, rotation='vertical') # plt.yticks(range(data_df_train.shape[1]), data_df_train.columns, rotation='horizontal') plt.colorbar(cax) # plt.colorbar(cax2) # ax1.set_xticks(data_df_train.columns) # , rotation='vertical' # ax1.grid(True) plt.title('Weights ') # labels=[str(x) for x in range(Nshow )] # ax1.set_xticklabels(labels,fontsize=20) # ax1.set_yticklabels(labels,fontsize=20) # Add colorbar, make sure to specify tick locations to match desired ticklabels plt.show() gl.savefig(folder_images +'Weights.png', dpi = 100, sizeInches = [2*8, 2*2])
def create_image_training_epoch(X_data_tr, Y_data_tr, X_data_val, Y_data_val, tr_loss, val_loss, x_grid, y_grid, cf_a, video_fotograms_folder, epoch_i): """ Creates the image of the training and validation accuracy """ gl.init_figure() ax1 = gl.subplot2grid((2, 1), (0, 0), rowspan=1, colspan=1) ax2 = gl.subplot2grid((2, 1), (1, 0), rowspan=1, colspan=1) plt.title("Training") ## First plot with the data and predictions !!! ax1 = gl.scatter(X_data_tr, Y_data_tr, ax=ax1, lw=3, legend=["tr points"], labels=["Analysis of training", "X", "Y"]) gl.scatter(X_data_val, Y_data_val, lw=3, legend=["val points"]) gl.plot(x_grid, y_grid, legend=["Prediction function"]) gl.set_zoom(xlimPad=[0.2, 0.2], ylimPad=[0.2, 0.2], X=X_data_tr, Y=Y_data_tr) ## Second plot with the evolution of parameters !!! ax2 = gl.plot([], tr_loss, ax=ax2, lw=3, labels=["RMSE. lr: %.3f" % cf_a.lr, "epoch", "RMSE"], legend=["train"]) gl.plot([], val_loss, lw=3, legend=["validation"], loc=3) gl.set_fontSizes(ax=[ax1, ax2], title=20, xlabel=20, ylabel=20, legend=20, xticks=12, yticks=12) # Set final properties and save figure gl.subplots_adjust(left=.09, bottom=.10, right=.90, top=.95, wspace=.30, hspace=0.30) gl.savefig(video_fotograms_folder + '%i.png' % epoch_i, dpi=100, sizeInches=[14, 10], close=True, bbox_inches=None)
Z = R.dot(Y - mu_Y) + mu_Y SigmaZ = R.dot(SigmaY.dot(R.T)) mu_Z = mu_Y ## TODO: AS we can see, the angle is actually positive, but when proejcting that is what you lose. ############################################################ ################# PLOT DATA ############################### ############################################################ if(distribution_graph): # Get the histogram and gaussian estimations ! ## Scatter plot of the points gl.init_figure() ax1 = gl.subplot2grid((4,4), (1,0), rowspan=3, colspan=3) gl.scatter(Y[0,:],Y[1,:], alpha = 0.5, ax = ax1, lw = 4, AxesStyle = "Normal", labels = ["","U1","U2"], legend = ["%i points"%Nsam]) # Plot the projection vectors n = 6; gl.plot([-n*R[0,0],n*R[0,0]],[- n*R[0,1],n*R[0,1]],color = "y", lw = 3); gl.plot([-n*R[1,0],n*R[1,0]],[-n*R[1,1],n*R[1,1]],color = "r", lw = 3); ## Plot the projections !! # V1_pr= [] # V2_pr= [] # # for i in range(Y.shape[1]): # V1_pr.append([Y[:,i],Y[:,i]- R[0,:].dot(Y[:,i]) * R[0,:]])
def generate_images_iterations_ll(Xs,mus,covs, Ks ,myDManager, logl,theta_list,model_theta_list,folder_images_gif): # os.remove(folder_images_gif) # Remove previous images if existing """ WARNING: MEANT FOR ONLY 3 Distributions due to the color RGB """ import shutil ul.create_folder_if_needed(folder_images_gif) shutil.rmtree(folder_images_gif) ul.create_folder_if_needed(folder_images_gif) ######## Plot the original data ##### Xdata = np.concatenate(Xs,axis = 1).T colors = ["r","b","g"] K_G,K_W,K_vMF = Ks ### FOR EACH ITERATION for i in range(len(theta_list)): # theta_list indx = i gl.init_figure() ax1 = gl.subplot2grid((1,2), (0,0), rowspan=1, colspan=1) ## Get the relative ll of the Gaussian denoising cluster. ll = myDManager.pdf_log_K(Xdata,theta_list[indx]) N,K = ll.shape # print ll.shape for j in range(N): # For every sample #TODO: Can this not be done without a for ? # Normalize the probability of the sample being generated by the clusters Marginal_xi_probability = gf.sum_logs(ll[j,:]) ll[j,:] = ll[j,:]- Marginal_xi_probability ax1 = gl.scatter(Xdata[j,0],Xdata[j,1], labels = ['EM Evolution. Kg:'+str(K_G)+ ', Kw:' + str(K_W) + ', K_vMF:' + str(K_vMF), "X1","X2"], color = (np.exp(ll[j,1]), np.exp(ll[j,0]), np.exp(ll[j,2])) , ### np.exp(ll[j,2]) alpha = 1, nf = 0) # Only doable if the clusters dont die for k_c in myDManager.clusterk_to_Dname.keys(): k = myDManager.clusterk_to_thetak[k_c] distribution_name = myDManager.clusterk_to_Dname[k_c] # G W if (distribution_name == "Gaussian"): ## Plot the ecolution of the mu #### Plot the Covariance of the clusters ! mean,w,h,theta = bMA.get_gaussian_ellipse_params( mu = theta_list[indx][k][0], Sigma = theta_list[indx][k][1], Chi2val = 2.4477) r_ellipse = bMA.get_ellipse_points(mean,w,h,theta) gl.plot(r_ellipse[:,0], r_ellipse[:,1], ax = ax1, ls = "-.", lw = 3, AxesStyle = "Normal2", legend = ["Kg(%i). pi:%0.2f"%(k, float(model_theta_list[indx][0][0,k]))]) elif(distribution_name == "Watson"): #### Plot the pdf of the distributino ! ## Distribution parameters for Watson kappa = float(theta_list[indx][k][1]); mu = theta_list[-1][k][0] Nsa = 1000 # Draw 2D samples as transformation of the angle Xalpha = np.linspace(0, 2*np.pi, Nsa) Xgrid= np.array([np.cos(Xalpha), np.sin(Xalpha)]) probs = [] # Vector with probabilities for i in range(Nsa): probs.append(np.exp(Wad.Watson_pdf_log(Xgrid[:,i],[mu,kappa]) )) probs = np.array(probs) # Plot it in polar coordinates X1_w = (1 + probs) * np.cos(Xalpha) X2_w = (1 + probs) * np.sin(Xalpha) gl.plot(X1_w,X2_w, alpha = 1, lw = 3, ls = "-.", legend = ["Kw(%i). pi:%0.2f"%(k, float(model_theta_list[indx][0][0,k]))]) elif(distribution_name == "vonMisesFisher"): #### Plot the pdf of the distributino ! ## Distribution parameters for Watson kappa = float(theta_list[indx][k][1]); mu = theta_list[indx][k][0] Nsa = 1000 # Draw 2D samples as transformation of the angle Xalpha = np.linspace(0, 2*np.pi, Nsa) Xgrid= np.array([np.cos(Xalpha), np.sin(Xalpha)]) probs = [] # Vector with probabilities for i in range(Nsa): probs.append(np.exp(vMFd.vonMisesFisher_pdf_log(Xgrid[:,i],[mu,kappa]) )) probs = np.array(probs) probs = probs.reshape((probs.size,1)).T # Plot it in polar coordinates X1_w = (1 + probs) * np.cos(Xalpha) X2_w = (1 + probs) * np.sin(Xalpha) # print X1_w.shape, X2_w.shape gl.plot(X1_w,X2_w, alpha = 1, lw = 3, ls = "-.", legend = ["Kvmf(%i). pi:%0.2f"%(k, float(model_theta_list[indx][0][0,k]))]) gl.set_zoom(xlim = [-6,6], ylim = [-6,6], ax = ax1) ax2 = gl.subplot2grid((1,2), (0,1), rowspan=1, colspan=1) if (indx == 0): gl.add_text(positionXY = [0.1,.5], text = r' Initilization Incomplete LogLike: %.2f'%(logl[0]),fontsize = 15) pass elif (indx >= 1): gl.plot(range(1,np.array(logl).flatten()[1:].size +1),np.array(logl).flatten()[1:(indx+1)], ax = ax2, legend = ["Iteration %i, Incom LL: %.2f"%(indx, logl[indx])], labels = ["Convergence of LL with generated data","Iterations","LL"], lw = 2) gl.scatter(1, logl[1], lw = 2) pt = 0.05 gl.set_zoom(xlim = [0,len(logl)], ylim = [logl[1] - (logl[-1]-logl[1])*pt,logl[-1] + (logl[-1]-logl[1])*pt], ax = ax2) gl.subplots_adjust(left=.09, bottom=.10, right=.90, top=.95, wspace=.2, hspace=0.01) gl.savefig(folder_images_gif +'gif_'+ str(indx) + '.png', dpi = 100, sizeInches = [16, 8], close = "yes",bbox_inches = None) gl.close("all")
def create_Bayesian_analysis_charts_simplified(model, train_dataset, validation_dataset, tr_loss, val_loss, KL_loss, folder_images, epoch_i = None): # Configurations of the plots alpha_points = 0.2 color_points_train = "dark navy blue" color_points_val = "amber" color_train_loss = "cobalt blue" color_val_loss = "blood" color_truth = "k" color_mean = "b" color_most_likey = "y" ################################ Divide in plots ############################## gl.init_figure(); ax1 = gl.subplot2grid((6,3), (0,0), rowspan=3, colspan=1) ax2 = gl.subplot2grid((6,3), (3,0), rowspan=3, colspan=1, sharex = ax1, sharey = ax1) ax3 = gl.subplot2grid((6,3), (0,1), rowspan=2, colspan=1) ax4 = gl.subplot2grid((6,3), (2,1), rowspan=2, colspan=1, sharex = ax3) ax5 = gl.subplot2grid((6,3), (4,1), rowspan=2, colspan=1, sharex = ax3) ax6 = gl.subplot2grid((6,3), (0,2), rowspan=3, colspan=1) ax7 = gl.subplot2grid((6,3), (3,2), rowspan=3, colspan=1, sharex = ax6) ####### ax1, ax2: Get confusion matrices ########## labels_classes, confusion = model.get_confusion_matrix(train_dataset) plot_confusion_matrix(confusion,labels_classes, ax1 ) labels_classes, confusion = model.get_confusion_matrix(validation_dataset) plot_confusion_matrix(confusion,labels_classes, ax2 ) ############## ax3 ax4 ax5: Loss Evolution !! ###################### ## ax3: Evolutoin of the data loss gl.plot([], tr_loss, ax = ax3, lw = 3, labels = ["Losses", "","Data loss (MSE)"], legend = ["train"], color = color_train_loss) gl.plot([], val_loss,ax = ax3, lw = 3, legend = ["validation"], color = color_val_loss, AxesStyle = "Normal - No xaxis") ## ax4: The evolution of the KL loss gl.plot([], KL_loss, ax = ax4, lw = 3, labels = ["", "","KL loss"], legend = ["Bayesian Weights"], AxesStyle = "Normal - No xaxis", color = "k") ## ax5: Evolutoin of the total loss gl.plot([], tr_loss, ax = ax5, lw = 3, labels = ["", "epoch","Total Loss (Bayes)"], legend = ["train"], color = color_train_loss) gl.plot([], val_loss,ax = ax5, lw = 3, legend = ["validation"], color = color_val_loss) ############## ax6 ax7: Variational Weights !! ###################### create_plot_variational_weights(model,ax6,ax7) gl.set_zoom (ax = ax6, ylim = [-0.1,10]) gl.set_zoom (ax = ax7, xlim = [-2.5, 2.5], ylim = [-0.1,0.5]) # Set final properties and save figure gl.set_fontSizes(ax = [ax1,ax2,ax3,ax4,ax5,ax6,ax7], title = 20, xlabel = 20, ylabel = 20, legend = 10, xticks = 12, yticks = 12) gl.subplots_adjust(left=.09, bottom=.10, right=.90, top=.95, wspace=.30, hspace=0.10) if (type(epoch_i) == type(None)): gl.savefig(folder_images +'Training_Example_Data_Bayesian.png', dpi = 100, sizeInches = [20, 10]) else: gl.savefig(folder_images +'%i.png'%epoch_i, dpi = 100, sizeInches = [20, 10], close = True, bbox_inches = "tight")
def create_image_weights_epoch(model, video_fotograms_folder2, epoch_i): """ Creates the image of the training and validation accuracy """ N_Bayesian_layers = len(model.VBmodels) N_Normal_layers = len(model.LinearModels) # Compute the number of squares we will need: # 1 x linear layers, 2 x LSTMS gl.init_figure() cmap = cm.get_cmap('coolwarm', 30) all_axes = [] for i in range(N_Bayesian_layers): layer = model.VBmodels[i] # if (layer.type_layer == "linear"): if ("linear" in type(layer).__name__.lower()): ax = gl.subplot2grid((1, N_Bayesian_layers + N_Normal_layers), (0, i), rowspan=1, colspan=1) weights = layer.weight.detach().cpu().numpy() biases = layer.bias.detach().cpu().numpy().reshape(-1, 1) neurons = np.concatenate((weights, biases), axis=1) cax = ax.imshow(neurons, interpolation="nearest", cmap=cmap, vmin=-2, vmax=2) all_axes.append(ax) else: ax = gl.subplot2grid((1, N_Bayesian_layers + N_Normal_layers), (0, i), rowspan=1, colspan=1) weights_ih = layer.weight_ih.detach().cpu().numpy() biases_ih = layer.bias_ih.detach().cpu().numpy().reshape(-1, 1) weights_hh = layer.weight_hh.detach().cpu().numpy() biases_hh = layer.bias_hh.detach().cpu().numpy().reshape(-1, 1) weights = np.concatenate((weights_ih, weights_hh), axis=1) biases = np.concatenate((biases_ih, biases_hh), axis=1) neurons = np.concatenate((weights, biases), axis=1) cax = ax.imshow(neurons, interpolation="nearest", cmap=cmap, vmin=-2, vmax=2) all_axes.append(ax) for i in range(N_Normal_layers): layer = model.LinearModels[i] if ("linear" in type(layer).__name__.lower()): ax = gl.subplot2grid((1, N_Bayesian_layers + N_Normal_layers), (0, N_Bayesian_layers + i), rowspan=1, colspan=1) weights = layer.weight.detach().cpu().numpy() biases = layer.bias.detach().cpu().numpy().reshape(-1, 1) neurons = np.concatenate((weights, biases), axis=1) cax = ax.imshow(neurons, interpolation="nearest", cmap=cmap, vmin=-2, vmax=2) all_axes.append(ax) else: ax = gl.subplot2grid((1, N_Bayesian_layers + N_Normal_layers), (0, N_Bayesian_layers + i), rowspan=1, colspan=1) weights_ih = layer.weight_ih.detach().cpu().numpy() biases_ih = layer.bias_ih.detach().cpu().numpy().reshape(-1, 1) weights_hh = layer.weight_hh.detach().cpu().numpy() biases_hh = layer.bias_hh.detach().cpu().numpy().reshape(-1, 1) weights = np.concatenate((weights_ih, weights_hh), axis=1) biases = np.concatenate((biases_ih, biases_hh), axis=1) neurons = np.concatenate((weights, biases), axis=1) cax = ax.imshow(neurons, interpolation="nearest", cmap=cmap, vmin=-2, vmax=2) all_axes.append(ax) # plt.xticks(range(data_df_train.shape[1]), data_df_train.columns, rotation='vertical') # plt.yticks(range(data_df_train.shape[1]), data_df_train.columns, rotation='horizontal') plt.colorbar(cax) # plt.colorbar(cax2) # ax1.set_xticks(data_df_train.columns) # , rotation='vertical' # ax1.grid(True) plt.title('Weights ') # labels=[str(x) for x in range(Nshow )] # ax1.set_xticklabels(labels,fontsize=20) # ax1.set_yticklabels(labels,fontsize=20) # Add colorbar, make sure to specify tick locations to match desired ticklabels plt.show() gl.set_fontSizes(ax=[all_axes], title=20, xlabel=20, ylabel=20, legend=20, xticks=12, yticks=12) # Set final properties and save figure gl.subplots_adjust(left=.09, bottom=.10, right=.90, top=.95, wspace=.30, hspace=0.30) gl.savefig(video_fotograms_folder2 + '%i.png' % epoch_i, dpi=100, sizeInches=[14, 10], close=True, bbox_inches=None)
################### PLOTTING THE DATA ######################### ################################################################ ## Plotting plotting plotting_some = 1 if (plotting_some == 1): Ndiv = 6 HPV = 2 ### PLOT THE ORIGINAL PRICE AND MOVING AVERAGES timeData = Cartera.get_timeDataObj(period=-1, symbol_names=[symbols[indx]])[0] gl.init_figure() ########################## AX0 ######################## ### Plot the initial Price Volume gl.subplot2grid((Ndiv, 4), (0, 0), rowspan=HPV, colspan=4) # gl.plot_indicator(timeData, Ndiv = Ndiv, HPV = HPV) gl.plot(dates, prices[:, indx], legend=["Price"], nf=0, labels=["Xing Average Strategy", "Price", "Time"]) Volume = timeData.get_timeSeries(seriesNames=["Volume"]) gl.plot(dates, Volume, nf=0, na=1, lw=0, alpha=0) gl.fill_between(dates, Volume) axes = gl.get_axes() axP = axes[0] # Price axes axV = axes[1] # Volumne exes
plt.xlim([-1, X.shape[1]]) plt.stem(range(X.shape[1]), pvalues[indices], label="p-value") plt.show() gl.savefig(folder_images + 'Feauture_importance_LM.png', dpi=100, sizeInches=[2 * 8, 2 * 2]) ############## Plot the correlation matrix ####################### if (plot_correlation): Cov_tr = np.corrcoef(data_df_train.T) from matplotlib import cm as cm # gl.init_figure() ax1 = gl.subplot2grid((1, 4), (0, 0), rowspan=1, colspan=4) cmap = cm.get_cmap('jet', 30) cax = ax1.imshow(Cov_tr, interpolation="nearest", cmap=cmap) plt.xticks(range(data_df_train.shape[1]), data_df_train.columns, rotation='vertical') plt.yticks(range(data_df_train.shape[1]), data_df_train.columns, rotation='horizontal') plt.colorbar(cax) # ax1.set_xticks(data_df_train.columns) # , rotation='vertical' # ax1.grid(True) plt.title('Correlation matrix of variables') # labels=[str(x) for x in range(Nshow )] # ax1.set_xticklabels(labels,fontsize=20)
def init_figure(self): """ This function initializes the chart, with its widgets and everything """ button_height = 0.030; textbox_length0 = 0.02 textbox_length1 = 0.04 textbox_length2 = 0.05 fig = gl.init_figure(); ## Set the image to full screen fig_manager = plt.get_current_fig_manager() if hasattr(fig_manager, 'window'): fig_manager.window.showMaximized() data_axes = gl.subplot2grid((1,4), (0,0), rowspan=1, colspan=3) self.fig = fig; self.data_axes = data_axes; #### Logo Images !! logo_path = self.output_folder + "images_IoTubes/IoTubes_logo.png" image = mpimg.imread(logo_path) ax_img = plt.axes([0.725, 0.75, 0.2, 0.2]) ax_img.imshow(image) ax_img.axis("off") ################## Widgets Axes ##################### widgets_x = 0.76 widgets_x2 = 0.85 widgets_x3 = 0.90 w1_x, w2_x, w3_x = 0.73, 0.8,0.87 base_y = 0.69 administration_y = base_y monitoring_y = administration_y - 0.12 chart_s_y = monitoring_y - 0.12 chart_s_y2 = chart_s_y -0.05 chart_start_stop_y = chart_s_y2 - 0.05 output_y = chart_start_stop_y - 0.12 diff_headline_content = 0.052 ## Administration ! headlines_x = 0.705 text = self.fig.text(headlines_x, administration_y + diff_headline_content, 'Administration:', size=20) # ha='center', va='center', size=20) axbox_machineID = plt.axes([widgets_x, administration_y, textbox_length1, button_height]) axbox_pipingID = plt.axes([widgets_x2, administration_y, textbox_length1, button_height]) ### Monitoring text = self.fig.text(headlines_x, monitoring_y + diff_headline_content, 'PH Monitoring:', size=20) # ha='center', va='center', size=20) axbox_desired_value = plt.axes([widgets_x, monitoring_y, textbox_length0, button_height]) axbox_range_warning = plt.axes([widgets_x2, monitoring_y, textbox_length0, button_height]) ## Sampling and plotting text = self.fig.text(headlines_x, output_y + diff_headline_content, 'Output Generation:', size=20) # ha='center', va='center', size=20) axbox_sample_period = plt.axes([widgets_x, chart_s_y, textbox_length1, button_height]) axbox_plot_period = plt.axes([widgets_x2, chart_s_y, textbox_length1, button_height]) axbox_Nsamples_show = plt.axes([widgets_x, chart_s_y2, textbox_length1, button_height]) ax_start = plt.axes([widgets_x,chart_start_stop_y, 0.04, button_height]) ax_stop = plt.axes([widgets_x2, chart_start_stop_y, 0.04, button_height]) ## Output text = self.fig.text(headlines_x, chart_s_y + diff_headline_content, 'Sampling and plotting:', size=20) # ha='center', va='center', size=20) axsave_disk = plt.axes([w1_x, output_y, 0.055, button_height]) axsave_DDBB = plt.axes([w2_x, output_y, 0.055, button_height]) axreport = plt.axes([w3_x, output_y, 0.055, button_height]) ################## Add functionalities ########################### ################ Chart AXES ################: bstop = Button(ax_stop, 'Stop') bstop.on_clicked(self.stop_reading_data) bstart = Button(ax_start, 'Start') bstart.on_clicked(self.start_reading_data) # bprev.on_clicked(self.auto_update_test) #### Text input Period #### initial_text = str(int(self.period_sampling * 1000)); text_box_sample_period = TextBox(axbox_sample_period, 'Sample(ms) ', initial=initial_text) text_box_sample_period.on_submit(self.submit_sample_period) initial_text = str(int(self.period_plotting * 1000)); text_box_plotting_period = TextBox(axbox_plot_period, 'Plot(ms) ', initial=initial_text) text_box_plotting_period.on_submit(self.submit_plotting_period) #### Text input N samples #### initial_text = str(int(self.show_window)); text_Nsamples_show = TextBox(axbox_Nsamples_show, 'Samples Chart ', initial=initial_text) text_Nsamples_show.on_submit(self.submit_show_window) ################ Data generation widgets ################ bpsave_disk = Button(axsave_disk, 'Save Disk') bpsave_disk.on_clicked(self.save_to_disk) bpsave_DDBB = Button(axsave_DDBB, 'Save DDBB') bpsave_DDBB.on_clicked(self.send_buffer_to_DDBB) bpsave_report = Button(axreport, 'Report') bpsave_report.on_clicked(self.generate_report) ################ Cleaning input widgets ################ ## Text input MAchine ID initial_text = self.machine_ID text_box_machine = TextBox(axbox_machineID, 'Machine ID ', initial=initial_text) text_box_machine.on_submit(self.submit_machineID) initial_text = self.piping_ID text_box_piping = TextBox(axbox_pipingID, 'Piping ID ', initial=initial_text) text_box_piping.on_submit(self.submit_pipingID) ################ MONITORING variables ################ initial_text = str(self.Monitor.desired_value); text_desired_value = TextBox(axbox_desired_value, 'Desired PH ', initial=initial_text) text_desired_value.on_submit(self.submit_desired_value) initial_text = str(self.Monitor.range_warning); text_range_warning = TextBox(axbox_range_warning, 'Warning Range ', initial=initial_text) text_range_warning.on_submit(self.submit_range_warning) # I think we needed to keep them in memory of they would die self.buttons = [bstart, bstop, bpsave_disk,bpsave_DDBB,text_box_machine, text_box_sample_period,text_box_plotting_period, text_Nsamples_show, text_desired_value, text_range_warning,bpsave_report, text_box_piping] self.initial_text_data = gl.add_text(positionXY = [0.35,0.5], text = r'Waiting for data',fontsize = 30, ax = data_axes) gl.subplots_adjust(left=.09, bottom=.20, right=.90, top=.90, wspace=.20, hspace=0) self.monitoring_y = monitoring_y
return_lazy_loading_size, return_hidden_size, return_betas, return_initialization_index ] #Standard_values_alyses = [0.001,0.2,40, # 0.2,10000,100, # 0.9, "whatever"] Standard_values_alyses = [0.001, 0.2, 30, 0.2, 10000, 100, 0.9, "whatever"] """ Get the data from the training_logger for the charts for Batch info """ N_analyses = len(List_analyses) for an_i in range(N_analyses): gl.init_figure() ax1 = gl.subplot2grid((1, 2), (0, 0), rowspan=1, colspan=1) ax2 = gl.subplot2grid((1, 2), (0, 1), rowspan=1, colspan=1, sharex=ax1, sharey=ax1) ## Subselect models to plot !!! ## Models with Lazy loading True, 35 epochs Selected_training_logger_list = [] Selected_cf_a_list = [] for i in range(Nmodels): training_logger = training_logger_list[i] cf_a = cf_a_list[i]
MACD, MACDsign, MACDdiff = timeData.MACD() TRIX = timeData.TRIX() gl.set_subplots(3,1) gl.plot(dates, price , nf = 1, labels = ["Averages","Time","Value"], legend = ["Price"]) gl.plot(dates, [MACD, MACDsign, MACDdiff], nf = 1, na = 0, legend = ["MACD"]) gl.plot(dates, TRIX , nf = 1, na = 0, legend = [ "TRIX"]) gl.subplot2grid((6,4), (1,0), rowspan=4, colspan=4, axisbg='#07000d') gl.create_axes(position = [0.3,0.4,0.3,0.4]) # gl.subplot2grid((10,10),) # gl.subplot2grid((6,4), (5,0), ro) gl.plot(dates, TRIX , nf = 0, na = 0,legend = [ "TRIX"]) # gl.plot(dates, ADX , nf = 1, na = 0, # legend = ["ADX"]) # # gl.plot(dates, ACCDIST , nf = 1, na = 0, # legend = ["ACCDIST"]) # trading_indicators_complex = 0
nMA1 = 10 nMA2 = 20 SMAw = indl.get_SMA(bMA.delta(nMA1), nMA1, cval = 1) EMAw = indl.get_EMA(bMA.delta(nMA1), nMA1, cval = 1) WMAw = indl.get_WMA(bMA.delta(nMA1), nMA1, cval = 1) SMAw2 = indl.get_SMA(bMA.delta(nMA2), nMA2, cval = 1) EMAw2 = indl.get_EMA(bMA.delta(nMA2), nMA2, cval = 1) WMAw2 = indl.get_WMA(bMA.delta(nMA2), nMA2, cval = 1) SMA = timeData.SMA(n = nMA1) """ 1st GRAPH """ ############## Average and Window ################ ax1 = gl.subplot2grid((1,5), (0,0), rowspan=1, colspan=3) title = "Price and SMA. " + str(symbols[0]) + "(" + ul.period_dic[timeData.period]+ ")" gl.plot(dates, [price, SMA] ,AxesStyle = "Normal", labels = [title,"",r"Price ($\$$)"], legend = ["Price", "SMA(%i)"%nMA1]) ax2 = gl.subplot2grid((1,5), (0,3), rowspan=1, colspan=2) gl.stem([], SMAw, nf = 0, AxesStyle = "Normal2", labels = ["SMA Window","lag",""], legend = ["SMAw(%i)"%nMA1], xlimPad = [0.1,0.3], ylimPad = [0.1,0.4], marker = [".",10,None]) gl.subplots_adjust(left=.09, bottom=.10, right=.90, top=.95, wspace=.35, hspace=0) gl.savefig(folder_images +'basicSMA.png',
def create_Bayesian_analysis_charts(model, X_data_tr, Y_data_tr, X_data_val, Y_data_val, tr_loss, val_loss, KL_loss,final_loss_tr,final_loss_val, xgrid_real_func, ygrid_real_func, folder_images, epoch_i = None): # Configurations of the plots alpha_points = 0.2 color_points_train = "dark navy blue" color_points_val = "amber" color_train_loss = "cobalt blue" color_val_loss = "blood" color_truth = "k" color_mean = "b" color_most_likey = "y" ############################# Data computation ####################### if(type(X_data_tr) == type([])): pass else: if (X_data_tr.shape[1] == 1): # Regression Example x_grid, all_y_grid,most_likely_ygrid = compute_regression_1D_data( model,X_data_tr,X_data_val, Nsamples = 100) elif(X_data_tr.shape[1] == 2): # Classification Example xx,yy , all_y_grid,most_likely_ygrid = compute_classification_2D_data( model,X_data_tr,X_data_val, Nsamples = 100) else: # RNN x_grid, all_y_grid,most_likely_ygrid = compute_RNN_1D_data( model,X_data_tr,X_data_val, Nsamples = 100) ################################ Divide in plots ############################## gl.init_figure(); ax1 = gl.subplot2grid((6,3), (0,0), rowspan=3, colspan=1) ax2 = gl.subplot2grid((6,3), (3,0), rowspan=3, colspan=1, sharex = ax1, sharey = ax1) ax3 = gl.subplot2grid((6,3), (0,1), rowspan=2, colspan=1) ax4 = gl.subplot2grid((6,3), (2,1), rowspan=2, colspan=1, sharex = ax3) ax5 = gl.subplot2grid((6,3), (4,1), rowspan=2, colspan=1, sharex = ax3) ax6 = gl.subplot2grid((6,3), (0,2), rowspan=3, colspan=1) ax7 = gl.subplot2grid((6,3), (3,2), rowspan=3, colspan=1, sharex = ax6) if(type(X_data_tr) == type([])): Xtrain = [torch.tensor(X_data_tr[i],device=model.cf_a.device, dtype=model.cf_a.dtype) for i in range(len(X_data_tr))] Ytrain = torch.tensor(Y_data_tr,device=model.cf_a.device, dtype=torch.int64) Xval = [torch.tensor(X_data_val[i],device=model.cf_a.device, dtype=model.cf_a.dtype) for i in range(len(X_data_val))] Yval = torch.tensor(Y_data_val,device=model.cf_a.device, dtype=torch.int64) confusion = model.get_confusion_matrix(Xtrain, Ytrain) plot_confusion_matrix(confusion,model.languages, ax1 ) confusion = model.get_confusion_matrix(Xval, Yval) plot_confusion_matrix(confusion,model.languages, ax2 ) else: if (X_data_tr.shape[1] == 1): # Regression Example plot_data_regression_1d_2axes(X_data_tr, Y_data_tr, xgrid_real_func, ygrid_real_func, X_data_val, Y_data_val, x_grid,all_y_grid, most_likely_ygrid, alpha_points, color_points_train, color_points_val, color_most_likey,color_mean,color_truth, ax1,ax2) elif(X_data_tr.shape[1] == 2): # Classification Example plot_data_classification_2d_2axes(X_data_tr, Y_data_tr, xgrid_real_func, ygrid_real_func, X_data_val, Y_data_val, xx,yy,all_y_grid, most_likely_ygrid, alpha_points, color_points_train, color_points_val, color_most_likey,color_mean, color_truth, ax1,ax2) else: # RNN example plot_data_RNN_1d_2axes(X_data_tr, Y_data_tr, xgrid_real_func, ygrid_real_func, X_data_val, Y_data_val, x_grid,all_y_grid, most_likely_ygrid, alpha_points, color_points_train, color_points_val, color_most_likey,color_mean,color_truth, ax1,ax2) # gl.fill_between (x_grid, [mean_samples_grid + 2*std_samples_grid, mean_samples_grid - 2*std_samples_grid] # , ax = ax2, alpha = 0.10, color = "b", legend = ["Mean realizaions"]) ## ax2: The uncertainty of the prediction !! # gl.plot (x_grid, std_samples_grid, ax = ax2, labels = ["Std (%i)"%(Nsamples),"X","f(X)"], legend = [" std predictions"], fill = 1, alpha = 0.3) ############## ax3 ax4 ax5: Loss Evolution !! ###################### ## ax3: Evolutoin of the data loss gl.plot([], tr_loss, ax = ax3, lw = 3, labels = ["Losses", "","Data loss"], legend = ["train"], color = color_train_loss) gl.plot([], val_loss,ax = ax3, lw = 3, legend = ["validation"], color = color_val_loss, AxesStyle = "Normal - No xaxis") ## ax4: The evolution of the KL loss gl.plot([], KL_loss, ax = ax4, lw = 3, labels = ["", "","KL loss"], legend = ["Bayesian Weights"], AxesStyle = "Normal - No xaxis", color = "k") ## ax5: Evolutoin of the total loss gl.plot([], final_loss_tr, ax = ax5, lw = 3, labels = ["", "epoch","Total Loss (Bayes)"], legend = ["train"], color = color_train_loss) gl.plot([], final_loss_val,ax = ax5, lw = 3, legend = ["validation"], color = color_val_loss) ############## ax6 ax7: Variational Weights !! ###################### create_plot_variational_weights(model,ax6,ax7) ## Plot in chart 7 the acceptable mu = 2sigma -> sigma = |mu|/2sigma mu_grid = np.linspace(-3,3,100) y_grid = np.abs(mu_grid)/2 gl.fill_between(mu_grid, 10*np.ones(mu_grid.size), y_grid, alpha = 0.2, color = "r", ax = ax7, legend = ["95% non-significant"]) gl.set_zoom (ax = ax6, ylim = [-0.1,10]) gl.set_zoom (ax = ax7, xlim = [-2.5, 2.5], ylim = [-0.05, np.exp(model.cf_a.input_layer_prior["log_sigma2"])*(1 + 0.15)]) # gl.set_zoom (ax = ax7, xlim = [-2.5, 2.5], ylim = [-0.1,2]) # Set final properties and save figure gl.set_fontSizes(ax = [ax1,ax2,ax3,ax4,ax5,ax6,ax7], title = 20, xlabel = 20, ylabel = 20, legend = 10, xticks = 12, yticks = 12) gl.subplots_adjust(left=.09, bottom=.10, right=.90, top=.95, wspace=.30, hspace=0.10) if (type(epoch_i) == type(None)): gl.savefig(folder_images +"../"+'Final_values_regression_1D_' +str(model.cf_a.eta_KL) +'.png', dpi = 100, sizeInches = [20, 10]) else: gl.savefig(folder_images +'%i.png'%epoch_i, dpi = 100, sizeInches = [20, 10], close = True, bbox_inches = "tight")
ygrid_real_func, folder_images) if (plot_weights): ####### PLOT ANALYSIS OF THE WEIGHTS ########### pf.plot_weights_network(myGeneralVBModel, folder_images) pf.plot_Variational_weights_network(myGeneralVBModel, folder_images) saved_models.append(myGeneralVBModel) if (1): ### USED TO GENERATE THE CHART FOR THE INTRO: gl.init_figure() Nmodels = len(saved_models) all_axes = [] for i in range(Nmodels): gl.colorIndex = 0 model = saved_models[i] ax1 = gl.subplot2grid((2, Nmodels), (0, i), rowspan=1, colspan=1) ax2 = gl.subplot2grid((2, Nmodels), (1, i), rowspan=1, colspan=1) alpha_points = 0.2 color_points_train = "dark navy blue" color_points_val = "amber" color_train_loss = "cobalt blue" color_val_loss = "blood" color_truth = "k" color_mean = "b" color_most_likey = "y" x_grid, all_y_grid, most_likely_ygrid = pf.compute_regression_1D_data( model, X_data_tr, X_data_val, Nsamples=100) pf.plot_data_regression_1d_2axes( X_data_tr, Y_data_tr, xgrid_real_func, ygrid_real_func, X_data_val,
def create_Bayesian_analysis_charts(model, X_data_tr, X_data_val, tr_data_loss, val_data_loss, KL_loss_tr, KL_loss_val, final_loss_tr, final_loss_val, folder_images, epoch_i=None): # Configurations of the plots alpha_points = 0.2 color_points_train = "dark navy blue" color_points_val = "amber" color_truth = "k" color_mean = "b" color_most_likey = "y" ################################ Divide in plots ############################## gl.init_figure() ax1 = gl.subplot2grid((6, 3), (0, 0), rowspan=3, colspan=1) ax2 = gl.subplot2grid((6, 3), (3, 0), rowspan=3, colspan=1, sharex=ax1) ax3 = gl.subplot2grid((6, 3), (0, 1), rowspan=2, colspan=1) ax4 = gl.subplot2grid((6, 3), (2, 1), rowspan=2, colspan=1, sharex=ax3) ax5 = gl.subplot2grid((6, 3), (4, 1), rowspan=2, colspan=1, sharex=ax3) ax6 = gl.subplot2grid((6, 3), (0, 2), rowspan=3, colspan=1) ax7 = gl.subplot2grid((6, 3), (3, 2), rowspan=3, colspan=1, sharex=ax6) """ ############################# Data computation ####################### """ Xtrain_sample_cpu, Xtrain_reconstruction,Xtrain_reconstruction_samples = \ compute_reconstruction_data( model,X_data_tr, Nsamples = 100, sample_index = 2) plot_reconstruction_data(Xtrain_sample_cpu, Xtrain_reconstruction, Xtrain_reconstruction_samples, ax1, ax2) """ ############## ax3 ax4 ax5: Loss Evolution !! ###################### """ plot_losses_evolution_epoch(tr_data_loss, val_data_loss, KL_loss_tr, KL_loss_val, final_loss_tr, final_loss_val, ax3, ax4, ax5) """ ############## ax6 ax7: Projecitons Weights !! ###################### """ plot_projections_VAE(model, X_data_tr, ax6) ## Plot in chart 7 the acceptable mu = 2sigma -> sigma = |mu|/2sigma # gl.set_zoom (ax = ax6, ylim = [-0.1,10]) # gl.set_zoom (ax = ax7, xlim = [-2.5, 2.5], ylim = [-0.05, np.exp(model.cf_a.input_layer_prior["log_sigma2"])*(1 + 0.15)]) # gl.set_zoom (ax = ax7, xlim = [-2.5, 2.5], ylim = [-0.1,2]) # Set final properties and save figure gl.set_fontSizes(ax=[ax1, ax2, ax3, ax4, ax5, ax6, ax7], title=20, xlabel=20, ylabel=20, legend=10, xticks=12, yticks=12) gl.subplots_adjust(left=.09, bottom=.10, right=.90, top=.95, wspace=.30, hspace=0.10) if (type(epoch_i) == type(None)): gl.savefig(folder_images + "../" + 'Final_values_regression_1D_' + str(model.cf_a.eta_KL) + '.png', dpi=100, sizeInches=[20, 10]) else: gl.savefig(folder_images + '%i.png' % epoch_i, dpi=100, sizeInches=[20, 10], close=True, bbox_inches="tight")
def generate_images_iterations_ll(Xs, mus, covs, Ks, myDManager, logl, theta_list, model_theta_list, folder_images_gif): # os.remove(folder_images_gif) # Remove previous images if existing """ WARNING: MEANT FOR ONLY 3 Distributions due to the color RGB """ import shutil ul.create_folder_if_needed(folder_images_gif) shutil.rmtree(folder_images_gif) ul.create_folder_if_needed(folder_images_gif) ######## Plot the original data ##### Xdata = np.concatenate(Xs, axis=1).T colors = ["r", "b", "g"] K_G, K_W, K_vMF = Ks ### FOR EACH ITERATION for i in range(len(theta_list)): # theta_list indx = i gl.init_figure() ax1 = gl.subplot2grid((1, 2), (0, 0), rowspan=1, colspan=1) ## Get the relative ll of the Gaussian denoising cluster. ll = myDManager.pdf_log_K(Xdata, theta_list[indx]) N, K = ll.shape # print ll.shape for j in range(N): # For every sample #TODO: Can this not be done without a for ? # Normalize the probability of the sample being generated by the clusters Marginal_xi_probability = gf.sum_logs(ll[j, :]) ll[j, :] = ll[j, :] - Marginal_xi_probability ax1 = gl.scatter( Xdata[j, 0], Xdata[j, 1], labels=[ 'EM Evolution. Kg:' + str(K_G) + ', Kw:' + str(K_W) + ', K_vMF:' + str(K_vMF), "X1", "X2" ], color=(np.exp(ll[j, 1]), np.exp(ll[j, 0]), np.exp(ll[j, 2])), ### np.exp(ll[j,2]) alpha=1, nf=0) # Only doable if the clusters dont die for k_c in myDManager.clusterk_to_Dname.keys(): k = myDManager.clusterk_to_thetak[k_c] distribution_name = myDManager.clusterk_to_Dname[k_c] # G W if (distribution_name == "Gaussian"): ## Plot the ecolution of the mu #### Plot the Covariance of the clusters ! mean, w, h, theta = bMA.get_gaussian_ellipse_params( mu=theta_list[indx][k][0], Sigma=theta_list[indx][k][1], Chi2val=2.4477) r_ellipse = bMA.get_ellipse_points(mean, w, h, theta) gl.plot(r_ellipse[:, 0], r_ellipse[:, 1], ax=ax1, ls="-.", lw=3, AxesStyle="Normal2", legend=[ "Kg(%i). pi:%0.2f" % (k, float(model_theta_list[indx][0][0, k])) ]) elif (distribution_name == "Watson"): #### Plot the pdf of the distributino ! ## Distribution parameters for Watson kappa = float(theta_list[indx][k][1]) mu = theta_list[-1][k][0] Nsa = 1000 # Draw 2D samples as transformation of the angle Xalpha = np.linspace(0, 2 * np.pi, Nsa) Xgrid = np.array([np.cos(Xalpha), np.sin(Xalpha)]) probs = [] # Vector with probabilities for i in range(Nsa): probs.append( np.exp(Wad.Watson_pdf_log(Xgrid[:, i], [mu, kappa]))) probs = np.array(probs) # Plot it in polar coordinates X1_w = (1 + probs) * np.cos(Xalpha) X2_w = (1 + probs) * np.sin(Xalpha) gl.plot(X1_w, X2_w, alpha=1, lw=3, ls="-.", legend=[ "Kw(%i). pi:%0.2f" % (k, float(model_theta_list[indx][0][0, k])) ]) elif (distribution_name == "vonMisesFisher"): #### Plot the pdf of the distributino ! ## Distribution parameters for Watson kappa = float(theta_list[indx][k][1]) mu = theta_list[indx][k][0] Nsa = 1000 # Draw 2D samples as transformation of the angle Xalpha = np.linspace(0, 2 * np.pi, Nsa) Xgrid = np.array([np.cos(Xalpha), np.sin(Xalpha)]) probs = [] # Vector with probabilities for i in range(Nsa): probs.append( np.exp( vMFd.vonMisesFisher_pdf_log( Xgrid[:, i], [mu, kappa]))) probs = np.array(probs) probs = probs.reshape((probs.size, 1)).T # Plot it in polar coordinates X1_w = (1 + probs) * np.cos(Xalpha) X2_w = (1 + probs) * np.sin(Xalpha) # print X1_w.shape, X2_w.shape gl.plot(X1_w, X2_w, alpha=1, lw=3, ls="-.", legend=[ "Kvmf(%i). pi:%0.2f" % (k, float(model_theta_list[indx][0][0, k])) ]) gl.set_zoom(xlim=[-6, 6], ylim=[-6, 6], ax=ax1) ax2 = gl.subplot2grid((1, 2), (0, 1), rowspan=1, colspan=1) if (indx == 0): gl.add_text(positionXY=[0.1, .5], text=r' Initilization Incomplete LogLike: %.2f' % (logl[0]), fontsize=15) pass elif (indx >= 1): gl.plot( range(1, np.array(logl).flatten()[1:].size + 1), np.array(logl).flatten()[1:(indx + 1)], ax=ax2, legend=["Iteration %i, Incom LL: %.2f" % (indx, logl[indx])], labels=[ "Convergence of LL with generated data", "Iterations", "LL" ], lw=2) gl.scatter(1, logl[1], lw=2) pt = 0.05 gl.set_zoom(xlim=[0, len(logl)], ylim=[ logl[1] - (logl[-1] - logl[1]) * pt, logl[-1] + (logl[-1] - logl[1]) * pt ], ax=ax2) gl.subplots_adjust(left=.09, bottom=.10, right=.90, top=.95, wspace=.2, hspace=0.01) gl.savefig(folder_images_gif + 'gif_' + str(indx) + '.png', dpi=100, sizeInches=[16, 8], close="yes", bbox_inches=None) gl.close("all")
MACD, MACDsign, MACDdiff = timeData.MACD() TRIX = timeData.TRIX() gl.set_subplots(3,1) gl.plot(dates, price , nf = 1, labels = ["Averages","Time","Value"], legend = ["Price"]) gl.plot(dates, [MACD, MACDsign, MACDdiff], nf = 1, na = 0, legend = ["MACD"]) gl.plot(dates, TRIX , nf = 1, na = 0, legend = [ "TRIX"]) gl.subplot2grid((6,4), (1,0), rowspan=4, colspan=4, axisbg='#07000d') gl.create_axes(position = [0.3,0.4,0.3,0.4]) # gl.subplot2grid((10,10),) # gl.subplot2grid((6,4), (5,0), ro) gl.plot(dates, TRIX , nf = 0, na = 0,legend = [ "TRIX"]) # gl.plot(dates, ADX , nf = 1, na = 0, # legend = ["ADX"]) # # gl.plot(dates, ACCDIST , nf = 1, na = 0, # legend = ["ACCDIST"]) # ########################################################################### ############## Moving Averages ############################################
color = gl.get_color() gl.scatter(t_val_abs, t.pdf(t_val_abs, N-1) , color = color, legend = ["T: %.2f, p-v: %.3f"%(t_val,p_val)]) gl.plot(x_grid, t_pdf, color = color, fill = 1, alpha = 0.2) gl.set_zoom(ax = ax1, X = x_grid_all,xlimPad = [0.1,0.1]) gl.savefig(folder_images +'t-StatSig.png', dpi = 100, sizeInches = [14,6]) ##### Plot the both sided one !!! gl.init_figure() ax0 = gl.subplot2grid((1,2), (0,0), rowspan=1, colspan=1) t_pdf = t.pdf(x_grid_all, df) gl.plot(x_grid_all, t_pdf, alpha = 1, lw = 3, AxesStyle = "Normal", legend = ["df %i"%df],color = color, labels = ["right-tail event","t","pdf(t)"]) ## Plot the right sided for i in days: ## Day 1 D = ret1[i*26:(i+1)*26] N,mu_hat,S = D.size,np.mean(D),np.std(D) t_val = (mu_hat - mu_0)/(S/np.sqrt(N)) x_grid = np.linspace(t_val,4,100) t_pdf = t.pdf(x_grid, N-1) p_val = 1 - t.cdf(t_val, N-1)
gl.plot(dates, priceA, ax=axP, nf=0, na=0, legend=["Average price"]) # Formating the legend maLeg = axP.legend(loc=9, ncol=2, prop={'size': 7}, fancybox=True, borderaxespad=0.) maLeg.get_frame().set_alpha(0.4) textEd = axP.get_legend().get_texts() pylab.setp(textEd[0:5], color='w') ## Plot other indicators pos = 0 gl.subplot2grid((Ndiv, 4), (HPV + pos, 0), rowspan=1, colspan=4, sharex=axP, axisbg='#07000d') gl.plotMACD(timeData, ax=None) ## Plot other indicators pos = pos + 1 gl.subplot2grid((Ndiv, 4), (HPV + pos, 0), rowspan=1, colspan=4, sharex=axP) MOM = timeData.MOM(n=1) ROC = timeData.ROC(n=2) gl.plot(dates, MOM, nf=0, na=0, legend=["Momentum"]) gl.plot(dates, ROC, nf=0, na=1, legend=["ROC"])
dates2 = Cartera.get_timeData(symbolIDs[symbol_ID_indx2],periods[0]).get_dates() symbolIDs = cmplist.iloc[0:30]["Symbol"].tolist() symbol_ID1 = symbolIDs[symbol_ID_indx1] symbol_ID2 = symbolIDs[symbol_ID_indx2] #print dates[0], dates[26], dates[27] ################# Plotting the data ################# if(trading_graph): # Trading plot of the points ! title = "CLOSE Price, Volume and Return evolution" ax1 = gl.subplot2grid((4,1), (0,0), rowspan=1, colspan=1) gl.tradingBarChart(Cartera.get_timeData(symbolIDs[symbol_ID_indx1],periods[0]), ax = ax1, dataTransform = dataTransform, AxesStyle = "Normal - No xaxis", color = "k", labels = [title,"",symbolIDs[symbol_ID_indx1] +"(" +str(periods[0])+"M)"]) ax2 = gl.subplot2grid((4,1), (1,0), rowspan=1, colspan=1, sharex = ax1) gl.tradingBarChart(Cartera.get_timeData(symbolIDs[symbol_ID_indx2],periods[0]), ax = ax2, dataTransform = dataTransform, AxesStyle = "Normal - No xaxis", color = "k", labels = ["","",symbolIDs[symbol_ID_indx2] +"(" +str(periods[0])+"M)"]) ax3 = gl.subplot2grid((4,1), (2,0), rowspan=1, colspan=1) gl.stem(dates, ret1, ax = ax3, dataTransform = dataTransform, AxesStyle = "Normal", labels = ["","",symbolIDs[symbol_ID_indx1] +"("+ str(periods[0])+ "M)"], legend = ["Return"]) ax4 = gl.subplot2grid((4,1), (3,0), rowspan=1, colspan=1, sharex = ax1, sharey = ax3)
def create_Bayesian_analysis_charts(model, X_data_tr, Y_data_tr, X_data_val, Y_data_val, tr_loss, val_loss, KL_loss, final_loss_tr, final_loss_val, xgrid_real_func, ygrid_real_func, folder_images, epoch_i=None): # Configurations of the plots alpha_points = 0.2 color_points_train = "dark navy blue" color_points_val = "amber" color_train_loss = "cobalt blue" color_val_loss = "blood" color_truth = "k" color_mean = "b" color_most_likey = "y" ############################# Data computation ####################### if (type(X_data_tr) == type([])): pass else: if (X_data_tr.shape[1] == 1): # Regression Example x_grid, all_y_grid, most_likely_ygrid = compute_regression_1D_data( model, X_data_tr, X_data_val, Nsamples=100) elif (X_data_tr.shape[1] == 2): # Classification Example xx, yy, all_y_grid, most_likely_ygrid = compute_classification_2D_data( model, X_data_tr, X_data_val, Nsamples=100) else: # RNN x_grid, all_y_grid, most_likely_ygrid = compute_RNN_1D_data( model, X_data_tr, X_data_val, Nsamples=100) ################################ Divide in plots ############################## gl.init_figure() ax1 = gl.subplot2grid((6, 3), (0, 0), rowspan=3, colspan=1) ax2 = gl.subplot2grid((6, 3), (3, 0), rowspan=3, colspan=1, sharex=ax1, sharey=ax1) ax3 = gl.subplot2grid((6, 3), (0, 1), rowspan=2, colspan=1) ax4 = gl.subplot2grid((6, 3), (2, 1), rowspan=2, colspan=1, sharex=ax3) ax5 = gl.subplot2grid((6, 3), (4, 1), rowspan=2, colspan=1, sharex=ax3) ax6 = gl.subplot2grid((6, 3), (0, 2), rowspan=3, colspan=1) ax7 = gl.subplot2grid((6, 3), (3, 2), rowspan=3, colspan=1, sharex=ax6) if (type(X_data_tr) == type([])): Xtrain = [ torch.tensor(X_data_tr[i], device=model.cf_a.device, dtype=model.cf_a.dtype) for i in range(len(X_data_tr)) ] Ytrain = torch.tensor(Y_data_tr, device=model.cf_a.device, dtype=torch.int64) Xval = [ torch.tensor(X_data_val[i], device=model.cf_a.device, dtype=model.cf_a.dtype) for i in range(len(X_data_val)) ] Yval = torch.tensor(Y_data_val, device=model.cf_a.device, dtype=torch.int64) confusion = model.get_confusion_matrix(Xtrain, Ytrain) plot_confusion_matrix(confusion, model.languages, ax1) confusion = model.get_confusion_matrix(Xval, Yval) plot_confusion_matrix(confusion, model.languages, ax2) else: if (X_data_tr.shape[1] == 1): # Regression Example plot_data_regression_1d_2axes( X_data_tr, Y_data_tr, xgrid_real_func, ygrid_real_func, X_data_val, Y_data_val, x_grid, all_y_grid, most_likely_ygrid, alpha_points, color_points_train, color_points_val, color_most_likey, color_mean, color_truth, ax1, ax2) elif (X_data_tr.shape[1] == 2): # Classification Example plot_data_classification_2d_2axes( X_data_tr, Y_data_tr, xgrid_real_func, ygrid_real_func, X_data_val, Y_data_val, xx, yy, all_y_grid, most_likely_ygrid, alpha_points, color_points_train, color_points_val, color_most_likey, color_mean, color_truth, ax1, ax2) else: # RNN example plot_data_RNN_1d_2axes(X_data_tr, Y_data_tr, xgrid_real_func, ygrid_real_func, X_data_val, Y_data_val, x_grid, all_y_grid, most_likely_ygrid, alpha_points, color_points_train, color_points_val, color_most_likey, color_mean, color_truth, ax1, ax2) # gl.fill_between (x_grid, [mean_samples_grid + 2*std_samples_grid, mean_samples_grid - 2*std_samples_grid] # , ax = ax2, alpha = 0.10, color = "b", legend = ["Mean realizaions"]) ## ax2: The uncertainty of the prediction !! # gl.plot (x_grid, std_samples_grid, ax = ax2, labels = ["Std (%i)"%(Nsamples),"X","f(X)"], legend = [" std predictions"], fill = 1, alpha = 0.3) ############## ax3 ax4 ax5: Loss Evolution !! ###################### ## ax3: Evolutoin of the data loss gl.plot([], tr_loss, ax=ax3, lw=3, labels=["Losses", "", "Data loss"], legend=["train"], color=color_train_loss) gl.plot([], val_loss, ax=ax3, lw=3, legend=["validation"], color=color_val_loss, AxesStyle="Normal - No xaxis") ## ax4: The evolution of the KL loss gl.plot([], KL_loss, ax=ax4, lw=3, labels=["", "", "KL loss"], legend=["Bayesian Weights"], AxesStyle="Normal - No xaxis", color="k") ## ax5: Evolutoin of the total loss gl.plot([], final_loss_tr, ax=ax5, lw=3, labels=["", "epoch", "Total Loss (Bayes)"], legend=["train"], color=color_train_loss) gl.plot([], final_loss_val, ax=ax5, lw=3, legend=["validation"], color=color_val_loss) ############## ax6 ax7: Variational Weights !! ###################### create_plot_variational_weights(model, ax6, ax7) ## Plot in chart 7 the acceptable mu = 2sigma -> sigma = |mu|/2sigma mu_grid = np.linspace(-3, 3, 100) y_grid = np.abs(mu_grid) / 2 gl.fill_between(mu_grid, 10 * np.ones(mu_grid.size), y_grid, alpha=0.2, color="r", ax=ax7, legend=["95% non-significant"]) gl.set_zoom(ax=ax6, ylim=[-0.1, 10]) gl.set_zoom(ax=ax7, xlim=[-2.5, 2.5], ylim=[ -0.05, np.exp(model.cf_a.input_layer_prior["log_sigma2"]) * (1 + 0.15) ]) # gl.set_zoom (ax = ax7, xlim = [-2.5, 2.5], ylim = [-0.1,2]) # Set final properties and save figure gl.set_fontSizes(ax=[ax1, ax2, ax3, ax4, ax5, ax6, ax7], title=20, xlabel=20, ylabel=20, legend=10, xticks=12, yticks=12) gl.subplots_adjust(left=.09, bottom=.10, right=.90, top=.95, wspace=.30, hspace=0.10) if (type(epoch_i) == type(None)): gl.savefig(folder_images + "../" + 'Final_values_regression_1D_' + str(model.cf_a.eta_KL) + '.png', dpi=100, sizeInches=[20, 10]) else: gl.savefig(folder_images + '%i.png' % epoch_i, dpi=100, sizeInches=[20, 10], close=True, bbox_inches="tight")
dpi = 100, sizeInches = [14, 7]) if (plot_projections_2Assets): X2D = X[:,[AAPL_id, GOOGL_id]] componentsPCA = MSlib.get_components_PCA(X2D, n_components = 2) Xproj = MSlib.get_projected_PCA(X2D, n_components = 2) gl.init_figure() X_1,X_2 = X2D[:,[0]], X2D[:,[1]] mu_1, mu_2 = np.mean(Xproj, axis =0) std_1,std_2 = np.std(Xproj,axis =0) cov = np.cov(np.concatenate((X_1,X_2),axis = 1).T).T std_K = 3 ## Do stuff now ax0 = gl.subplot2grid((1,2), (0,0), rowspan=1, colspan=1) gl.scatter(X_1,X_2, alpha = 0.5, ax = ax0, lw = 4, AxesStyle = "Normal", labels = ["Original 2D data","X1: %s" %(symbolIDs[AAPL_id]), "X2: %s" %(symbolIDs[GOOGL_id])]) ax0.axis('equal') ################# Draw the error ellipse ################# mean,w,h,theta = bMA.get_gaussian_ellipse_params(X2D, Chi2val = 2.4477) corr = bMA.get_corrMatrix(X2D) cov = bMA.get_covMatrix(X2D) vecs,vals = bMA.get_eigenVectorsAndValues(X2D) r_ellipse = bMA.get_ellipse_points(mean,w,h,theta) gl.plot(r_ellipse[:,0], r_ellipse[:,1], ax = ax0, ls = "--",color = "k", lw = 2, legend = ["Corr: %.2f"%(corr[0,1])]) gl.plot([mean[0], mean[0] + vecs[0,0]*w],
if (fill_data_f): Cartera.get_timeData(symbolIDs[symbol_ID_indx1],periods[0]).fill_data() ########## Obtain the data ############### price = Cartera.get_timeData(symbolIDs[symbol_ID_indx1],periods[0]).get_timeSeries(["Close"]) volume = Cartera.get_timeData(symbolIDs[symbol_ID_indx1],periods[0]).get_timeSeries(["Volume"]) ret1 = Cartera.get_timeData(symbolIDs[symbol_ID_indx1],periods[0]).get_timeSeriesReturn(["Close"])*100 dates = Cartera.get_timeData(symbolIDs[symbol_ID_indx1],periods[0]).get_dates() #print dates[0], dates[26], dates[27] ################# Plotting the data ################# if(trading_graph): # Trading plot of the points ! title = "CLOSE Price, Volume and Return evolution" ax1 = gl.subplot2grid((5,1), (0,0), rowspan=2, colspan=1) gl.tradingBarChart(Cartera.get_timeData(symbolIDs[symbol_ID_indx1],periods[0]), ax = ax1, dataTransform = dataTransform, AxesStyle = "Normal - No xaxis", labels = [title,"",symbolIDs[symbol_ID_indx1] +"(" +str(periods[0])+")"]) ax2 = gl.subplot2grid((5,1), (2,0), rowspan=1, colspan=1, sharex = ax1) gl.stem(dates, volume, ax = ax2, dataTransform = dataTransform, AxesStyle = "Normal - No xaxis - Ny:4", labels = ["","",symbolIDs[0] +"("+ str(periods[0])+ "M)"], legend = [ "Volume"]) ax3 = gl.subplot2grid((5,1), (3,0), rowspan=2, colspan=1, sharex = ax1) gl.stem(dates, ret1, ax = ax3, dataTransform = dataTransform, AxesStyle = "Normal", labels = ["","",symbolIDs[0] +"("+ str(periods[0])+ "M)"], legend = ["Return"]) # gl.set_fontSizes(ax = [ax1,ax2,ax3], title = 20, xlabel = 20, ylabel = 20,
################################################################ ################### PLOTTING THE DATA ######################### ################################################################ ## Plotting plotting plotting_some = 1 if (plotting_some == 1): Ndiv = 6; HPV = 2 ### PLOT THE ORIGINAL PRICE AND MOVING AVERAGES timeData = Cartera.get_timeDataObj(period = -1, symbol_names = [symbols[indx]])[0] gl.init_figure() ########################## AX0 ######################## ### Plot the initial Price Volume gl.subplot2grid((Ndiv,4), (0,0), rowspan=HPV, colspan=4) # gl.plot_indicator(timeData, Ndiv = Ndiv, HPV = HPV) gl.plot(dates, prices[:,indx], legend = ["Price"], nf = 0, labels = ["Xing Average Strategy","Price","Time"]) Volume = timeData.get_timeSeries(seriesNames = ["Volume"]) gl.plot(dates, Volume, nf = 0, na = 1, lw = 0, alpha = 0) gl.fill_between(dates, Volume) axes = gl.get_axes() axP = axes[0] # Price axes axV = axes[1] # Volumne exes axV.set_ylim(0,3 * max(Volume)) gl.plot(dates, EMAfast[:,indx],ax = axP, legend = ["EMA = %i" %(n_fast)], nf = 0) gl.plot(dates, EMAslow[:,indx],ax = axP, legend = ["EMA = %i" %(n_slow)], nf = 0)
plot_charts = 1 if (plot_charts): if (True): Nrows = 2 Ncols = 3 list_all_axes = [] gl.init_figure() list_all_weights = [] list_all_labels = [] if (cf_a.VB_Linear_projection_ELMO): # gl.colorIndex = 0 VBmodel = model._linear_projection_ELMO ax1 = gl.subplot2grid((Nrows, Ncols), (0, 0), rowspan=1, colspan=1) plot_VB_weights_mu_std_2D(VBmodel, ax1, "LinearVB", "Linear proyection ELMo $W_{E}$") list_all_axes.append(ax1) list_all_labels.append("$W_{E}$") list_all_weights.append(get_LinearVB_weights(VBmodel)) if (cf_a.VB_highway_layers): # gl.colorIndex = 0 VBmodel = model._highway_layer._module.VBmodels[0] ax1 = gl.subplot2grid((Nrows, Ncols), (0, 1), rowspan=1, colspan=1) plot_VB_weights_mu_std_2D(VBmodel, ax1, "HighwayVB", "Highway matrix weights $W_{H}$") list_all_axes.append(ax1)
gl.set_subplots(Npeople, 1) ax1 = None legend = [] labels_title = "Cluster responsibility for the EM" Ndiv = 4 for i in range(Npeople_plot): if (myEM.clusters_relation == "independent"): resp = r[N * i:N * (i + 1), :] elif (myEM.clusters_relation == "MarkovChain1"): resp = r[i] Nclusters = resp.shape[1] ax_ii = gl.subplot2grid((Npeople_plot, Ndiv), (i, 0), rowspan=1, colspan=Ndiv - 1) ax1 = gl.plot_filled(time, resp, nf=0, fill_mode="stacked", legend=legend, sharex=ax1, sharey=ax1, AxesStyle="Normal - No yaxis", labels=[labels_title, "", "%i" % i]) gl.colorIndex = 0 labels_title = "" ax_i = gl.subplot2grid((Npeople_plot, Ndiv), (0, Ndiv - 1),
## Plot the covariance matrix ! # Show the Nshow first samples Nshow = 20 ## Plot realizations of the Gaussian process Nrealizations = 10 flag = 1 legend = ["Realizations"] labels = ["Gaussian Process noise e(t)", "t", "e(t)"] # Plot the realizations gl.init_figure() ax0 = gl.subplot2grid((1, 4), (0, 0), rowspan=1, colspan=3) for i in range(Nrealizations): f_prime = np.random.randn(N, 1) error = L.dot(f_prime) gl.plot(tgrid, error, lw=3, color="b", ls="-", alpha=0.5, legend=legend, labels=labels) # gl.scatter(tgrid,f_prime, lw = 1, alpha = 0.3, color = "b") if (flag == 1): flag = 0
plt.xticks(range(X.shape[1]), names, rotation='vertical') plt.xlim([-1, X.shape[1]]) plt.stem(range(X.shape[1]), pvalues[indices], label = "p-value") plt.show() gl.savefig(folder_images +'Feauture_importance_LM.png', dpi = 100, sizeInches = [2*8, 2*2]) ############## Plot the correlation matrix ####################### if (plot_correlation): Cov_tr = np.corrcoef(data_df_train.T) from matplotlib import cm as cm # gl.init_figure(); ax1 = gl.subplot2grid((1,4), (0,0), rowspan=1, colspan=4) cmap = cm.get_cmap('jet', 30) cax = ax1.imshow(Cov_tr, interpolation="nearest", cmap=cmap) plt.xticks(range(data_df_train.shape[1]), data_df_train.columns, rotation='vertical') plt.yticks(range(data_df_train.shape[1]), data_df_train.columns, rotation='horizontal') plt.colorbar(cax) # ax1.set_xticks(data_df_train.columns) # , rotation='vertical' # ax1.grid(True) plt.title('Correlation matrix of variables') # labels=[str(x) for x in range(Nshow )] # ax1.set_xticklabels(labels,fontsize=20) # ax1.set_yticklabels(labels,fontsize=20) # Add colorbar, make sure to specify tick locations to match desired ticklabels plt.show() gl.savefig(folder_images +'Corr.png',
List_f_analyses = [ return_layers_dropout, return_hidden_size, return_etaKL, return_sigma2, return_initialization_index ] Standard_values_alyses = [0.0, 100, 0.01, 0.5, "whatever"] images_prefix += "eta_KL_" + str(Standard_values_alyses[2]) + "_DRr_" + str( Standard_values_alyses[0]) + "_sigma_" + str(Standard_values_alyses[3]) """ Get the data from the training_logger for the charts for Batch info """ N_analyses = len(List_analyses) for an_i in range(N_analyses): gl.init_figure() ax1 = gl.subplot2grid((1, 2), (0, 0), rowspan=1, colspan=1) ax2 = gl.subplot2grid((1, 2), (0, 1), rowspan=1, colspan=1, sharex=ax1, sharey=ax1) ## Subselect models to plot !!! ## Models with Lazy loading True, 35 epochs Selected_training_logger_list = [] Selected_cf_a_list = [] for i in range(Nmodels): training_logger = training_logger_list[i] cf_a = cf_a_list[i]
Cartera.set_interval(sdate, edate) Cartera.set_seriesNames(["Close"]) ####################################################### ############# DANSKE BANK Stuff ################### ###################################################### timeDataObjs = Cartera.get_timeDataObj(period1) Nsym = len(timeDataObjs) gl.init_figure() #ax1.xaxis_date() i = 0 for tdo in timeDataObjs: gl.subplot2grid((Nsym, 4), (i, 0), rowspan=1, colspan=4) gl.tradingPV(tdo, color_mode=1, fontsize=15) i = i + 1 ax = gl.get_axes()[-1] all_axes = gl.get_axes() for i in range(len(all_axes) - 2): ax = all_axes[i] plt.setp(ax.get_xticklabels(), visible=False) #plt.setp(ax.get_xticklabels(), visible=True) plt.suptitle("Danske Bank", color='k', fontsize=20) plt.subplots_adjust(left=.09, bottom=.10, right=.90, top=.95,
f = 2 * x_2 + x_1 * x_2 - 4 * x_1 - 4 * x_2 * x_2 - x_1 * x_1 + 5 print("---- Results after Iteration %i ------" % (i)) print("m1 = %.4f, m2 = %.4f" % (m_1, m_2)) print("x1 = %.4f, x2 = %.4f" % (x_1, x_2)) print("t = %.4f" % (t)) print("f(x): %.4f" % (f)) f_values.append(f) t_values.append(t) x1_values.append(x_1) x2_values.append(x_2) m1_values.append(m_1) m2_values.append(m_2) gl.init_figure() ax1 = gl.subplot2grid((1, 4), (0, 0), rowspan=1, colspan=1) ax2 = gl.subplot2grid((1, 4), (0, 1), rowspan=1, colspan=1, sharex=ax1) ax3 = gl.subplot2grid((1, 4), (0, 2), rowspan=1, colspan=1, sharex=ax1) ax4 = gl.subplot2grid((1, 4), (0, 3), rowspan=1, colspan=1, sharex=ax1) ax1 = gl.plot([], f_values, ax=ax1, lw=3, labels=["Objective function", "iterations", "f(X)"], legend=["f(x)"], AxesStyle="Normal ", color="k") ax2 = gl.plot([], t_values,
# Bollinger Bands and ATR nBB = 10; nBB1 = 20; nBB2 = 10 BB1 = timeData.BBANDS(seriesNames = ["Close"], n = nBB1) SMA1 = timeData.SMA(n = nBB1) BB2 = timeData.BBANDS(seriesNames = ["Close"], n = nBB2) SMA2 = timeData.SMA(n = nBB2) EMA1 = timeData.EMA(n = nBB1) BBE1 = timeData.BBANDS(seriesNames = ["Close"], MA = SMA1, n = nBB1) color1 = "k" colorBB1 = "cobalt blue" colorBB2 = "irish green" ## Plotting t the BB !! ax1 = gl.subplot2grid((5,1), (0,0), rowspan=4, colspan=1) # gl.plot(dates, price, ax = ax1, AxesStyle = "Normal - No xaxis", # labels = ["Volatility indicator BB", "", "Price"], # legend = ["Price"], color = "dark navy blue") title = "Bollinger Bands. " + str(symbols[0]) + "(" + ul.period_dic[timeData.period]+ ")" gl.barchart(dates, dataHLOC, ax = ax1, color = color1, labels = [title, "", r"Price ($\$$)"], legend = ["HLOC Price"]) BBs = np.concatenate([BB1[:,[0]],BB1[:,[1]]],axis = 1) gl.plot(dates, SMA1, color = colorBB1, legend = ["0.95 BB(%i)"%nBB1]) gl.plot(dates, BBs, color = colorBB1, ls = "--") gl.plot_filled(dates, BBs, color = colorBB1, alpha = 0.1, AxesStyle = "Normal - No xaxis",)
if(distribution_graph_2D): # Get the histogram and gaussian estimations ! ## Scatter plot of the points # gl.init_figure() i_1 = 2 i_2 = 0 X_1,X_2 = X[:,[i_1]], X[:,[i_2]] mu_1, mu_2 = mus[i_1],mus[i_2] std_1, std_2 = stds[i_1],stds[i_2] mu = mus[[i_1,i_2]] cov = np.cov(np.concatenate((X_1,X_2),axis = 1).T).T std_K = 3 ## Do stuff now ax1 = gl.subplot2grid((4,4), (1,0), rowspan=3, colspan=3) gl.scatter(X_1,X_2, alpha = 0.5, ax = ax1, lw = 4, AxesStyle = "Normal", labels = ["","X1", "X2"]) ## X distribution ax2 = gl.subplot2grid((4,4), (0,0), rowspan=1, colspan=3, sharex = ax1) x_grid, y_val = bMA.gaussian1D_points(mean = mu_1, std = std_1, std_K = std_K) gl.plot(x_grid, y_val, color = "k", labels = ["","",""], legend = ["M: %.1f, std: %.1f"%(mu_1, std_1)], AxesStyle = "Normal - No xaxis") # Y distribution ax3 = gl.subplot2grid((4,4), (1,3), rowspan=3, colspan=1,sharey = ax1,) x_grid, y_val = bMA.gaussian1D_points(mean = mu_2, std = std_2, std_K = std_K)
return_betas,return_initialization_index] #Standard_values_alyses = [0.001,0.2,40, # 0.2,10000,100, # 0.9, "whatever"] Standard_values_alyses = [0.001,0.2,30, 0.2,10000,100, 0.9, "whatever"] """ Get the data from the training_logger for the charts for Batch info """ N_analyses = len(List_analyses) for an_i in range(N_analyses): gl.init_figure(); ax1 = gl.subplot2grid((1,2), (0,0), rowspan=1, colspan=1) ax2 = gl.subplot2grid((1,2), (0,1), rowspan=1, colspan=1, sharex = ax1, sharey = ax1) ## Subselect models to plot !!! ## Models with Lazy loading True, 35 epochs Selected_training_logger_list = [] Selected_cf_a_list = [] for i in range (Nmodels): training_logger = training_logger_list[i] cf_a = cf_a_list[i] condition_analysis = True # Substract one because the last one is the iterations one. for an_j in range(N_analyses -1): if(an_j != an_i):
nBB1 = 20 nBB2 = 10 BB1 = timeData.BBANDS(seriesNames=["Close"], n=nBB1) SMA1 = timeData.SMA(n=nBB1) BB2 = timeData.BBANDS(seriesNames=["Close"], n=nBB2) SMA2 = timeData.SMA(n=nBB2) EMA1 = timeData.EMA(n=nBB1) BBE1 = timeData.BBANDS(seriesNames=["Close"], MA=SMA1, n=nBB1) color1 = "k" colorBB1 = "cobalt blue" colorBB2 = "irish green" ## Plotting t the BB !! ax1 = gl.subplot2grid((5, 1), (0, 0), rowspan=4, colspan=1) # gl.plot(dates, price, ax = ax1, AxesStyle = "Normal - No xaxis", # labels = ["Volatility indicator BB", "", "Price"], # legend = ["Price"], color = "dark navy blue") title = "Bollinger Bands. " + str( symbols[0]) + "(" + ul5.period_dic[timeData.period] + ")" ##### The problem is that we are using dataTrasnform so the X axis is not being transformed into integers ##### but fed directly, we need to still make such a transformation for this to work? gl.barchart(dates, dataHLOC, ax=ax1, color=color1, labels=[title, "", r"Price ($\$$)"], legend=["HLOC Price"])
MACD, MACDsign, MACDdiff = timeData.MACD() TRIX = timeData.TRIX() gl.set_subplots(3, 1) gl.plot(dates, price, nf=1, labels=["Averages", "Time", "Value"], legend=["Price"]) gl.plot(dates, [MACD, MACDsign, MACDdiff], nf=1, na=0, legend=["MACD"]) gl.plot(dates, TRIX, nf=1, na=0, legend=["TRIX"]) gl.subplot2grid((6, 4), (1, 0), rowspan=4, colspan=4, axisbg='#07000d') gl.create_axes(position=[0.3, 0.4, 0.3, 0.4]) # gl.subplot2grid((10,10),) # gl.subplot2grid((6,4), (5,0), ro) gl.plot(dates, TRIX, nf=0, na=0, legend=["TRIX"]) # gl.plot(dates, ADX , nf = 1, na = 0, # legend = ["ADX"]) # # gl.plot(dates, ACCDIST , nf = 1, na = 0, # legend = ["ACCDIST"]) # ########################################################################### ############## Moving Averages ############################################ ###########################################################################
## Scatter plot of the points # gl.init_figure() i_1 = 2 i_2 = 0 X_1,X_2 = X[:,[i_1]], X[:,[i_2]] mu_1, mu_2 = mus[i_1],mus[i_2] Xjoint = np.concatenate((X_1,X_2), axis = 1).T std_1, std_2 = stds[i_1],stds[i_2] mu = mus[[i_1,i_2]] cov = np.cov(Xjoint) std_K = 3 ## Do stuff now ax1 = gl.subplot2grid((1,2), (0,0), rowspan=1, colspan=1) gl.scatter(Xjoint[0,:],Xjoint[1,:], alpha = 0.5, ax = ax1, lw = 4, AxesStyle = "Normal", labels = ["","U1", "U2"]) ax1.axis('equal') xx, yy, zz = bMA.get_gaussian2D_pdf( xbins=40j, ybins=40j, mu = mu, cov = cov, std_K = std_K, x_grid = None) ax1.contour(xx, yy, zz, linewidths = 3, linestyles = "solid", alpha = 0.8, colors = None, zorder = 100) ######## Transformation !! A = np.array([[0.9,2],[0.8,0.7]]) mu = np.array([-1.5,2]).reshape(2,1) Yjoint = A.dot(Xjoint) + mu
## Plot the function Q_values = range (10000,100000,30) T_values = [] S_values = [] q_max = [] negative = [] for Q in Q_values: S = Q*((b*p + h*d)/((p+h)*b)) T = K*d/Q + c*d + p*b*(Q-S)*(Q-S)/(2*Q*(b-d)) + h*(b*S - d*Q)*(b*S - d*Q)/(2*b*Q*(b-d)) T_values.append(T) q_max.append(S - Q*d/b) negative.append(Q-S) gl.init_figure(); ax1 = gl.subplot2grid((1,3), (0,0), rowspan=1, colspan=1) ax2 = gl.subplot2grid((1,3), (0,1), rowspan=1, colspan=1, sharex = ax1) ax3 = gl.subplot2grid((1,3), (0,2), rowspan=1, colspan=1, sharex = ax1) ax1 = gl.plot(Q_values, T_values, ax = ax1, lw = 3, labels = ["Total Anual Cost", "Q","T(Q)"], legend = ["T(Q)"], AxesStyle = "Normal ", color = "k") ax2 = gl.plot(Q_values, q_max, ax = ax2, lw = 3, labels = ["Maximum inventory", "Q","qmax(Q)"], legend = ["qmax(Q)"], AxesStyle = "Normal ", color = "k") ax3 = gl.plot(Q_values, negative, ax = ax3, lw = 3, labels = ["Maximum Shortage", "Q","(Q-S)(Q)"], legend = ["(Q-S)(Q)"], AxesStyle = "Normal ", color = "k")
nMA1 = 10 nMA2 = 20 SMAw = indl.get_SMA(bMA.delta(nMA1), nMA1, cval=1) EMAw = indl.get_EMA(bMA.delta(nMA1), nMA1, cval=1) WMAw = indl.get_WMA(bMA.delta(nMA1), nMA1, cval=1) SMAw2 = indl.get_SMA(bMA.delta(nMA2), nMA2, cval=1) EMAw2 = indl.get_EMA(bMA.delta(nMA2), nMA2, cval=1) WMAw2 = indl.get_WMA(bMA.delta(nMA2), nMA2, cval=1) SMA = timeData.SMA(n=nMA1) """ 1st GRAPH """ ############## Average and Window ################ ax1 = gl.subplot2grid((1, 5), (0, 0), rowspan=1, colspan=3) title = "Price and SMA. " + str( symbols[0]) + "(" + ul5.period_dic[timeData.period] + ")" gl.plot(dates, [price, SMA], AxesStyle="Normal", labels=[title, "", r"Price ($\$$)"], legend=["Price", "SMA(%i)" % nMA1]) ax2 = gl.subplot2grid((1, 5), (0, 3), rowspan=1, colspan=2) gl.stem([], SMAw, nf=0, AxesStyle="Normal2", labels=["SMA Window", "lag", ""], legend=["SMAw(%i)" % nMA1],
###### SET THE READING ######## ser = serial.Serial('/dev/ttyUSB0', 9600) ser.readline() for i in range(10): print (float(ser.readline().decode("utf-8").split("\n")[0])) #ser.close() ###### GENERATE FAKE DATA ############ data = np.random.randn(100,1) + 35 time = range(data.size) ###### GENERATE THE FIGURE ############ fig = gl.init_figure(); data_axes = gl.subplot2grid((1,4), (0,0), rowspan=1, colspan=3) data = [] time = [] update_data.index = 0 print ("starting...") ## Define the class with all the info class information(): ## Serial port info serial = ser # Serial port we get the info from rt = None ## Data information time = time
## Plot the covariance matrix ! # Show the Nshow first samples Nshow = 20 ## Plot realizations of the Gaussian process Nrealizations = 10 flag = 1; legend = ["Realizations"] labels = ["Gaussian Process noise e(t)","t", "e(t)"] # Plot the realizations gl.init_figure(); ax0 = gl.subplot2grid((1,4), (0,0), rowspan=1, colspan=3) for i in range(Nrealizations): f_prime = np.random.randn(N,1) error = L.dot(f_prime) gl.plot(tgrid,error, lw = 3, color = "b", ls = "-", alpha = 0.5, legend = legend, labels = labels) # gl.scatter(tgrid,f_prime, lw = 1, alpha = 0.3, color = "b") if (flag == 1): flag = 0 legend = [] #Variance of each prediction v = np.diagonal(K) gl.fill_between(tgrid, -2*np.sqrt(v), 2*np.sqrt(v), lw = 3, alpha = 0.5, color = "yellow",
periods[0]).get_dates() symbolIDs = cmplist.iloc[0:30]["Symbol"].tolist() symbol_ID1 = symbolIDs[symbol_ID_indx1] symbol_ID2 = symbolIDs[symbol_ID_indx2] #print dates[0], dates[26], dates[27] ################# Plotting the data ################# if (trading_graph): # Trading plot of the points ! title = "CLOSE Price, Volume and Return evolution" ax1 = gl.subplot2grid((4, 1), (0, 0), rowspan=1, colspan=1) gl.tradingBarChart(Cartera.get_timeData(symbolIDs[symbol_ID_indx1], periods[0]), ax=ax1, dataTransform=dataTransform, AxesStyle="Normal - No xaxis", color="k", labels=[ title, "", symbolIDs[symbol_ID_indx1] + "(" + str(periods[0]) + "M)" ]) ax2 = gl.subplot2grid((4, 1), (1, 0), rowspan=1, colspan=1, sharex=ax1) gl.tradingBarChart( Cartera.get_timeData(symbolIDs[symbol_ID_indx2], periods[0]), ax=ax2,
plot_charts = 1 if (plot_charts): if (True): Nrows = 2 Ncols = 3 list_all_axes = [] gl.init_figure() list_all_weights = [] list_all_labels = [] if (cf_a.VB_Linear_projection_ELMO): # gl.colorIndex = 0 VBmodel = model._linear_projection_ELMO ax1 = gl.subplot2grid((Nrows,Ncols), (0,0), rowspan=1, colspan=1) plot_VB_weights_mu_std_2D(VBmodel,ax1,"LinearVB", "Linear proyection ELMo $W_{E}$") list_all_axes.append(ax1) list_all_labels.append("$W_{E}$") list_all_weights.append(get_LinearVB_weights(VBmodel)) if (cf_a.VB_highway_layers): # gl.colorIndex = 0 VBmodel = model._highway_layer._module.VBmodels[0] ax1 = gl.subplot2grid((Nrows,Ncols), (0,1), rowspan=1, colspan=1) plot_VB_weights_mu_std_2D(VBmodel,ax1,"HighwayVB", "Highway matrix weights $W_{H}$") list_all_axes.append(ax1) list_all_labels.append("$W_{H}$") list_all_weights.append(get_LinearVB_weights(VBmodel))
# %% """ ########################################################## ############### PLOTTING ################################# ########################################################## """ if (plotting_daily): # Get the daily values of the remaining days timeData_daily = tut.get_daily_timedata(timeData, symbols[0]) ## Get the daily HLOC H,L,O,C,V = np.array(timeData_daily.TD[["High","Low","Open","Close","Volume"]][:]).T gl.init_figure() ax1 = gl.subplot2grid((4,1), (0,0), rowspan=3, colspan=1) title = "Bar Chart. " + str(symbols[0]) + "(" + ul.period_dic[1440]+ ")" gl.tradingBarChart(timeData_daily, ax = ax1, legend = ["Close price"], color = "k", labels = [title,"",r"Rate"], AxesStyle = "Normal - No xaxis") ax2 = gl.subplot2grid((4,1), (3,0), rowspan=1, colspan=1, sharex = ax1) gl.tradingVolume(timeData_daily, ax = ax2,legend = ["Volume"], AxesStyle = "Normal", labels = ["","","Volume"], color = "#53868B") gl.set_fontSizes(ax = [ax1,ax2], title = 20, xlabel = 20, ylabel = 20, legend = 10, xticks = 10, yticks = 10) image_name = "daily_data" gl.savefig(folder_images + image_name, dpi = 100, sizeInches = [20, 7])
def create_Bayesian_analysis_charts_simplified(model, train_dataset, validation_dataset, tr_loss, val_loss, KL_loss, folder_images, epoch_i=None): # Configurations of the plots alpha_points = 0.2 color_points_train = "dark navy blue" color_points_val = "amber" color_train_loss = "cobalt blue" color_val_loss = "blood" color_truth = "k" color_mean = "b" color_most_likey = "y" ################################ Divide in plots ############################## gl.init_figure() ax1 = gl.subplot2grid((6, 3), (0, 0), rowspan=3, colspan=1) ax2 = gl.subplot2grid((6, 3), (3, 0), rowspan=3, colspan=1, sharex=ax1, sharey=ax1) ax3 = gl.subplot2grid((6, 3), (0, 1), rowspan=2, colspan=1) ax4 = gl.subplot2grid((6, 3), (2, 1), rowspan=2, colspan=1, sharex=ax3) ax5 = gl.subplot2grid((6, 3), (4, 1), rowspan=2, colspan=1, sharex=ax3) ax6 = gl.subplot2grid((6, 3), (0, 2), rowspan=3, colspan=1) ax7 = gl.subplot2grid((6, 3), (3, 2), rowspan=3, colspan=1, sharex=ax6) ####### ax1, ax2: Get confusion matrices ########## labels_classes, confusion = model.get_confusion_matrix(train_dataset) plot_confusion_matrix(confusion, labels_classes, ax1) labels_classes, confusion = model.get_confusion_matrix(validation_dataset) plot_confusion_matrix(confusion, labels_classes, ax2) ############## ax3 ax4 ax5: Loss Evolution !! ###################### ## ax3: Evolutoin of the data loss gl.plot([], tr_loss, ax=ax3, lw=3, labels=["Losses", "", "Data loss (MSE)"], legend=["train"], color=color_train_loss) gl.plot([], val_loss, ax=ax3, lw=3, legend=["validation"], color=color_val_loss, AxesStyle="Normal - No xaxis") ## ax4: The evolution of the KL loss gl.plot([], KL_loss, ax=ax4, lw=3, labels=["", "", "KL loss"], legend=["Bayesian Weights"], AxesStyle="Normal - No xaxis", color="k") ## ax5: Evolutoin of the total loss gl.plot([], tr_loss, ax=ax5, lw=3, labels=["", "epoch", "Total Loss (Bayes)"], legend=["train"], color=color_train_loss) gl.plot([], val_loss, ax=ax5, lw=3, legend=["validation"], color=color_val_loss) ############## ax6 ax7: Variational Weights !! ###################### create_plot_variational_weights(model, ax6, ax7) gl.set_zoom(ax=ax6, ylim=[-0.1, 10]) gl.set_zoom(ax=ax7, xlim=[-2.5, 2.5], ylim=[-0.1, 0.5]) # Set final properties and save figure gl.set_fontSizes(ax=[ax1, ax2, ax3, ax4, ax5, ax6, ax7], title=20, xlabel=20, ylabel=20, legend=10, xticks=12, yticks=12) gl.subplots_adjust(left=.09, bottom=.10, right=.90, top=.95, wspace=.30, hspace=0.10) if (type(epoch_i) == type(None)): gl.savefig(folder_images + 'Training_Example_Data_Bayesian.png', dpi=100, sizeInches=[20, 10]) else: gl.savefig(folder_images + '%i.png' % epoch_i, dpi=100, sizeInches=[20, 10], close=True, bbox_inches="tight")
dataCSV['Recent dividend payed (per share)'][comp], edate,lastDivs[i], m_periods[i], inflation = inflation) # Check the currency if (dataCSV['Dividend currency'][comp] == "USD"): dividends = dividends * USDDKK # print "%s changed currency" % comp # Apply the TAXes dividends = dividends * (1-TAX) total_div += dividends all_divs.append(total_div) gl.subplot2grid((4,4), (0,0), rowspan=4, colspan=4) gl.plot(range_months,all_divs, legend = ["Inflation 0%"], labels = ["Dividends","Months", "DKK"], nf = 0, fill =1, alpha = 0.5) gl.set_xlim(range_months[0],range_months[-1]) if (1): #TAX = 0.25 inflation = 0.02 all_divs = [] dataCSV.loc['HP Inc' , 'Amount (No.)'] += 1300 dataCSV.loc['Exxon Mobil Corp' ,'Amount (No.)'] -= 1000
model, device, dataset_iterable, num_batches, Evaluate_Model_Results, bayesian_ensemble=bayesian_ensemble) DataSet_statistics_list.append(DataSet_statistics) DataSet_statistics = DataSet_statistics_list[0] EM_list = [] F1_list = [] for i in range(len(DataSet_statistics_list)): EM_list.append(100 * np.mean(DataSet_statistics_list[i]["em"])) F1_list.append(100 * np.mean(DataSet_statistics_list[i]["f1"])) gl.init_figure() ax1 = gl.subplot2grid((3, 1), (0, 0), rowspan=1, colspan=1) ax2 = gl.subplot2grid((3, 1), (1, 0), rowspan=1, colspan=1, sharex=ax1) ax3 = gl.subplot2grid((3, 1), (2, 0), rowspan=1, colspan=1, sharex=ax1) ## Accuracies !! gl.plot(trim_mu_sigma, EM_list, ax=ax1, legend=["EM"], labels=[ "Trimming of the weights and biases by $|\mu_w|/\sigma_w$", "", "Accuracy" ]) gl.plot(trim_mu_sigma, F1_list, ax=ax1, legend=["F1"]) ## Systems !
###### SET THE READING ######## if (0): ser = serial.Serial('/dev/ttyUSB0', 9600) ser.readline() for i in range(10): print(float(ser.readline().decode("utf-8").split("\n")[0])) #ser.close() ###### GENERATE FAKE DATA ############ data = np.random.randn(100, 1) + 35 time = range(data.size) ###### GENERATE THE FIGURE ############ fig = gl.init_figure() data_axes = gl.subplot2grid((1, 4), (0, 0), rowspan=1, colspan=3) data = [] time = [] update_data.index = 0 print("starting...") ## Define the class with all the info class information(): ## Serial port info serial = ser # Serial port we get the info from rt = None ## Data information
test_cross_entropy = Ytest * np.log(Ypredict_test_proba) + ( 1 - Ytest) * np.log(1 - Ypredict_test_proba) train_cross_entropy = Ytrain * np.log(Ypredict_train_proba) + ( 1 - Ytrain) * np.log(1 - Ypredict_train_proba) test_cross_entropy = -test_cross_entropy train_cross_entropy = -train_cross_entropy ############################################################## alpha_stem = 0.5 marker_stem = [".", 1, None] train_color = "b" test_color = "r" gl.init_figure() ax1 = gl.subplot2grid((4, 1), (0, 0), rowspan=1, colspan=1) ax2 = gl.subplot2grid((4, 1), (1, 0), rowspan=1, colspan=1, sharex=ax1) ax3 = gl.subplot2grid((4, 1), (2, 0), rowspan=1, colspan=1, sharex=ax1) ax4 = gl.subplot2grid((4, 1), (3, 0), rowspan=1, colspan=1, sharex=ax1) ## Ax1 = Close price at the end of the sessions gl.plot(days_keys, C, ax=ax1, labels=["Results " + key_classifier, "", "Close Rate"], AxesStyle="Normal - No xaxis", legend=["Close Rate"]) ## Ax2 = 1 if the stock has gone up, zero if it has gone down gl.stem(dates_train, Ytrain_reg,
def create_image_weights_epoch(model, video_fotograms_folder2, epoch_i): """ Creates the image of the training and validation accuracy """ N_Bayesian_layers = len(model.VBmodels) N_Normal_layers = len(model.LinearModels) # Compute the number of squares we will need: # 1 x linear layers, 2 x LSTMS gl.init_figure(); cmap = cm.get_cmap('coolwarm', 30) all_axes = [] for i in range(N_Bayesian_layers): layer = model.VBmodels[i] # if (layer.type_layer == "linear"): if ("linear" in type(layer).__name__.lower()): ax = gl.subplot2grid((1,N_Bayesian_layers + N_Normal_layers), (0,i), rowspan=1, colspan=1) weights = layer.weight.detach().cpu().numpy() biases = layer.bias.detach().cpu().numpy().reshape(-1,1) neurons = np.concatenate((weights, biases), axis = 1) cax = ax.imshow(neurons, interpolation="nearest", cmap=cmap, vmin=-2, vmax=2) all_axes.append(ax) else: ax = gl.subplot2grid((1,N_Bayesian_layers + N_Normal_layers), (0,i), rowspan=1, colspan=1) weights_ih = layer.weight_ih.detach().cpu().numpy() biases_ih = layer.bias_ih.detach().cpu().numpy().reshape(-1,1) weights_hh = layer.weight_hh.detach().cpu().numpy() biases_hh = layer.bias_hh.detach().cpu().numpy().reshape(-1,1) weights = np.concatenate((weights_ih,weights_hh),axis = 1) biases = np.concatenate((biases_ih,biases_hh),axis = 1) neurons = np.concatenate((weights, biases), axis = 1) cax = ax.imshow(neurons, interpolation="nearest", cmap=cmap, vmin=-2, vmax=2) all_axes.append(ax) for i in range(N_Normal_layers): layer = model.LinearModels[i] if ("linear" in type(layer).__name__.lower()): ax = gl.subplot2grid((1,N_Bayesian_layers + N_Normal_layers), (0,N_Bayesian_layers +i), rowspan=1, colspan=1) weights = layer.weight.detach().cpu().numpy() biases = layer.bias.detach().cpu().numpy().reshape(-1,1) neurons = np.concatenate((weights, biases), axis = 1) cax = ax.imshow(neurons, interpolation="nearest", cmap=cmap, vmin=-2, vmax=2) all_axes.append(ax) else: ax = gl.subplot2grid((1,N_Bayesian_layers + N_Normal_layers), (0,N_Bayesian_layers +i), rowspan=1, colspan=1) weights_ih = layer.weight_ih.detach().cpu().numpy() biases_ih = layer.bias_ih.detach().cpu().numpy().reshape(-1,1) weights_hh = layer.weight_hh.detach().cpu().numpy() biases_hh = layer.bias_hh.detach().cpu().numpy().reshape(-1,1) weights = np.concatenate((weights_ih,weights_hh),axis = 1) biases = np.concatenate((biases_ih,biases_hh),axis = 1) neurons = np.concatenate((weights, biases), axis = 1) cax = ax.imshow(neurons, interpolation="nearest", cmap=cmap, vmin=-2, vmax=2) all_axes.append(ax) # plt.xticks(range(data_df_train.shape[1]), data_df_train.columns, rotation='vertical') # plt.yticks(range(data_df_train.shape[1]), data_df_train.columns, rotation='horizontal') plt.colorbar(cax) # plt.colorbar(cax2) # ax1.set_xticks(data_df_train.columns) # , rotation='vertical' # ax1.grid(True) plt.title('Weights ') # labels=[str(x) for x in range(Nshow )] # ax1.set_xticklabels(labels,fontsize=20) # ax1.set_yticklabels(labels,fontsize=20) # Add colorbar, make sure to specify tick locations to match desired ticklabels plt.show() gl.set_fontSizes(ax = [all_axes], title = 20, xlabel = 20, ylabel = 20, legend = 20, xticks = 12, yticks = 12) # Set final properties and save figure gl.subplots_adjust(left=.09, bottom=.10, right=.90, top=.95, wspace=.30, hspace=0.30) gl.savefig(video_fotograms_folder2 +'%i.png'%epoch_i, dpi = 100, sizeInches = [14, 10], close = True, bbox_inches = None)