def plot_bar_battery(datas, num_of_bars,numb_of_cols, filename): ps.set_mode("tiny") fig = plt.gcf() ax = fig.add_subplot(111) ind = np.arange(numb_of_cols) # the x locations for the groups width = 0.35 # the width of the bars: can also be len(x) sequence bottomdt=np.zeros(numb_of_cols) p1 = ax.bar([0.5,1.85], datas[0], width, color='dodgerblue',align='center') #for i in range(2): bottomdt = bottomdt + datas[0] #print bottomdt # for j in range(numb_of_cols): # bottomdt[j]=bottomdt[i]+datas[i][j] p1 = ax.bar([0.5,1.85], datas[1], 0.35, color='r',bottom = bottomdt,align='center') #plt.show() plt.xticks([0.55,1.85],('MUB4','MUB5')) plt.ylabel('Power (KW)') plt.title('') #plt.xlim(0,2) #plt.xticks(ind, ind) plt.legend(('Battery', 'Fue'),loc=4,ncol=2) plt.show() fig.tight_layout() name = filename + '.pdf' fig.savefig(name)
def plot_tenant_util(tenant_reward_hours_array, tenant_cost_hours_array, num_hours, num_tenants, scheme=1): ps.set_mode("small") fig, ax = plt.subplots() width = 0.5 patterns = ["|||", "\\" ,"///" , "...", "---" , "xxx" , "+++" , "o", "O", "*" ] ind = np.arange(num_hours) + 1 name = ['Tenant 1', 'Tenant 2', 'Tenant 3','Tenant 4','Tenant 5'] bottom = np.zeros(num_hours) y = tenant_reward_hours_array - tenant_cost_hours_array print " Tenants' utility is: {} ".format(y) for i in range(num_tenants): ax.bar(ind, y[:,i], width=width, color= 'white', align='center', edgecolor='black', \ label=name[i], hatch=patterns[i], bottom=bottom) bottom += y[:,i] ax.set_xlabel(r'Time (h)') ax.set_ylabel("Tenants' utility") ax.set_xlim([-0.5, num_hours + 1]) if scheme == 1: # ax.set_title('EPM') plt.savefig('tenant_util_EPM.pdf') elif scheme ==2: # ax.set_title('SWO') plt.savefig('tenant_util_SWO.pdf') else: ax.legend(loc="best") # ax.set_title('RAND') plt.savefig('tenant_util_RAND.pdf') plt.show()
def plot_bar(datas, num_of_bars,numb_of_cols, filename): ps.set_mode("small") fig = plt.gcf() ax = fig.add_subplot(111) ind = np.arange(numb_of_cols) # the x locations for the groups width = 0.35 # the width of the bars: can also be len(x) sequence bottomdt=np.zeros(numb_of_cols) p1 = ax.bar(ind, datas[0], width, color=ps.colors[0]) for i in range(4): bottomdt = bottomdt + datas[i] #print bottomdt # for j in range(numb_of_cols): # bottomdt[j]=bottomdt[i]+datas[i][j] p1 = ax.bar(ind, datas[i+1], width, color=ps.colors[i+1],bottom = bottomdt) #plt.show() plt.xlabel('Time slots') plt.ylabel('Workloads') plt.title('') #plt.xticks(ind, ind) #plt.yticks(np.arange(0, 81, 10)) plt.legend(('DC 1', 'DC 2','DC 3','DC 4','DC 5'),loc=2,ncol=2) plt.show() fig.tight_layout() name = filename + '.pdf' fig.savefig(name)
def plot_bar_energy(data,numofsite): ps.set_mode("small") fig = plt.gcf() ax = fig.add_subplot(111, projection='3d') i=0 width=0.15 index = np.arange(numofsite) for c, z in zip(['r', 'g', 'b', 'y', 'c'], [1,2,3,4,5]): xs = np.arange(9) ys = data[i] i=i+1 # You can provide either a single color or an array. To demonstrate this, # the first bar of each set will be colored cyan. cs = [c] * len(xs) ax.bar(xs, ys, zs=z, zdir='y', color=cs, alpha=0.8) if i==4: plt.yticks(index + width + 1, ('1', ' 2', '3', '4', '5')) ax.set_xlabel('Time slot') ax.set_ylabel('MUB') ax.set_zlabel('Energy (KWh)') plt.show() fig.tight_layout() fig.savefig('plot_bar_energy.pdf')
def plot_compare_water(datas, num_of_bars, numb_of_cols, filename): ps.set_mode("tiny") fig = plt.gcf() ax = fig.add_subplot(111) ind = np.arange(numb_of_cols) # the x locations for the groups width = 0.35 # the width of the bars: can also be len(x) sequence bottomdt = np.zeros(numb_of_cols) #(31, 119, 180), (174, 199, 232), colors=[ (44, 160, 44), (152, 223, 138), (214, 39, 40), (255, 152, 150), (148, 103, 189), (197, 176, 213), (140, 86, 75), (196, 156, 148), (227, 119, 194), (247, 182, 210), (127, 127, 127), (199, 199, 199), (188, 189, 34), (219, 219, 141), (23, 190, 207), (158, 218, 229)] for i in range(len(colors)): r, g, b = colors[i] colors[i] = (r / 255., g / 255., b / 255.) p1 = ax.bar(ind, datas[0], width, color=colors[0]) p1 = ax.bar(ind+width, datas[1], width, color='r') plt.ylabel('Water (L)') plt.xticks(ind+width, ["MUB1","MUB2","MUB3","MUB4","MUB5"]) # plt.yticks(np.arange(0, 81, 10)) plt.legend(('JEWAS-ON', 'Over'), loc=2, ncol=2) plt.show() fig.tight_layout() name = filename + '.pdf' fig.savefig(name)
def plot_cost_case2(): ps.set_mode("tiny") labels = ['DCSM', 'SMT', 'K-mean'] markerstyle = ['>', 'o', '+', '+', 's', 'd', '^', '<', '>', '+', '*', 'x'] fig = plt.gcf() N = len(dmp.numberof_CT_dcsm) ind = np.arange(20,60, step=5) # the x locations for the groups width = 0.25 # the width of the bars: can also be len(x) sequence data = [dmp.total_cost_dcsm_case2, dmp.total_cost_smt_case2, dmp.total_cost_shortest_case2] numb_of_line=3 for line in range(numb_of_line): plt.plot(data[line], color=new_colors[line], ls=linestyles[line], marker=markers[line], markersize=4, label=labels[line], markevery=1) plt.ylabel('Total cost') plt.xlabel('\# service chains') plt.xticks(np.arange(0,40, step=5),np.arange(20,60, step=5)) #plt.ylim([2,8.5]) plt.legend( ('DCSM','SMT','K-mean'),loc=2,ncol=3) plt.show() filename="plot_cost_case2" fig.tight_layout() name = filename + '.pdf' fig.savefig(name)
def plot_tenant_util(tenant_reward_hours_array, tenant_cost_hours_array, num_hours, num_tenants, scheme=1): ps.set_mode("small") fig, ax = plt.subplots() width = 0.5 patterns = ["|||", "\\" ,"///" , "...", "---" , "xxx" , "+++" , "o", "O", "*" ] ind = np.arange(num_hours) + 1 name = ['Tenant 1', 'Tenant 2', 'Tenant 3','Tenant 4','Tenant 5'] bottom = np.zeros(num_hours) y = tenant_reward_hours_array - tenant_cost_hours_array #print " Tenants' utility is: {} ".format(y) for i in range(num_tenants): ax.bar(ind, y[:,i], width=width, color= 'white', align='center', edgecolor='black', \ label=name[i], hatch=patterns[i], bottom=bottom) bottom += y[:,i] ax.set_xlabel(r'Time (h)') ax.set_ylabel("Tenants' utility") ax.set_xlim([-0.5, num_hours + 1]) if scheme == 1: # ax.set_title('EPM') plt.savefig('tenant_util_EPM.pdf') elif scheme ==2: # ax.set_title('SWO') plt.savefig('tenant_util_SWO.pdf') else: ax.legend(loc="best") # ax.set_title('RAND') plt.savefig('tenant_util_RAND.pdf') plt.show()
def plot_tenant_e(tenant_e_hours_list, num_hours, num_tenants, scheme=1): ps.set_mode("small") fig, ax = plt.subplots() width = 0.5 patterns = ["|||", "\\" ,"///" , "...", "---" , "xxx" , "+++" , "o", "O", "*" ] index = np.arange(num_hours) + 1 name = ['Tenant 1', 'Tenant 2', 'Tenant 3','Tenant 4','Tenant 5'] bottom = np.zeros(num_hours) for i in range(num_tenants): ax.bar(index, tenant_e_hours_list[:,i]*scale, width=width, color= 'white', align='center', edgecolor='black', \ label=name[i], hatch=patterns[i], bottom=bottom) bottom += tenant_e_hours_list[:,i]*scale ax.set_xlabel(r'Time (h)') ax.set_ylabel(r'$\Delta e_i$') ax.set_xlim([-0.5, num_hours+1]) if scheme == 1: # ax.set_title('EPM') plt.savefig('tenant_e_EPM.pdf') elif scheme ==2: # ax.set_title('SWO') plt.savefig('tenant_e_SWO.pdf') else: ax.legend(loc="best") # ax.set_title('RAND') plt.savefig('tenant_e_RAND.pdf') plt.show()
def plot_price_convg(provider, k): ps.set_mode("small") fig, (ax1, ax2) = plt.subplots(1, 2, sharex=True, sharey=True) x = np.arange(k)[start_iter:] y = provider.price_convg_list[start_iter:] ax1.plot(x,y, lw=linewidth, alpha=0.6, marker = markers[1]) y_max = provider.price_convg_list[-1] ax1.set_ylim(0.5*y_max, 1.5*y_max ) ax1.set_xlabel('iterations') ax1.set_ylabel(r'$g(\Theta^{ne})$') y = provider.price_convg_SWO_list[start_iter:] ax2.plot(x,y, lw=linewidth, alpha=0.6, marker = markers[2]) y_max = provider.price_convg_SWO_list[-1] ax2.set_ylim(0.5*y_max, 1.5*y_max ) ax2.set_xlabel('iterations') ax2.set_ylabel(r'$\nu^*$') ax2.legend(loc="upper left") fig.tight_layout() plt.savefig('price_convg.pdf') plt.show()
def plot_totalcost(): labels=['Branch-and-bound','RMINLP','L-VNFP'] ps.set_mode("tiny") fig = plt.gcf() number_lines=3 x_data=dmp.optimal_nodes #print(len(x_data)) y_data=[dmp.optimal_cost,dmp.rminlp_cost,dmp.lvnf_cost] for i in range(number_lines): plt.plot(x_data,y_data[i], color=new_colors[i],ls=linestyles[i], marker=markers[i],label=labels[i],markevery=5) plt.ylabel('Total cost') plt.xlabel('Number of nodes') plt.legend(loc=2) plt.show() filename="plot_totalcost" fig.tight_layout() name = filename + '.pdf' fig.savefig(name) plt.show() filename="plot_instance" fig.tight_layout() name = filename + '.pdf' fig.savefig(name)
def plot_cdf(): labels = ['R-DCSM', 'SMT','K-mean'] ps.set_mode("tiny") fig = plt.gcf() N = 3 ind = np.arange(N) # the x locations for the groups width = 0.35 # the width of the bars: can also be len(x) sequence x_data=[dmp.RDCSM_CDF_iteration,dmp.SMT_CDF_iteration,dmp.DCA_iteration] data=[dmp.RDCSM_CDF,dmp.SMT_CDF,dmp.DCA_CDF] numb_of_line=3 for line in range(numb_of_line): plt.plot(x_data[line],data[line], color=ps.colors[line],ls='-', label=labels[line],markevery=2) plt.legend(loc=4) # if xlim != []: # plt.xlim(xlim) # if ylim != []: # plt.ylim(ylim) # if title != '': # plt.title(title) filename="plot_CDF" plt.xlabel("Iterations") plt.ylabel("CDF") plt.show() fig.tight_layout() name = filename + '.pdf' fig.savefig(name) labels = ['DCSM','R-DCSM','D-DCSM', 'SMT', 'K-mean'] ps.set_mode("tiny") fig = plt.gcf() N = 3 ind = np.arange(N) # the x locations for the groups width = 0.35 # the width of the bars: can also be len(x) sequence x_data = [20,60,110] data = [dmp.dcsm_time, dmp.rdcsm_time,dmp.ddcsm_time, dmp.smt_time,dmp.short_time] numb_of_line = 5 markerstyle = ['>', '*', 'o', '+', 's', 'd', '^', '<', '>', '+', '*', 'x'] for line in range(numb_of_line): plt.plot(x_data, data[line], color=ps.colors[line], ls='-', label=labels[line], markevery=1) plt.legend(loc=2) # if xlim != []: # plt.xlim(xlim) # if ylim != []: # plt.ylim(ylim) # if title != '': # plt.title(title) filename = "plot_execution_time" plt.xlabel("\# service chains") plt.ylabel("Time (seconds)") plt.show() fig.tight_layout() name = filename + '.pdf' fig.savefig(name)
def plot_instance: ps.set_mode("tiny") fig = plt.gcf() N = len(dmp.numberof_CT_dcsm) ind = np.arange(N) # the x locations for the groups width = 0.25 # the width of the bars: can also be len(x) sequence p1 = plt.bar(ind, np.array(dmp.Energy_cost_dcsm), width, color=new_colors[0], align='center') p2 = plt.bar(ind + width, np.array(dmp.Energy_cost_shortest), width, color=new_colors[1], align='center') p3 = plt.bar(ind + 2 * width, np.array(dmp.Energy_cost_smt), width, color=new_colors[2], align='center') plt.ylabel('Energy cost') plt.xticks(ind + width - 0.15, dmp.numberof_SC) # plt.yticks(np.arange(0, 81, 10)) plt.legend((p1[0], p2[0], p3[0]), ('DCSM', 'Shortest', 'SMT'), loc=2, ncol=1)
def plot_lines(datas, numb_of_line, ls,markerstyle, title, labels, xlb, ylb): ps.set_mode("small") fig=plt.gcf() stride=20 for line in range(numb_of_line): plt.plot(datas[line], ls=ls[line],marker = markerstyle[line], markersize=5, label=labels[line],markevery=stride) plt.legend(loc=1) #plt.xlim([0,50]) #plt.ylim(0,20) plt.title(title) plt.xlabel=xlb plt.ylabel=ylb plt.show() name=ylb+'.pdf' fig.savefig(name)
def plot_lines(datas, numb_of_line, ls,markerstyle,mksize, title, labels, xlb, ylb,stri,filename): ps.set_mode("small") fig=plt.gcf() #stride=2 for line in range(numb_of_line): plt.plot(datas[line], ls=ls[line],marker = markerstyle[line], markersize=mksize, label=labels[line],markevery=stri) plt.legend(loc=1) #plt.xlim([0,50]) #plt.ylim(0,20) plt.title(title) plt.xlabel(xlb) plt.ylabel(ylb) plt.show() fig.tight_layout() name=filename+'.pdf' fig.savefig(name)
def sub_energy(energy): ps.set_mode("tiny") fig = plt.figure() ax = fig.add_subplot(111) ax.spines['top'].set_color('none') ax.spines['bottom'].set_color('none') ax.spines['left'].set_color('none') ax.spines['right'].set_color('none') ax.tick_params(labelcolor='w', top='off', bottom='off', left='off', right='off') ax.set_xlabel('common xlabel') ax.set_ylabel('common ylabel') axarr0=subplot(2,1,1) axarr0.plot(energy[0],ls='-',marker='',label='Office 1',markevery=stride) axarr0.plot(energy[1],ls='-',marker='+',label='Office 2',markevery=stride) axarr0.plot(energy[2],ls='-',marker='.',label='Office 3',markevery=stride) axarr0.set_xlim([0,runTime]) axarr0.set_ylim([0,200]) axarr0.legend(loc=1, ncol=1, shadow=True, fancybox=False) #xticks([]), yticks([0,20,40,60,80]) axarr1=subplot(2,1,2) axarr1.plot(energy[3],ls='--',marker='+',label='DC 1',markevery=stride) axarr1.plot(energy[4],ls='--',marker='.',label='DC 2',markevery=stride) axarr1.plot(energy[5],ls='--',marker='',label='DC 3',markevery=stride) axarr1.plot(energy[6],ls='-',marker='',label='BK',markevery=stride) axarr1.set_xlim([0,runTime]) axarr1.set_ylim([-5,300]) axarr1.legend(loc=1, ncol=1, shadow=True, fancybox=False) #xticks([]), yticks([0,20,40,60,80]) # axarr2=subplot(3,1,3) # axarr2.plot(energy[6],ls='-',marker='.',label='Backup') # # # axarr2.legend(loc="right", ncol=1, shadow=True, fancybox=False) # axarr2.set_ylim([75,80]) # axarr2.set_xlim([0,30]) # yticks([75,77,79]) fig.text(0.5, 0.04, 'Iterations', ha='center', va='center') fig.text(0.055, 0.5, 'Energy (Kwh)', ha='center', va='center', rotation='vertical') plt.show() fig.tight_layout() fig.savefig('energy_conv.pdf')
def sub_energy(energy): ps.set_mode("tiny") fig = plt.figure() ax = fig.add_subplot(111) ax.spines['top'].set_color('none') ax.spines['bottom'].set_color('none') ax.spines['left'].set_color('none') ax.spines['right'].set_color('none') ax.tick_params(labelcolor='w', top='off', bottom='off', left='off', right='off') ax.set_xlabel('common xlabel') ax.set_ylabel('common ylabel') axarr0=subplot(2,1,1) axarr0.plot(energy[0],ls='-',marker='',label='Office 1',markevery=stride) axarr0.plot(energy[1],ls='-',marker='+',label='Office 2',markevery=stride) axarr0.plot(energy[2],ls='-',marker='.',label='Office 3',markevery=stride) #axarr0.set_xlim([0,runTime]) axarr0.set_ylim([0,200]) axarr0.legend(loc=1, ncol=1, shadow=True, fancybox=False) #xticks([]), yticks([0,20,40,60,80]) axarr1=subplot(2,1,2) axarr1.plot(energy[3],ls='--',marker='+',label='DC 1',markevery=stride) axarr1.plot(energy[4],ls='--',marker='.',label='DC 2',markevery=stride) axarr1.plot(energy[5],ls='--',marker='',label='DC 3',markevery=stride) axarr1.plot(energy[6],ls='-',marker='',label='BK',markevery=stride) #axarr1.set_xlim([0,runTime]) #axarr1.set_ylim([-5,300]) axarr1.legend(loc=1, ncol=1, shadow=True, fancybox=False) #xticks([]), yticks([0,20,40,60,80]) # axarr2=subplot(3,1,3) # axarr2.plot(energy[6],ls='-',marker='.',label='Backup') # # # axarr2.legend(loc="right", ncol=1, shadow=True, fancybox=False) # axarr2.set_ylim([75,80]) # axarr2.set_xlim([0,30]) # yticks([75,77,79]) fig.text(0.5, 0.04, 'Iterations', ha='center', va='center') fig.text(0.015, 0.5, 'Energy (Kwh)', ha='center', va='center', rotation='vertical') plt.show() fig.tight_layout() fig.savefig('energy_conv.pdf')
def plot_everage_delay(data, numberofsite): ps.set_mode("tiny") fig, ax = plt.subplots() width = 0.3 patterns = ["|||", "\\", "///", "...", "---", "xxx", "+++", "o", "O", "*"] name = ['DCSM', 'SMT', 'K-mean'] index = np.arange(numberofsite) #for i in range(numberofsite): i=0 ax.bar(index + width * i, data, width=width, alpha=0.4, color='red', edgecolor='black') # ax.set_ylim([10., 350]) ax.set_ylabel("Latency (ms)") plt.xticks(index +0.2, ('DCSM', 'SMT', 'K-mean')) fig.tight_layout() plt.savefig('plot_everage_delay.pdf') plt.show()
def plot_alpha(nu_SWO, price_convg_list_alpha, alpha_prov_pay_list, alpha_list): ps.set_mode("small") fig, (ax1, ax2) = plt.subplots(1, 2) x_range = range(len(price_convg_list_alpha) + 1) stride = 10. for i in x_range: if i != max(x_range): x = range(len(price_convg_list_alpha[i])) y = price_convg_list_alpha[i] current_label = r"$\alpha=${}".format(alpha_list[i]) else: x = range(len(nu_SWO)) y = nu_SWO current_label = r'$\nu^{*}$' # if i < len(linestyles): # ax1.plot(x,y, lw=linewidth, color=ps.colors[i], alpha=0.6, label = current_label, ls = linestyles[i]) # else: ax1.plot(x,y, lw=linewidth, color=ps.colors[i], alpha=0.6, label =current_label, ls = linestyles[0], marker = markers[i], markevery=stride) # ax1.plot(x,y, lw=linewidth, color=ps.colors[i], alpha=0.6, label = current_label, marker = markers[i]) y_max = max([i[-1] for i in price_convg_list_alpha]) ax1.set_ylim(0.5*y_max, 2.5*y_max ) ax1.set_xlabel('iterations') ax1.set_ylabel(r'$g(\Theta^{ne})$') # Legend leg = ax1.legend(loc="upper center", ncol=2, fancybox=True, shadow=True, bbox_to_anchor=(0.5, 1.10)) # leg.get_frame().set_facecolor('0.9') # set the frame face color to light gray # leg.get_frame().set_alpha(0.99) # for t in leg.get_texts(): # t.set_fontsize('small') # the legend text fontsize # for l in leg.get_lines(): # l.set_linewidth(1.0) # the legend line width x = alpha_list y = alpha_prov_pay_list ax2.plot(x,y, lw=linewidth, alpha=0.6) ax2.set_xlabel(r'$\alpha$') ax2.set_ylabel(r'$\sum\limits_{i} R_i$') fig.tight_layout() plt.savefig('alpha.pdf') plt.show()
def plot_e_convg_SWO(tenant_list, k): ps.set_mode("small") fig, ax = plt.subplots() x = np.arange(k)[start_iter:] stride = max( int(len(x)/10), 1 ) for i in range(len(tenant_list)): y = (np.array(tenant_list[i].e_convg_SWO_list))[start_iter:]*scale current_label = r'Tenant {}'.format(i+1) # if i < len(linestyles): # ax.plot(x,y, lw=linewidth, color=ps.colors[i], alpha=0.6, label = current_label, ls = linestyles[i]) # else: ax.plot(x,y, lw=linewidth, color=ps.colors[i], alpha=0.6, label = current_label, ls = linestyles[0], marker = markers[i], markevery=stride) ax.set_xlabel('iterations') ax.set_ylabel(r'$\Delta e_i$') ax.legend(loc="upper left") fig.tight_layout() plt.savefig('e_convg_SWO.pdf') plt.show()
def plot_bar_battery_charging(datas, num_of_bars, numb_of_cols, filename): ps.set_mode("tiny") fig = plt.gcf() ax = fig.add_subplot(111) ind=np.arange(len(datas[0])) width = 0.35 # the width of the bars: can also be len(x) sequence p1 = ax.bar(ind,datas[0], width, color='b', align='edge') p1 = ax.bar(ind, datas[1], width, color='r', align='edge') plt.xlabel('Time slot') plt.ylabel('Power (KW)') plt.ylim([-700,700]) plt.legend(['Discharging','Charging'], loc=2, ncol=2) plt.show() fig.tight_layout() name = filename + '.pdf' fig.savefig(name)
def totalCost(DANE,baseline1,baseline2,opt): # ps.set_mode("tiny") fig=plt.figure() stride=4 plt.plot(DANE, marker = '^', markersize=5, label='DAMESH',markevery=stride) plt.plot(baseline1, ls='--',marker = '+', markersize=5, label='Baseline 1',markevery=stride) plt.plot(baseline2, ls='-',marker = 'o', markersize=5, label='Baseline 2',markevery=stride) #optimal value plt.plot(np.ones(runTime)*opt,ls='--', markersize=5, label='Optimal') plt.xlim([0,100]) #plt.ylim([0,10]) #plt.ylim([35,60]) plt.legend(loc=1) plt.xlabel('Iterations') plt.ylabel('Total cost') plt.show() fig.tight_layout() fig.savefig('plot/totalcost_conv.pdf')
def plot_traces(Lamb_array): ps.set_mode("small") fig, ax = plt.subplots() x = np.arange(np.size(Lamb_array[0])) + 1 name = ['MSR', 'FIU', 'Syn.1','Syn.2','Syn.3'] for i in range(len(name)): y = Lamb_array[i] if i < len(linestyles): ax.plot(x,y, lw=linewidth, color=ps.colors[i], alpha=0.6, label = name[i], ls = linestyles[i]) else: ax.plot(x,y, lw=linewidth, color=ps.colors[i], alpha=0.6, label = name[i], ls = linestyles[-1], marker = markers[i]) fig.tight_layout() ax.set_xlabel(r'Time (h)') ax.set_ylabel(r"$\lambda_i$") ax.set_ylim([0., 1]) ax.legend(loc="upper left") fig.tight_layout() plt.savefig('traces.pdf') plt.show()
def totalCost(DANE,baseline1,baseline2,opt): # ps.set_mode("tiny") fig=plt.figure() stride=2 plt.plot(DANE, marker = '^', markersize=5, label='DANE',markevery=stride) plt.plot(baseline1, ls='--',marker = '+', markersize=5, label='Baseline 1',markevery=stride) plt.plot(baseline2, ls='-',marker = 'o', markersize=5, label='Baseline 2',markevery=stride) #optimal value plt.plot(np.ones(runTime)*opt,ls='--', markersize=5, label='Optimal') plt.xlim([0,50]) #plt.ylim([0,10]) #plt.ylim([35,60]) plt.legend(loc=1) plt.xlabel('Iterations') plt.ylabel('Total cost') plt.show() fig.tight_layout() fig.savefig('plot/totalcost_conv.pdf')
def plot_lines(datas, numb_of_line, ls,markerstyle,mksize, title, labels, xlb, ylb,stri,xlim,ylim,filename): ps.set_mode("small") fig=plt.gcf() #stride=2 for line in range(numb_of_line): plt.plot(datas[line], color=ps.colors[line],ls=ls[line],marker = markerstyle[line], markersize=mksize, label=labels[line],markevery=stri) plt.legend(loc=2) if xlim!=[]: plt.xlim(xlim) if ylim!=[]: plt.ylim(ylim) if title!='': plt.title(title) plt.xlabel(xlb) plt.ylabel(ylb) plt.show() fig.tight_layout() name=filename+'.pdf' fig.savefig(name)
def plot_lines_convergence( x_data,datas,numb_of_line, ls,markerstyle,mksize, title, labels, xlb, ylb,stri,xlim,ylim,filename): ps.set_mode("tiny") fig=plt.gcf() #stride=2 data=datas[0] # for i in range(len(data)): # if i>200: # data[i]=data[i]/(i*0.0002+1) for line in range(numb_of_line): plt.plot(x_data[line],data, color='teal',ls='-', label=labels[line],markevery=stri) #plot optimal optimal=np.ones(len(dmp.iteration))*17.4 plt.plot(dmp.iteration,optimal,ls=':',label='Optimal',color='red') plt.legend(loc=1) if xlim != []: plt.xlim(xlim) if ylim!=[]: plt.ylim(ylim) if title!='': plt.title(title) #plt.yscale('log') fig=plt.gcf() plt.xlabel(xlb) plt.ylabel(ylb) plt.axes([.5, .45, .35, .25]) zoomx=np.zeros(20) zoomy=np.zeros(20) for i in range(20): j=220+i zoomx[i]=dmp.iteration[j] zoomy[i]=dmp.cost[j] plt.plot(zoomx,zoomy,color='teal') plt.yticks([17.843,17.85]) plt.show() fig.tight_layout() name=filename+'.pdf' fig.savefig(name)
def plot_total_cost( x_data,datas,numb_of_line, ls,markerstyle,mksize, title, labels, xlb, ylb,stri,xlim,ylim,filename): ps.set_mode("small") fig=plt.gcf() colors = ['orange','lightblue','darkgreen','gold', 'r', 'navy', 'teal', 'darkorange', 'purple', 'g', 'k', 'dodgerblue', 'm', 'darksalmon', 'b', 'y', 'darkgrey', 'c'] linestyles = ['-', '-','-','-.','-'] # ,'-.'] #stride=2 for line in range(numb_of_line): plt.plot(x_data[0],datas[line], color=colors[line],ls=linestyles[line],marker = markerstyle[line], markersize=mksize, label=labels[line],markevery=stri) plt.legend(loc=1,ncol=3,fontsize ='medium') if xlim!=[]: plt.xlim(xlim) #plt.ylim([35,160]) if title!='': plt.title(title) plt.xlabel(xlb) plt.ylabel(ylb) fig = plt.gcf() # x = [25,19.5] # y = [200,410] x = [8, 3.8] y = np.array([38, 55]) plt.plot(x, y, 'b-', linewidth=1) # x = [5,5] # y = [200,410] x = [9, 6.5] y = np.array([42, 55]) plt.plot(x, y, 'b-', linewidth=1) plt.axes([.2, .55, .3, .15], axisbg='w') #optimal plt.plot(np.array([286.5, 303.5])/8, color='r') #rounding plt.plot(np.array([318.5, 339.5,])/8,ls='-.', color='gold') #dcms plt.plot(np.array([298.5, 315.5])/8, color='orange') plt.xticks([0,1],[8,9]) plt.yticks([30,35, 40]) plt.show() fig.tight_layout() name=filename+'2.pdf' fig.savefig(name)
def plot_reward_convg(tenant_list, k): ps.set_mode("small") fig, ax = plt.subplots() x = np.arange(k)[start_iter:] stride = max( int(len(x)/10), 1 ) for i in range(len(tenant_list)): y = tenant_list[i].reward_convg_list[start_iter:] current_label = r'Tenant {}'.format(i+1) # if i < len(linestyles): # ax.plot(x,y, lw=linewidth, color=ps.colors[i], alpha=0.6, label = current_label, ls = linestyles[i]) # else: ax.plot(x,y, lw=linewidth, color=ps.colors[i], alpha=0.6, label = current_label, ls = linestyles[0], marker = markers[i], markevery=stride) y_max = max([i.reward_convg_list[-1] for i in tenant_list]) ax.set_ylim(0., 1.5*y_max ) ax.set_xlabel('iterations') ax.set_ylabel(r'$R_i$') ax.legend(loc="upper left") fig.tight_layout() plt.savefig('reward_convg.pdf') plt.show()
def plot_learningrate(): ps.set_mode("tiny") fig=plt.gcf() x_data=[dmp.time1,dmp.time2,dmp.time3] y_data=[dmp.error1,dmp.error2,dmp.error3] numb_of_lines=3 labels=['Learning rate 0.01','Learning rate 0.007','Learning rate 0.004'] for line in range(numb_of_lines): print(line) #plt.scatter(x_data[line],y_data[line], color=colors[line],ls=linestyles[line], label=labels[line]) plt.plot(x_data[line],y_data[line], color=colors[line],ls=linestyles[line], label=labels[line],markevery=1) plt.legend(loc=1) #plt.yscale('log') plt.xlabel('Seconds') plt.ylabel('Mean square error') plt.show() fig.tight_layout() name='plot_learningrate.pdf' fig.savefig(name)
def plot_energy_bar(data, numberofsite): ps.set_mode("small") fig, ax = plt.subplots() width = 0.15 patterns = ["|||", "\\", "///", "...", "---", "xxx", "+++", "o", "O", "*"] name = ['MUB 1', 'MUB 2', 'MUB 3', 'MUB 4', 'MUB 5'] # ax.annotate('The comfort energy of \n office tenant 1 at MUB 3.', xy=(2.2, 200), xytext=(3, 250.5), # arrowprops=dict(facecolor='black', width=0.1, frac=0.2, headwidth=3), # ) index = np.arange(numberofsite) for i in range(numberofsite): ax.bar(index + width * i, data[i], width=width, alpha=0.4, color=ps.colors[i], edgecolor='black') #ax.set_ylim([10., 350]) ax.set_ylabel("Energy (kW)") plt.xticks(index + width + 0.05, ('MUB 1', 'MUB 2', 'MUB 3', 'MUB 4', 'MUB 5')) fig.tight_layout() plt.savefig('plot_energy_lim.pdf') plt.show()
def plot_correlation(): ps.set_mode("tiny") fig, ax = plt.subplots() cax = ax.imshow(np.array(dmp.correlation_dcsm), interpolation='nearest', cmap=cm.afmhot) cbar = fig.colorbar(cax, ticks=[0, 0.2,0.4], orientation='vertical') cbar.ax.set_xticklabels(['Low', 'Medium', 'High']) # horizontal colorbar filename = "plot_correlation_dcsm" plt.xlabel("Controller") plt.ylabel("Controller") plt.show() fig.tight_layout() name = filename + '.pdf' fig.savefig(name) ############################ fig, ax = plt.subplots() cax = ax.imshow(np.array(dmp.correlation_shortest), interpolation='nearest', cmap=cm.afmhot) cbar = fig.colorbar(cax, ticks=[0, 0.2, 0.4], orientation='vertical') cbar.ax.set_xticklabels(['Low', 'Medium', 'High']) # horizontal colorbar filename = "plot_correlation_shortest" plt.xlabel("Controller") plt.ylabel("Controller") plt.show() fig.tight_layout() name = filename + '.pdf' fig.savefig(name) ############################ fig, ax = plt.subplots() cax = ax.imshow(np.array(dmp.correlation_smt), interpolation='nearest', cmap=cm.afmhot) cbar = fig.colorbar(cax, ticks=[0, 0.2, 0.4], orientation='vertical') cbar.ax.set_xticklabels(['Low', 'Medium', 'High']) # horizontal colorbar filename = "plot_correlation_smt" plt.xlabel("Controller") plt.ylabel("Controller") plt.show() fig.tight_layout() name = filename + '.pdf' fig.savefig(name)
def plot_sum_cost(sum_cost_all_array, num_hours, num_tenants): ps.set_mode("small") fig, ax = plt.subplots() index = np.arange(num_hours)+1 bar_width = 0.25 space = 0.01 opacity = 0.99 error_config = {'ecolor': '0.3'} patterns = ["|||", "\\" ,"///" , "...", "---" , "xxx" , "+++" , "o", "O", "*" ] alg1 = ax.bar(index, sum_cost_all_array[0,:]*scale, bar_width, alpha=opacity, color= 'white', error_kw=error_config, hatch=patterns[1], label='EPM', align='center') alg2 = ax.bar(index + bar_width + space, sum_cost_all_array[1,:]*scale, bar_width, alpha=opacity, color= 'white', error_kw=error_config, hatch=patterns[2], label='SWO', align='center') alg3 = ax.bar(index + 2*(bar_width + space), sum_cost_all_array[2,:]*scale, bar_width, alpha=opacity, color= 'white', error_kw=error_config, hatch=patterns[3], label='RAND',align='center') # autolabel(alg1) # autolabel(alg2, 0.01) # autolabel(alg3, 0.03) plt.xticks(index + bar_width, index, rotation='0', fontsize=8) ax.set_xlim(0,len(index) + 2) y_max = sum_cost_all_array.max()*scale ax.set_ylim(0., 1.1*y_max ) ax.set_ylabel(r"$\sum\nolimits_{i} C_i(m_i)$") ax.set_xlabel(r'Time (h)') ax.legend(loc="lower right") fig.tight_layout() plt.savefig("sum_cost.pdf")
def plot_compare_energy(datas, num_of_bars, numb_of_cols, filename): ps.set_mode("tiny") fig = plt.gcf() ax = fig.add_subplot(111) ind = np.arange(numb_of_cols) # the x locations for the groups width = 0.35 # the width of the bars: can also be len(x) sequence bottomdt = np.zeros(numb_of_cols) #(31, 119, 180), (174, 199, 232), colors=[ (255, 127, 14), (255, 187, 120), (44, 160, 44), (152, 223, 138), (214, 39, 40), (255, 152, 150), (148, 103, 189), (197, 176, 213), (140, 86, 75), (196, 156, 148), (227, 119, 194), (247, 182, 210), (127, 127, 127), (199, 199, 199), (188, 189, 34), (219, 219, 141), (23, 190, 207), (158, 218, 229)] for i in range(len(colors)): r, g, b = colors[i] colors[i] = (r / 255., g / 255., b / 255.) p1 = ax.bar(ind, datas[0], width, color=colors[0]) for i in range(numb_of_cols-1): bottomdt = bottomdt + datas[i] # print bottomdt # for j in range(numb_of_cols): # bottomdt[j]=bottomdt[i]+datas[i][j] p1 = ax.bar(ind, datas[i + 1], width, color=colors[i + 1]) # plt.show() plt.ylim([0,75]) plt.ylabel('Energy (MWh)') plt.title('') plt.xticks(ind+width/2, ["JEWAS-ON","Uncordinated","Over"]) # plt.yticks(np.arange(0, 81, 10)) plt.legend(('DC', 'HVAC', 'Battery', 'Fuel'), loc=2, ncol=3) plt.show() fig.tight_layout() name = filename + '.pdf' fig.savefig(name)
######### Read input files info itr=1 #base_dir= '/home/shusin3/users/moghimi/assimilation/assim_local/wave_current/run5_syn_paper_cases/04_wave_limit_test_final/99_wav_cur_true2true/' #base_dir= '/home/shusin4/users/moghimi/assimilation/assim_local/wave_current/run5_syn_paper_cases/05_wave_limit_test_final_new_chh/800_tru_tru_new_cov' #base_dir= '/home/shusin4/users/moghimi/assimilation/assim_local/wave_current/run5_syn_paper_cases/05_wave_limit_test_final_new_chh/801_tru_tru_simple_alpha01_hcrit0.5' base_dir= '/home/shusin4/users/moghimi/assimilation/assim_local/wave_current/run5_syn_paper_cases/05_wave_limit_test_final_new_chh/801_tru_tru_simple_alpha01_hcrit0.5' base=base_dir+'/run_'+str(1000+itr)+'/04_mem_adj/m*' flist=glob.glob(base) flist.sort() ################ figure setting stuff >>>>> # Publishable quality image if nall < 2: ps.set_mode("publish") fig_size1=ps.get_figsize(250) else: ps.set_mode("medium") fig_size1=ps.get_figsize(500) #subplot params icount=1 rrow=1 # figs param dpi=400 fwidth,fheight= fig_size1 my_fs=3 fontsize=6 icol=8
sigma[5][i] = mub.sigmai[2] sigma[6][i] = mub.sigmaz cost[0][i]=hvac.userComfCosti(0) cost[1][i]=hvac.userComfCosti(1) cost[2][i]=hvac.userComfCosti(2) cost[3][i]=dc.dcCosti(0) cost[4][i]=dc.dcCosti(1) cost[5][i]=dc.dcCosti(2) cost[6][i]=bk.bgCost() curr=sum(mub.sigmai)+sum(mub.sigman)+mub.sigmaz Totalcost[i]=cost[0][i]+cost[1][i]+cost[2][i]+cost[3][i]+cost[4][i]+cost[5][i]+cost[6][i] print(Totalcost[i]) #x=np.arange(runTime) ps.set_mode("tiny") plt.plot(Totalcost) plt.show() #ax.plot(x, y, color=next(color_cycler), label = current_label, marker = next(marker_cycler), markevery=stride) def plot_lines(datas, numb_of_line, ls,markerstyle, title, labels, xlb='', ylb=''): fig=plt.gcf() stride=20 for line in range(numb_of_line): plt.plot(datas[line], ls=ls[line],marker = markerstyle[line], markersize=4, label=labels[line],markevery=stride) plt.legend(loc=1) #plt.xlim([0,50]) #plt.ylim(ylim) plt.title(title) plt.xlabel=xlb plt.ylabel=ylb
def main(): print_output = False move_nao = True motion_proxy = ALProxy("ALMotion", "nao.ini.rub.de", 9559) initial_x = 0.05 initial_y = -0.10 initial_z = 0.0 if (move_nao): motion_proxy.setStiffnesses("RArm", 1.0) motion_proxy.positionInterpolation( "RArm", 0, [initial_x, initial_y, initial_z, 0, 0, 0], 7, 3, True) # create a task node task_node = DynamicField.DynamicField([], [], None) task_node.set_boost(10) # create a motor node motor_node_x = DynamicField.DynamicField([], [], None) motor_node_x.set_resting_level(0.) motor_node_x.set_initial_activation(initial_x) motor_node_x.set_noise_strength(0.0) motor_node_x.set_relaxation_time(60.) motor_node_y = DynamicField.DynamicField([], [], None) motor_node_y.set_resting_level(0.) motor_node_y.set_initial_activation(initial_y) motor_node_y.set_noise_strength(0.0) motor_node_y.set_relaxation_time(60.) # create elementary behavior: move end effector move_ee_field_sizes = [50, 50] move_ee_int_weight = numpy.ones((move_ee_field_sizes)) * 2.0 move_ee = BehOrg.ElementaryBehavior.with_internal_fields( field_dimensionality=2, field_sizes=[[move_ee_field_sizes[0]], [move_ee_field_sizes[1]]], field_resolutions=[], int_node_to_int_field_weight=move_ee_int_weight, name="move ee") # connect all elementary behaviors to the task node # BehOrg.connect_to_task(task_node, move_ee) time_steps = 1000 task_node_activation = [0] * time_steps motor_node_x_activation = [0] * time_steps motor_node_y_activation = [0] * time_steps move_ee_intention_node_activation = [0] * time_steps move_ee_cos_node_activation = [0] * time_steps move_ee_cos_memory_node_activation = [0] * time_steps move_ee_intention_field_activation = numpy.zeros( (time_steps, move_ee_field_sizes[0])) move_ee_cos_field_activation = numpy.zeros( (time_steps, move_ee_field_sizes[0])) for i in range(time_steps): # step all connectables and behaviors task_node.step() move_ee.step() # extract position of peak in the move ee intention field move_ee_int_field = move_ee.get_intention_field() move_ee_int_field_activation = move_ee_int_field.get_activation() if (i == 100): print "time to boost!" move_ee_boost = math_tools.gauss_2d( move_ee_int_field_activation.shape, amplitude=9.5, sigmas=[2.0, 2.0], shifts=[10, 0]) move_ee_int_field.set_boost(move_ee_boost) move_ee_int_field_activation_x = move_ee_int_field_activation.max(1) move_ee_int_field_activation_y = move_ee_int_field_activation.max(0) move_ee_int_field_output_x = move_ee_int_field.get_output().max(1) move_ee_int_field_output_y = move_ee_int_field.get_output().max(0) if (print_output): print "normalization x:" print move_ee_int_field_output_x.sum() print "normalization y:" print move_ee_int_field_output_y.sum() motor_node_x.set_normalization_factor(move_ee_int_field_output_x.sum()) motor_node_y.set_normalization_factor(move_ee_int_field_output_y.sum()) if (print_output): print "field x:" print move_ee_int_field_output_x print "field y:" print move_ee_int_field_output_y field_size_x = len(move_ee_int_field_output_x) field_size_y = len(move_ee_int_field_output_y) # ramp_x = numpy.linspace(-field_size_x/2., field_size_x/2., field_size_x) # ramp_y = numpy.linspace(-field_size_y/2., field_size_y/2., field_size_y) ramp_x = range(field_size_x) ramp_y = range(field_size_y) if (print_output): print "ramp x:" print ramp_x print "ramp y:" print ramp_y force_x = numpy.dot(move_ee_int_field_output_x, ramp_x) / 100. force_y = numpy.dot(move_ee_int_field_output_y, ramp_y) / -100. if (print_output): print "force x:" print force_x print "force y:" print force_y motor_node_x.set_boost(force_x) motor_node_y.set_boost(force_y) x_dot = motor_node_x.get_change()[0] y_dot = motor_node_y.get_change()[0] z_dot = 0.0 if (print_output): print "change x:" print x_dot print "change y:" print y_dot motor_node_x.step() motor_node_y.step() if (move_nao): motion_proxy.changePosition("RArm", 0, [x_dot, y_dot, z_dot, 0.0, 0.0, 0.0], 0.5, 7) time.sleep(0.03) if (print_output): print "motor node x activation:" print motor_node_x.get_activation()[0] print "motor node y activation:" print motor_node_y.get_activation()[0] # save task node activation task_node_activation[i] = task_node.get_activation()[0] # save motor node activation motor_node_x_activation[i] = motor_node_x.get_activation()[0] motor_node_y_activation[i] = motor_node_y.get_activation()[0] # save move end effector activations move_ee_intention_node_activation[i] = move_ee.get_intention_node( ).get_activation()[0] move_ee_cos_node_activation[i] = move_ee.get_cos_node().get_activation( )[0] move_ee_cos_memory_node_activation[i] = move_ee.get_cos_memory_node( ).get_activation()[0] move_ee_intention_field_activation[i] = move_ee.get_intention_field( ).get_activation().max(1) move_ee_cos_field_activation[i] = move_ee.get_cos_field( ).get_activation().max(1) if (print_output): print "done computing..." plot_settings.set_mode("icdl") ########################################################################## # create a figure for the "move ee" plots fig = plt.figure(1) fig.subplots_adjust(bottom=0.07, left=0.07, right=0.97, top=0.93) plt.axes([0.125, 0.2, 0.95 - 0.125, 0.95 - 0.2]) time_course_subplot = plt.subplot(2, 1, 1) time_course_subplot.axes.grid(color='grey', linestyle='dotted') plt.xlabel(r'time steps') plt.ylabel(r'activation') plt.plot(task_node_activation, 'y-', label=r'task') plt.plot(motor_node_x_activation, 'k-', label=r'motor x') plt.plot(motor_node_y_activation, 'k--', label=r'motor y') plt.plot(move_ee_intention_node_activation, 'r-', label=r'mee intention', antialiased=True) plt.plot(move_ee_cos_node_activation, 'b-', label=r'mee cos', antialiased=True) plt.plot(move_ee_cos_memory_node_activation, 'c-', label=r'mee cos mem', antialiased=True) plt.axis([0, 1000, -0.25, 0.25]) plt.legend(loc='upper right') grid = ImageGrid(fig, 212, nrows_ncols=(2, 1), axes_pad=0.1, aspect=False) grid[0].imshow(numpy.rollaxis(move_ee_intention_field_activation, 1), aspect="auto", vmin=-10, vmax=10) grid[0].invert_yaxis() grid[0].set_yticks(range(0, move_ee_field_sizes[0] + 10, 20)) grid[0].set_ylabel(r'mee int') grid[1].imshow(numpy.rollaxis(move_ee_cos_field_activation, 1), aspect="auto", vmin=-10, vmax=10) grid[1].invert_yaxis() grid[1].set_yticks(range(0, move_ee_field_sizes[0] + 10, 20)) grid[1].set_ylabel(r'mee cos') grid[1].set_xlabel(r'time steps') grid[1].set_xticks(range(0, time_steps + 100, 200)) plt.savefig("fig/move_ee.pdf", format="pdf")
date_sar = datetime.datetime(2012,05,10,20) #ebb else: #date_sar = datetime.datetime(2012,05,11,1,30) #flood date_sar = datetime.datetime(2012,05,11,2,30) #flood print '** > > plot date > ', date_sar #plot mask xm,ym,hm,um,vm,zm=read_nc_file(1,date_sar,surface_vel) maskplot=hm.mask maskpl=np.zeros(maskplot.shape) maskpl=np.ma.masked_array(maskpl,~maskplot) ################ figure setting stuff >>>>> ps.set_mode("m") fig_size1=ps.get_figsize(500) linewidth=0.2 #====== subplot adjustments =============== left1 = 0.15 # the left side of the subplots of the figure right1 = 0.95 # the right side of the subplots of the figure bottom1= 0.3 # the bottom of the subplots of the figure (ntr==16 bottom=0.05) top1 = 0.95 # the top of the subplots of the figure wspace1= 0.01 # the amount of width reserved for blank space between subplots hspace1= 0.01 # the amount of height reserved for white space between subplots ###############################################<<<<<< #subplot params icount=1 rrow=2
def main(): grasp_architecture = BehOrg.GraspArchitecture() time_steps = 300 task_node_activation = [0] * time_steps find_color_intention_node_activation = [0] * time_steps find_color_cos_node_activation = [0] * time_steps find_color_cos_memory_node_activation = [0] * time_steps find_color_intention_field_activation = numpy.zeros( (time_steps, grasp_architecture._find_color_field_size)) find_color_cos_field_activation = numpy.zeros( (time_steps, grasp_architecture._find_color_field_size)) move_ee_intention_node_activation = [0] * time_steps move_ee_cos_node_activation = [0] * time_steps move_ee_cos_memory_node_activation = [0] * time_steps move_ee_intention_field_activation = numpy.zeros( (time_steps, grasp_architecture._move_ee_field_sizes[0])) move_ee_cos_field_activation = numpy.zeros( (time_steps, grasp_architecture._move_ee_field_sizes[0])) gripper_open_intention_node_activation = [0] * time_steps gripper_open_cos_node_activation = [0] * time_steps gripper_open_cos_memory_node_activation = [0] * time_steps gripper_close_intention_node_activation = [0] * time_steps gripper_close_cos_node_activation = [0] * time_steps gripper_close_cos_memory_node_activation = [0] * time_steps gripper_intention_field_activation = numpy.zeros( (time_steps, grasp_architecture._gripper_field_size)) gripper_cos_field_activation = numpy.zeros( (time_steps, grasp_architecture._gripper_field_size)) gripper_open_precondition_node_activation = [0] * time_steps gripper_close_precondition_node_activation = [0] * time_steps color_space_field_x_activation = numpy.zeros( (time_steps, grasp_architecture._color_space_field_sizes[0])) color_space_field_y_activation = numpy.zeros( (time_steps, grasp_architecture._color_space_field_sizes[1])) color_space_field_hue_activation = numpy.zeros( (time_steps, grasp_architecture._color_space_field_sizes[2])) camera_field_x_activation = numpy.zeros( (time_steps, grasp_architecture._camera_field_sizes[0])) camera_field_y_activation = numpy.zeros( (time_steps, grasp_architecture._camera_field_sizes[1])) camera_field_hue_activation = numpy.zeros( (time_steps, grasp_architecture._camera_field_sizes[2])) spatial_target_field_x_activation = numpy.zeros( (time_steps, grasp_architecture._spatial_target_field_sizes[0])) spatial_target_field_y_activation = numpy.zeros( (time_steps, grasp_architecture._spatial_target_field_sizes[1])) perception_ee_field_x_activation = numpy.zeros( (time_steps, grasp_architecture._perception_ee_field_sizes[0])) gripper_boost = math_tools.gauss_1d( grasp_architecture._gripper_field_size, amplitude=10.0, sigma=0.5, shift=grasp_architecture._gripper_field_size - 5) grasp_architecture._gripper_open.get_cos_field().set_boost(gripper_boost) # perception_ee_boost = math_tools.gauss_2d(perception_ee_field_sizes, amplitude=8.0, sigmas=[2.0, 2.0], shifts=[20,5]) # perception_ee_field.set_boost(perception_ee_boost) for i in range(time_steps): print "time step: ", str(i) if (i == 400): perception_ee_boost = math_tools.gauss_2d( grasp_architecture._perception_ee_field_sizes, amplitude=8.0, sigmas=[0.5, 0.5], shifts=[5, 25]) grasp_architecture._perception_ee_field.set_boost( perception_ee_boost) # step all connectables and behaviors grasp_architecture.step() # save task node activation task_node_activation[i] = grasp_architecture._task_node.get_activation( )[0] # save find color activations find_color_intention_node_activation[ i] = grasp_architecture._find_color.get_intention_node( ).get_activation()[0] find_color_cos_node_activation[ i] = grasp_architecture._find_color.get_cos_node().get_activation( )[0] find_color_cos_memory_node_activation[ i] = grasp_architecture._find_color.get_cos_memory_node( ).get_activation()[0] find_color_intention_field_activation[ i] = grasp_architecture._find_color.get_intention_field( ).get_activation() find_color_cos_field_activation[ i] = grasp_architecture._find_color.get_cos_field().get_activation( ) # save move end effector activations move_ee_intention_node_activation[ i] = grasp_architecture._move_ee.get_intention_node( ).get_activation()[0] move_ee_cos_node_activation[ i] = grasp_architecture._move_ee.get_cos_node().get_activation()[0] move_ee_cos_memory_node_activation[ i] = grasp_architecture._move_ee.get_cos_memory_node( ).get_activation()[0] move_ee_intention_field_activation[ i] = grasp_architecture._move_ee.get_intention_field( ).get_activation().max(1) move_ee_cos_field_activation[ i] = grasp_architecture._move_ee.get_cos_field().get_activation( ).max(1) # save gripper open activations gripper_open_intention_node_activation[ i] = grasp_architecture._gripper_open.get_intention_node( ).get_activation()[0] gripper_open_cos_node_activation[ i] = grasp_architecture._gripper_open.get_cos_node( ).get_activation()[0] gripper_open_cos_memory_node_activation[ i] = grasp_architecture._gripper_open.get_cos_memory_node( ).get_activation()[0] # save gripper close activations gripper_close_intention_node_activation[ i] = grasp_architecture._gripper_close.get_intention_node( ).get_activation()[0] gripper_close_cos_node_activation[ i] = grasp_architecture._gripper_close.get_cos_node( ).get_activation()[0] gripper_close_cos_memory_node_activation[ i] = grasp_architecture._gripper_close.get_cos_memory_node( ).get_activation()[0] # save gripper field activations gripper_intention_field_activation[ i] = grasp_architecture._gripper_intention_field.get_activation() gripper_cos_field_activation[ i] = grasp_architecture._gripper_cos_field.get_activation() # save precondition activations gripper_open_precondition_node_activation[ i] = grasp_architecture._gripper_open_precondition_node.get_activation( )[0] gripper_close_precondition_node_activation[ i] = grasp_architecture._gripper_close_precondition_node.get_activation( )[0] # save color space field activations color_space_field_hue_x_activation = grasp_architecture._color_space_field.get_activation( ).max(1) color_space_field_hue_activation[ i] = color_space_field_hue_x_activation.max(0) color_space_field_x_activation[ i] = color_space_field_hue_x_activation.max(1) color_space_field_y_activation[ i] = grasp_architecture._color_space_field.get_activation().max( 0).max(1) # save camera field activations camera_field_hue_x_activation = grasp_architecture._camera_field.get_activation( ).max(1) camera_field_hue_activation[i] = camera_field_hue_x_activation.max(0) camera_field_x_activation[i] = camera_field_hue_x_activation.max(1) camera_field_y_activation[ i] = grasp_architecture._camera_field.get_activation().max(0).max( 1) # save spatial target activations spatial_target_field_x_activation[ i] = grasp_architecture._spatial_target_field.get_activation().max( 1) spatial_target_field_y_activation[ i] = grasp_architecture._spatial_target_field.get_activation().max( 0) # save perception end effector activations perception_ee_field_x_activation[ i] = grasp_architecture._perception_ee_field.get_activation().max( 1) plot_settings.set_mode("icdl") # create a figure for the "find color" plots fig = plt.figure(1) fig.subplots_adjust(bottom=0.07, left=0.07, right=0.97, top=0.93) plt.axes([0.125, 0.2, 0.95 - 0.125, 0.95 - 0.2]) time_course_subplot = plt.subplot(2, 1, 1) time_course_subplot.axes.grid(color='grey', linestyle='dotted') plt.xlabel(r'time steps') plt.ylabel(r'activation') plt.plot(task_node_activation, 'y-', label=r'task') plt.plot(find_color_intention_node_activation, 'r-', label=r'fc intention', antialiased=True) plt.plot(find_color_cos_node_activation, 'b-', label=r'fc cos', antialiased=True) plt.plot(find_color_cos_memory_node_activation, 'c-', label=r'fc cos mem', antialiased=True) plt.plot(gripper_open_precondition_node_activation, 'g-.', label=r'open precondition', antialiased=True) plt.plot(gripper_close_precondition_node_activation, 'm-.', label=r'close precondition', antialiased=True) plt.legend(loc='upper right') grid = ImageGrid(fig, 212, nrows_ncols=(2, 1), axes_pad=0.1, aspect=False) grid[0].imshow(numpy.rollaxis(find_color_intention_field_activation, 1), aspect="auto", vmin=-10, vmax=10) grid[0].invert_yaxis() grid[0].set_yticks( range(0, grasp_architecture._find_color_field_size + 10, 20)) grid[0].set_ylabel(r'fc int') grid[1].imshow(numpy.rollaxis(find_color_cos_field_activation, 1), aspect="auto", vmin=-10, vmax=10) grid[1].invert_yaxis() grid[1].set_yticks( range(0, grasp_architecture._find_color_field_size + 10, 20)) grid[1].set_ylabel(r'fc cos') grid[1].set_xlabel(r'time steps') grid[1].set_xticks(range(0, time_steps + 100, 200)) plt.savefig("fig/find_color.pdf", format="pdf") ########################################################################## # create a figure for the "move ee" plots fig = plt.figure(2) fig.subplots_adjust(bottom=0.07, left=0.07, right=0.97, top=0.93) plt.axes([0.125, 0.2, 0.95 - 0.125, 0.95 - 0.2]) time_course_subplot = plt.subplot(2, 1, 1) time_course_subplot.axes.grid(color='grey', linestyle='dotted') plt.xlabel(r'time steps') plt.ylabel(r'activation') plt.plot(move_ee_intention_node_activation, 'r-', label=r'mee intention', antialiased=True) plt.plot(move_ee_cos_node_activation, 'b-', label=r'mee cos', antialiased=True) plt.plot(move_ee_cos_memory_node_activation, 'c-', label=r'mee cos mem', antialiased=True) plt.legend(loc='upper right') grid = ImageGrid(fig, 212, nrows_ncols=(5, 1), axes_pad=0.1, aspect=False) grid[0].imshow(numpy.rollaxis(move_ee_intention_field_activation, 1), aspect="auto", vmin=-10, vmax=10) grid[0].invert_yaxis() grid[0].set_yticks( range(0, grasp_architecture._move_ee_field_sizes[0] + 10, 20)) grid[0].set_ylabel(r'mee int') grid[1].imshow(numpy.rollaxis(move_ee_cos_field_activation, 1), aspect="auto", vmin=-10, vmax=10) grid[1].invert_yaxis() grid[1].set_yticks( range(0, grasp_architecture._move_ee_field_sizes[0] + 10, 20)) grid[1].set_ylabel(r'mee cos') grid[2].imshow(numpy.rollaxis(spatial_target_field_x_activation, 1), aspect="auto", vmin=-10, vmax=10) grid[2].invert_yaxis() grid[2].set_yticks( range(0, grasp_architecture._spatial_target_field_sizes[0] + 10, 20)) grid[2].set_ylabel(r'st x') grid[3].imshow(numpy.rollaxis(spatial_target_field_y_activation, 1), aspect="auto", vmin=-10, vmax=10) grid[3].invert_yaxis() grid[3].set_yticks( range(0, grasp_architecture._spatial_target_field_sizes[1] + 10, 20)) grid[3].set_ylabel(r'st y') grid[4].imshow(numpy.rollaxis(perception_ee_field_x_activation, 1), aspect="auto", vmin=-10, vmax=10) grid[4].invert_yaxis() grid[4].set_yticks( range(0, grasp_architecture._perception_ee_field_sizes[0] + 10, 20)) grid[4].set_ylabel(r'pe x') grid[4].set_xlabel(r'time steps') grid[4].set_xticks(range(0, time_steps + 100, 200)) plt.savefig("fig/move_ee.pdf", format="pdf") ########################################################################## # create a figure for the "gripper" plots fig = plt.figure(3) fig.subplots_adjust(bottom=0.07, left=0.07, right=0.97, top=0.93) plt.axes([0.125, 0.2, 0.95 - 0.125, 0.95 - 0.2]) time_course_subplot = plt.subplot(2, 1, 1) time_course_subplot.axes.grid(color='grey', linestyle='dotted') plt.xlabel(r'time steps') plt.ylabel(r'activation') plt.plot(gripper_open_intention_node_activation, 'r-', label=r'go intention', antialiased=True) plt.plot(gripper_open_cos_node_activation, 'b-', label=r'go cos', antialiased=True) plt.plot(gripper_open_cos_memory_node_activation, 'c-', label=r'go cos mem', antialiased=True) plt.plot(gripper_close_intention_node_activation, 'r--', label=r'gc intention', antialiased=True) plt.plot(gripper_close_cos_node_activation, 'b--', label=r'gc cos', antialiased=True) plt.plot(gripper_close_cos_memory_node_activation, 'c--', label=r'gc cos mem', antialiased=True) plt.legend(loc='upper right') grid = ImageGrid(fig, 212, nrows_ncols=(2, 1), axes_pad=0.1, aspect=False) grid[0].imshow(numpy.rollaxis(gripper_intention_field_activation, 1), aspect="auto", vmin=-10, vmax=10) grid[0].invert_yaxis() grid[0].set_yticks( range(0, grasp_architecture._gripper_field_size + 10, 20)) grid[0].set_ylabel(r'go int') grid[1].imshow(numpy.rollaxis(gripper_cos_field_activation, 1), aspect="auto", vmin=-10, vmax=10) grid[1].invert_yaxis() grid[1].set_yticks( range(0, grasp_architecture._gripper_field_size + 10, 20)) grid[1].set_ylabel(r'go cos') grid[1].set_xlabel(r'time steps') grid[1].set_xticks(range(0, time_steps + 100, 200)) plt.savefig("fig/gripper.pdf", format="pdf") ########################################################################## # create a figure for the color space field plots fig = plt.figure(4) fig.subplots_adjust(bottom=0.07, left=0.07, right=0.97, top=0.93) plt.axes([0.125, 0.2, 0.95 - 0.125, 0.95 - 0.2]) time_course_subplot = plt.subplot(2, 1, 1) time_course_subplot.axes.grid(color='grey', linestyle='dotted') plt.plot(find_color_intention_node_activation, 'r-', label=r'fc intention', antialiased=True) plt.xlabel(r'time steps') plt.ylabel(r'activation') plt.legend(loc='upper right') grid = ImageGrid(fig, 212, nrows_ncols=(3, 1), axes_pad=0.1, aspect=False) grid[0].imshow(numpy.rollaxis(color_space_field_x_activation, 1), aspect="auto", vmin=-10, vmax=10) grid[0].invert_yaxis() grid[0].set_yticks( range(0, grasp_architecture._color_space_field_sizes[0] + 10, 20)) grid[0].set_ylabel(r'cs x') grid[1].imshow(numpy.rollaxis(color_space_field_y_activation, 1), aspect="auto", vmin=-10, vmax=10) grid[1].invert_yaxis() grid[1].set_yticks( range(0, grasp_architecture._color_space_field_sizes[1] + 10, 20)) grid[1].set_ylabel(r'cs y') grid[2].imshow(numpy.rollaxis(color_space_field_hue_activation, 1), aspect="auto", vmin=-10, vmax=10) grid[2].invert_yaxis() grid[2].set_yticks( range(0, grasp_architecture._color_space_field_sizes[2] + 10, 20)) grid[2].set_ylabel(r'cs hue') grid[2].set_xlabel(r'time steps') grid[2].set_xticks(range(0, time_steps + 100, 200)) plt.savefig("fig/color_space.pdf", format="pdf") ########################################################################## # create a figure for the camera field plots fig = plt.figure(5) fig.subplots_adjust(bottom=0.07, left=0.07, right=0.97, top=0.93) plt.axes([0.125, 0.2, 0.95 - 0.125, 0.95 - 0.2]) time_course_subplot = plt.subplot(2, 1, 1) time_course_subplot.axes.grid(color='grey', linestyle='dotted') plt.plot(find_color_intention_node_activation, 'r-', label=r'fc intention', antialiased=True) plt.xlabel(r'time steps') plt.ylabel(r'activation') plt.legend(loc='upper right') grid = ImageGrid(fig, 212, nrows_ncols=(3, 1), axes_pad=0.1, aspect=False) grid[0].imshow(numpy.rollaxis(camera_field_x_activation, 1), aspect="auto", vmin=-10, vmax=10) grid[0].invert_yaxis() grid[0].set_yticks( range(0, grasp_architecture._camera_field_sizes[0] + 10, 20)) grid[0].set_ylabel(r'cam x') grid[1].imshow(numpy.rollaxis(camera_field_y_activation, 1), aspect="auto", vmin=-10, vmax=10) grid[1].invert_yaxis() grid[1].set_yticks( range(0, grasp_architecture._camera_field_sizes[1] + 10, 20)) grid[1].set_ylabel(r'cam y') grid[2].imshow(numpy.rollaxis(camera_field_hue_activation, 1), aspect="auto", vmin=-10, vmax=10) grid[2].invert_yaxis() grid[2].set_yticks( range(0, grasp_architecture._camera_field_sizes[2] + 10, 20)) grid[2].set_ylabel(r'cam hue') grid[2].set_xlabel(r'time steps') grid[2].set_xticks(range(0, time_steps + 100, 200)) plt.savefig("fig/camera.pdf", format="pdf") plt.show()
def plot_cost_case1(): ps.set_mode("tiny") labels = ['DCSM', 'SMT', 'K-mean'] markerstyle = ['>', 'o', '+', '+', 's', 'd', '^', '<', '>', '+', '*', 'x'] fig = plt.gcf() N = len(dmp.numberof_CT_dcsm) ind = np.arange(20,60, step=5) # the x locations for the groups width = 0.25 # the width of the bars: can also be len(x) sequence data = [dmp.numberof_CT_dcsm, dmp.numberof_CT_SMT, dmp.numberof_CT_Shortestpath] numb_of_line=3 for line in range(numb_of_line): plt.plot(data[line], color=new_colors[line], ls=linestyles[line], marker=markers[line], markersize=4, label=labels[line], markevery=1) plt.ylabel('\# controllers') plt.xlabel('\# service chains') plt.xticks(np.arange(0,40, step=5),np.arange(20,60, step=5)) plt.ylim([2,8.5]) plt.legend( ('DCSM','SMT','K-mean'),loc=1,ncol=3) plt.show() filename="plot_num_CT_case1" fig.tight_layout() name = filename + '.pdf' fig.savefig(name) # ps.set_mode("tiny") # fig = plt.gcf() # N = len(dmp.numberof_CT_dcsm) # ind = np.arange(N) # the x locations for the groups # width = 0.25 # the width of the bars: can also be len(x) sequence # p1 = plt.bar(ind, np.array(dmp.Energy_cost_dcsm), width, color=new_colors[0], align='center') # p2 = plt.bar(ind + width, np.array(dmp.Energy_cost_shortest), width, color=new_colors[1], align='center') # p3 = plt.bar(ind + 2 * width, np.array(dmp.Energy_cost_smt), width, color=new_colors[2], align='center') # # plt.ylabel('Energy cost') # plt.xticks(ind + width - 0.15, dmp.numberof_SC) # # plt.yticks(np.arange(0, 81, 10)) # plt.legend((p1[0], p2[0], p3[0]), ('DCSM', 'Shortest', 'SMT'), loc=2, ncol=1) ps.set_mode("tiny") labels = ['DCSM', 'SMT', 'K-mean'] fig=plt.gcf() numb_of_line=3 data=np.array([dmp.Energy_cost_dcsm,dmp.Energy_cost_smt,dmp.Energy_cost_shortest])*.14 for line in range(numb_of_line): plt.plot(data[line], color=new_colors[line],ls='-',marker = markers[line], markersize=0, label=labels[line],markevery=1) plt.xlabel('\# service chains') plt.xticks(ind + width - 0.15, dmp.numberof_SC) plt.ylabel('Energy cost') plt.xticks(np.arange(0, len(dmp.Energy_cost_dcsm), step=5), np.arange(20, 60, step=5)) plt.xlabel('\# service chains') plt.legend( ('DCSM', 'SMT', 'K-mean'), loc=4, ncol=1) plt.xlim([0, 40]) plt.show() filename = "plot_cost_case1" fig.tight_layout() name = filename + '.pdf' fig.savefig(name) ps.set_mode("tiny") fig, ax = plt.subplots() width = 0.3 numberofsite=3 patterns = ["|||", "\\", "///", "...", "---", "xxx", "+++", "o", "O", "*"] name = ['DCSM', 'SMT', 'K-mean'] index = np.arange(7) # for i in range(numberofsite): i = 0 data=[[.67,.7,.7,.61,.6,.62,.72],[.85,.6,.85,.6,.78,.82,.83],[.89,.89,.5,.6,.5,.87,.87]] for i in range(3): ax.bar(index + width * i, data[i], width=width, alpha=0.4, color=new_colors[i], edgecolor='black') # ax.set_ylim([10., 350]) ax.legend(name,loc=1,ncol=3) ax.set_ylim([.4,1]) ax.set_ylabel("Utilization") ax.set_xlabel("Controller") plt.xticks(index + width, ([1,2,3,4,5,6,7])) fig.tight_layout() plt.savefig('plot_utilization.pdf') plt.show()
def main(): task_node = DynamicField.DynamicField([], [], None) field_sizes = [80, 80] int_weight_0 = math_tools.gauss_2d(field_sizes, amplitude=10, sigmas=[5.0, 5.0], shifts=[20, 20]) int_weight_1 = math_tools.gauss_2d(field_sizes, amplitude=10, sigmas=[5.0, 5.0], shifts=[40, 50]) elem_behavior_0 = BehOrg.ElementaryBehavior.with_internal_fields( field_dimensionality=2, field_sizes=[[field_sizes[0]], [field_sizes[1]]], field_resolutions=[], int_node_to_int_field_weight=int_weight_0, int_node_to_cos_node_weight=2.0, int_field_to_cos_field_weight=3.5, cos_field_to_cos_node_weight=3.0, cos_node_to_cos_memory_node_weight=2.5, int_inhibition_weight=-6.0, reactivating=False, name="eb0") elem_behavior_1 = BehOrg.ElementaryBehavior.with_internal_fields( field_dimensionality=2, field_sizes=[[field_sizes[0]], [field_sizes[1]]], field_resolutions=[], int_node_to_int_field_weight=int_weight_1, int_node_to_cos_node_weight=2.0, int_field_to_cos_field_weight=3.5, cos_field_to_cos_node_weight=3.0, cos_node_to_cos_memory_node_weight=2.5, int_inhibition_weight=-6.0, reactivating=False, name="eb1") BehOrg.connect_to_task(task_node, elem_behavior_0) BehOrg.connect_to_task(task_node, elem_behavior_1) competition_nodes = BehOrg.competition(elem_behavior_0, elem_behavior_1, task_node, bidirectional=True) time_steps = 1000 task_node_activation = [0] * time_steps eb0_intention_node_activation = [0] * time_steps eb0_intention_field_activation = [0] * time_steps eb0_cos_node_activation = [0] * time_steps eb0_cos_field_activation = [0] * time_steps eb0_cos_memory_node_activation = [0] * time_steps eb0_intention_field_activation_1d = numpy.zeros( (time_steps, field_sizes[1])) eb0_cos_field_activation = [0] * time_steps eb0_cos_field_activation_1d = numpy.zeros((time_steps, field_sizes[1])) competition_node_01_activation = [0] * time_steps eb1_intention_node_activation = [0] * time_steps eb1_intention_field_activation = [0] * time_steps eb1_cos_node_activation = [0] * time_steps eb1_cos_field_activation = [0] * time_steps eb1_cos_memory_node_activation = [0] * time_steps eb1_intention_field_activation_1d = numpy.zeros( (time_steps, field_sizes[1])) eb1_cos_field_activation = [0] * time_steps eb1_cos_field_activation_1d = numpy.zeros((time_steps, field_sizes[1])) competition_node_10_activation = [0] * time_steps print_output = False for i in range(time_steps): if (i > 1): task_node.set_boost(10) if (i > 200): elem_behavior_0.get_cos_field().set_boost(2.5) if (i > 350): elem_behavior_0.get_cos_field().set_boost(0.0) if (i > 550): elem_behavior_1.get_cos_field().set_boost(2.5) if (i > 650): elem_behavior_1.get_cos_field().set_boost(0.0) task_node.step() elem_behavior_0.step() competition_nodes[0].step() competition_nodes[1].step() elem_behavior_1.step() if (print_output is True): print("task node activation (boost: " + str(task_node.get_boost()) + ")") task_node_activation[i] = task_node.get_activation()[0] if (print_output is True): print(task_node_activation[i]) if (print_output is True): print("int node activation") eb0_intention_node_activation[i] = elem_behavior_0.get_intention_node( ).get_activation()[0] if (print_output is True): print(eb0_intention_node_activation[i]) if (print_output is True): print("int field activation") eb0_intention_field_activation[ i] = elem_behavior_0.get_intention_field().get_activation() if (print_output is True): print(eb0_intention_field_activation[i]) if (print_output is True): print("int field activation 1d") eb0_intention_field_activation_1d[i] = eb0_intention_field_activation[ i].max(0) if (print_output is True): print(eb0_intention_field_activation_1d) if (print_output is True): print("cos field activation (boost: " + str(elem_behavior_0.get_cos_field().get_boost()) + ")") eb0_cos_field_activation[i] = elem_behavior_0.get_cos_field( ).get_activation() if (print_output is True): print(eb0_cos_field_activation[i]) if (print_output is True): print("cos field activation 1d: ") eb0_cos_field_activation_1d[i] = eb0_cos_field_activation[i].max(0) if (print_output is True): print(eb0_cos_field_activation_1d) if (print_output is True): print("cos node activation") eb0_cos_node_activation[i] = elem_behavior_0.get_cos_node( ).get_activation()[0] if (print_output is True): print(eb0_cos_node_activation[i]) print("cos mem node activation") eb0_cos_memory_node_activation[ i] = elem_behavior_0.get_cos_memory_node().get_activation()[0] if (print_output is True): print(eb0_cos_memory_node_activation[i]) print("") print("competition node 01 activation") competition_node_01_activation[i] = competition_nodes[ 0].get_activation()[0] if (print_output is True): print(competition_node_01_activation[i]) print("competition node 10 activation") competition_node_10_activation[i] = competition_nodes[ 1].get_activation()[0] if (print_output is True): print(competition_nodes[1].get_activation()) print("") print("int node activation 1") eb1_intention_node_activation[i] = elem_behavior_1.get_intention_node( ).get_activation()[0] if (print_output is True): print(elem_behavior_1.get_intention_node().get_activation()) print("int field activation 1") eb1_intention_field_activation[ i] = elem_behavior_1.get_intention_field().get_activation() if (print_output is True): print(elem_behavior_1.get_intention_field().get_activation()) print("int field activation 1 1d") eb1_intention_field_activation_1d[i] = eb1_intention_field_activation[ i].max(0) if (print_output is True): print(eb0_intention_field_activation_1d) if (print_output is True): print("cos field activation 1 (boost: " + str(elem_behavior_1.get_cos_field().get_boost()) + ")") eb1_cos_field_activation[i] = elem_behavior_1.get_cos_field( ).get_activation() if (print_output is True): print(elem_behavior_1.get_cos_field().get_activation()) eb1_cos_field_activation_1d[i] = eb1_cos_field_activation[i].max(0) if (print_output is True): print(eb1_cos_field_activation_1d) if (print_output is True): print("cos node activation 1") eb1_cos_node_activation[i] = elem_behavior_1.get_cos_node( ).get_activation()[0] if (print_output is True): print(elem_behavior_1.get_cos_node().get_activation()) print("cos mem node activation 1") eb1_cos_memory_node_activation[ i] = elem_behavior_1.get_cos_memory_node().get_activation()[0] if (print_output is True): print(elem_behavior_1.get_cos_memory_node().get_activation()) print("\n----------------------------------------------------\n") plot_settings.set_mode("icdl") fig = plt.figure(1) fig.subplots_adjust(bottom=0.07, left=0.07, right=0.97, top=0.93) plt.axes([0.125, 0.2, 0.95 - 0.125, 0.95 - 0.2]) time_course_subplot = plt.subplot(2, 1, 1) time_course_subplot.axes.grid(color='grey', linestyle='dotted') plt.xlabel(r'time steps') plt.ylabel(r'activation') plt.plot(task_node_activation, 'k-', label=r'task') plt.plot(eb0_intention_node_activation, 'r-', label=r'EB0 intention', antialiased=True) plt.plot(eb0_cos_node_activation, 'r--', label=r'EB0 CoS', antialiased=True) plt.plot(eb0_cos_memory_node_activation, 'r:', label=r'EB0 CoS mem', antialiased=True) plt.plot(eb1_intention_node_activation, 'b-', label=r'EB1 intention', antialiased=True) plt.plot(eb1_cos_node_activation, 'b--', label=r'EB1 CoS', antialiased=True) plt.plot(eb1_cos_memory_node_activation, 'b:', label=r'EB1 CoS mem', antialiased=True) plt.plot(competition_node_01_activation, 'g-.', label=r'competition 01', antialiased=True) plt.plot(competition_node_10_activation, 'c-.', label=r'competition 10', antialiased=True) plt.legend(loc='upper right') plt.annotate('CoS EB0', xy=(200, -2), xytext=(110, -10), arrowprops=dict( arrowstyle="->", connectionstyle="angle,angleA=0,angleB=90,rad=10")) plt.annotate('CoS EB1', xy=(550, -2), xytext=(460, -10), arrowprops=dict( arrowstyle="->", connectionstyle="angle,angleA=0,angleB=90,rad=10")) grid = ImageGrid(fig, 212, nrows_ncols=(4, 1), axes_pad=0.1, aspect=False) grid[0].imshow(numpy.rollaxis(eb0_intention_field_activation_1d, 1), label='eb0 int field', aspect="auto", vmin=-10, vmax=10) grid[0].invert_yaxis() grid[0].set_yticks(range(0, field_sizes[0] + 10, 20)) grid[0].set_ylabel(r'EB0 int') grid[1].imshow(numpy.rollaxis(eb0_cos_field_activation_1d, 1), label='eb0 CoS field', aspect="auto", vmin=-10, vmax=10) grid[1].invert_yaxis() grid[1].set_yticks(range(0, field_sizes[0] + 10, 20)) grid[1].set_ylabel(r'EB0 CoS') grid[2].imshow(numpy.rollaxis(eb1_intention_field_activation_1d, 1), label='eb1 int field', aspect="auto", vmin=-10, vmax=10) grid[2].invert_yaxis() grid[2].set_yticks(range(0, field_sizes[0] + 10, 20)) grid[2].set_ylabel(r'EB1 int') grid[3].imshow(numpy.rollaxis(eb1_cos_field_activation_1d, 1), label='eb1 CoS field', aspect="auto", vmin=-10, vmax=10) grid[3].invert_yaxis() grid[3].set_yticks(range(0, field_sizes[0] + 10, 20)) grid[3].set_ylabel(r'EB1 CoS') grid[3].set_xlabel(r'time steps') grid[3].set_xticks(range(0, time_steps + 100, 200)) plt.savefig("competition_plot.pdf", format="pdf") plt.show()