def plot_model(self, partition=0, show_plot=True, save_fig_folder=None): # plotting the data points fig = pl.figure(partition) ax = fig.add_subplot(111, projection='3d') # for each partition for i in range(len(self.partition)): state = Expert2.get_sa(self.partition[i]) prediction = Expert2.get_s2(self.partition[i]) x_actual = [] y_actual = [] z_actual = [] for x in state: x_actual.append(x[0]) y_actual.append(x[1]) for z in prediction: z_actual.append(z[0]) x_actual = tuple(x_actual) y_actual = tuple(y_actual) z_actual = tuple(z_actual) if i == partition: colour = 'r' else: colour = 'k' ax.scatter(x_actual, y_actual, z_actual, color=colour) # plotting the model x = y = np.arange(0, 10, 0.05) X, Y = np.meshgrid(x, y) try: zs = np.array([self.model[partition].predict(tuple([x,y])) for x,y in zip(np.ravel(X), np.ravel(Y))]) Z = zs.reshape(X.shape) ax.plot_surface(X, Y, Z, color='c', linewidth=0, antialiased=True) except AttributeError: print("Expert #" + str(partition) + " does not have a valid model.") ax.set_xlabel('State 0') ax.set_ylabel('Action 0') ax.set_zlabel('Predicted State 1') pl.title('Support Vector Regression Model (Partition #' + str(partition) + ")") if save_fig_folder is not None: save_figure.save(save_fig_folder+"/Support Vector Regression Model (Partition #" + str(partition) + ")") if show_plot: pl.show()
#calling curvefit result = gmod.fit(new_y, r=new_x,a=2.33616190e-04,r_d=1.0) print(result.fit_report()) fig= plt.subplot(1,2,2) ax=plt.gca() plt.plot(new_x, new_y, 'bo') plt.plot(new_x, result.init_fit, 'k--') plt.plot(new_x, result.best_fit, 'r-') ax.set_xlabel("r") ax.set_ylabel("Mean surface density") save_figure.save("surface_profile", ext="png", close=False, verbose=True) plt.show() #print radialprofile.size """ fig = plt.subplot(1,2,2) plt.plot(Ddata.r,Ddata.mean) fp= open("my3.txt","w") np.savetxt(fp, np.c_[Ddata.r,Ddata.mean])
t += 1 print("t = " + str(t)) # LOOP END # ==== Visualization ==== folder_name = 'outputs/random(0.1) gamma(0.5) learn(0.1) VelocityControl 3-Action 3' for i in range(expert.cluster_num): expert.plot_model(partition=i, show_plot=False, save_fig_folder=folder_name) #(i==expert.cluster_num-1)) pl.figure(expert.cluster_num+1) pl.plot(prediction_error_history) pl.title("Prediction Error History") pl.xlabel("time") pl.ylabel("Prediction Error") save_figure.save(folder_name+"/Prediction Error History") pl.figure(expert.cluster_num+2) pl.hist(state1_history) pl.title("Resultant State Histogram") pl.xlabel("State") pl.ylabel("# of Occurrence") pl.autoscale(True) save_figure.save(folder_name+"/Resultant State Histogram") pl.figure(expert.cluster_num+3) pl.hist2d(state0_history, action0_history) pl.title("Initial State vs Initial Action Histogram") pl.xlabel("State") pl.ylabel("Action") pl.colorbar()
plt.plot(snapshot_win_time[:len(sample_avg_activation_avg_all_nodes)], sample_peak_activation_avg_all_nodes, "-mo", ms=10, label="Average Sample Peak Activation (for all Nodes; window=%.2f)" % win_size) # add the x-axis label plt.xlabel("Time (s)") # add the legend fontP = plt_font.FontProperties() fontP.set_size('small') plt.legend( bbox_to_anchor=(1.02, 1), loc=4, prop=fontP) # add text about correlation plt.text(60, 0.1,'R=%f' % pearson_correlation[0]) # plt.show() save_figure.save(fig, filename="study_%d - average_total_activation" % study_id, directory="plot_figures", verbose=False) # 7 b. plot the statistics that includes node of each node type fig = plt.figure(2) plt.clf() num_plot = len(sample_peak_activation_avg_type) + 1 line_color = iter(plt.cm.get_cmap('brg')(np.linspace(0,1,num_plot))) # plot the sample interest level over time plt.plot(snapshot_win_time[:len(sample_interest_level)], sample_interest_level, "-o", c=next(line_color), ms=10, label="Sample Interest Level",) # plot the average of peak sample activation level among nodes in each node type for node_type_id, node_type_data in sample_peak_activation_avg_type.items():
avg_activation_all = [] for row_id in range(ACTIVATION_DATA_ROW, len(activation_sheet)): activation_win_time.append(activation_sheet[row_id][ACTIVATION_TIME_COL]) cell_array = activation_sheet[row_id][ACTIVATION_DATA_COL:] # replace non-numerical values with 0 for id, cell in enumerate(cell_array): if not isinstance(cell, (float, int)): cell_array[id] = 0.0 avg_activation_all.append(np.mean(tuple(cell_array))) # 5. Compute the Pearson correlation between interest level and average sample activation level pearson_correlation = stats.pearsonr(sample_interest_level[:len(avg_sample_activation_all)], avg_sample_activation_all) print("Pearson Correlation --- R: %f; P-Value: %f" % (pearson_correlation[0], pearson_correlation[1])) # 6. plot them plt.clf() fig = plt.figure(1) plt.plot(snapshot_win_time[:len(avg_sample_activation_all)], avg_sample_activation_all, "-ro", ms=10, label="Sample Avg Activation (for all Nodes)") plt.plot(activation_win_time[:len(avg_activation_all)], avg_activation_all, "-b", label="Avg Activation (for all Nodes)") plt.plot(snapshot_win_time[:len(sample_interest_level)], sample_interest_level, "-go", ms=10, label="Sample Interest Level") plt.xlabel("Time (s)") plt.legend(bbox_to_anchor=(1.05, 1), loc=5, ) # add text about correlation plt.text(60, 0.1,'R=%f' % pearson_correlation[0]) # plt.show() save_figure.save(fig, filename="study_%d - average_total_activation.png" % study_id, directory="plot_figures") # return back to where the program was executed os.chdir(program_dir)
M1=[] for M in np.linspace(8,16,15): R_kpc = math.log(Disk_Scale_Radius(10**(M),Z,SPIN)/(3.086e+19),10) R1.append(R_kpc) M1.append(M) plt.plot(M1,R1,'--', linewidth='3', color = colors[count],label='z = %1.2f'%(Z)) count +=1 plt.grid(True) ll = plt.legend(loc='upper left') plt.xlabel("log$M_{vir}(M_0)$") plt.ylabel("log($R_d$ (kpc))") save_figure.save("M_{vir}vs_R_d_for_Z", ext="png", close=False, verbose=True) #CODE FOR DIFFERENT SPIN PARAMETER BUT REDSHIFT = 0 Z = 0.0 SPIN_PARA= np.linspace(0.01,0.09,8) del M1[:] del R1[:] count = 0 colors = plt.get_cmap("gist_rainbow")(np.linspace(0,1,len(SPIN_PARA))) plt.figure(2)