include("aux_func.jl") using PlotlyJS: savefig using Statistics using PlotlyJS using Random #= Obtain energy data =# #mni_folder_1 = "ini_exp_data/" mni_folder_100 = "exp_100_epochs/"; cif_folder_100 = "CIFAR_100_epoch/"; mni_folder_acc = "data_bounded/"; cif_folder_acc = "CIFAR_acc_bound/"; mni_folder_wat = "data_budget/"; cif_folder_wat = "CIFAR_energy_bound/"; mni_folder_est = "early_stop_res/"; cif_folder_est = "CIFAR_early_stop/"; bayes_model = "bayes"; freq_model = "freq"; w_type = "watt"; e_type = "exp"; #= Load GPU data =# mni_100_bay_ene = getgpudata(mni_folder_100, bayes_model, w_type, "eo"); mni_100_fre_ene = getgpudata(mni_folder_100, freq_model, w_type, "eo"); cif_100_bay_ene = getgpudata(cif_folder_100, bayes_model, w_type, "eo"); cif_100_fre_ene = getgpudata(cif_folder_100, freq_model, w_type, "eo"); #= Define CPU paths =# cif = "cifar"; mni = "mnist"; bay = "bayes"; wat = "cpu_watts"; frq = "freq"; ram = "ram_use"; _100 = "100"; acc = "acc"; es = "es"; wbud = "wbud"; #= Load CPU data =# bay_cif_100_ene = readcpudata(cif, bay, wat, _100); bay_mni_100_ene = readcpudata(mni, bay, wat, _100); frq_cif_100_ene = readcpudata(cif, frq, wat, _100); frq_mni_100_ene = readcpudata(mni, frq, wat, _100); for s = 1:5 bay_cif_100_ene[s] = round.(getcpuwatt(bay_cif_100_ene[s])) bay_mni_100_ene[s] = round.(getcpuwatt(bay_mni_100_ene[s])) frq_cif_100_ene[s] = round.(getcpuwatt(frq_cif_100_ene[s])) frq_mni_100_ene[s] = round.(getcpuwatt(frq_mni_100_ene[s])) end for s = 1:5 mni_100_bay_ene[s]["Ene"] = vcat(mni_100_bay_ene[s]["Ene"], bay_mni_100_ene[s]) mni_100_fre_ene[s]["Ene"] = vcat(mni_100_fre_ene[s]["Ene"], frq_mni_100_ene[s]) cif_100_bay_ene[s]["Ene"] = vcat(cif_100_bay_ene[s]["Ene"], bay_cif_100_ene[s]) cif_100_fre_ene[s]["Ene"] = vcat(cif_100_fre_ene[s]["Ene"], frq_cif_100_ene[s]) end ene_data = Dict("mni" => Dict("bay" => Dict(1 => [],2 => [],3 => [],4 => [],5 => []), "fre" => Dict(1 => [],2 => [],3 => [],4 => [],5 => [])), "cif" => Dict("bay" => Dict(1 => [],2 => [],3 => [],4 => [],5 => []), "fre" => Dict(1 => [],2 => [],3 => [],4 => [],5 => []))) #ene_data = Dict("mni" => Dict("bay" => Dict(1 => 0.0,2 => 0.0,3 => 0.0,4 => 0.0,5 => 0.0), # "fre" => Dict(1 => 0.0,2 => 0.0,3 => 0.0,4 => 0.0,5 => 0.0)), # "cif" => Dict("bay" => Dict(1 => 0.0,2 => 0.0,3 => 0.0,4 => 0.0,5 => 0.0), # "fre" => Dict(1 => 0.0,2 => 0.0,3 => 0.0,4 => 0.0,5 => 0.0))) for s = 1:5 ene_data["mni"]["bay"][s] = sum.(join_vectors(resize1(makechunks(shuffle(mni_100_bay_ene[s]["Ene"]), 100)))) ene_data["mni"]["fre"][s] = sum.(join_vectors(resize1(makechunks(shuffle(mni_100_fre_ene[s]["Ene"]), 100)))) ene_data["cif"]["bay"][s] = sum.(join_vectors(resize1(makechunks(shuffle(cif_100_bay_ene[s]["Ene"]), 100)))) ene_data["cif"]["fre"][s] = sum.(join_vectors(resize1(makechunks(shuffle(cif_100_fre_ene[s]["Ene"]), 100)))) end #for s = 1:5 # ene_data["mni"]["bay"][s] = sum(mni_100_bay_ene[s]["Ene"]) / 100 # ene_data["mni"]["fre"][s] = sum(mni_100_fre_ene[s]["Ene"]) / 100 # ene_data["cif"]["bay"][s] = sum(cif_100_bay_ene[s]["Ene"]) / 100 # ene_data["cif"]["fre"][s] = sum(cif_100_fre_ene[s]["Ene"]) / 100 #end #= Load Accuracy data =# mni_100_bay_exp = getgpudata(mni_folder_100, bayes_model, e_type, "eo"); mni_100_fre_exp = getgpudata(mni_folder_100, freq_model, e_type, "eo"); cif_100_bay_exp = getgpudata(cif_folder_100, bayes_model, e_type, "eo"); cif_100_fre_exp = getgpudata(cif_folder_100, freq_model, e_type, "eo"); for i = 1:5 mni_100_bay_exp[i] = expdatatodict(mni_100_bay_exp[i]) mni_100_fre_exp[i] = expdatatodict(mni_100_fre_exp[i]) cif_100_bay_exp[i] = expdatatodict(cif_100_bay_exp[i]) cif_100_fre_exp[i] = expdatatodict(cif_100_fre_exp[i]) end original_vectors = Dict("LeNet" => Dict("MNIST" => Dict(1 => [],2 => [],3 => [],4 => [],5 => []), "CIFAR" => Dict(1 => [],2 => [],3 => [],4 => [],5 => [])), "BCNN" => Dict("MNIST" => Dict(1 => [],2 => [],3 => [],4 => [],5 => []), "CIFAR" => Dict(1 => [],2 => [],3 => [],4 => [],5 => []))) #= delta_vectors = Dict("LeNet" => Dict("MNIST" => Dict(1 => [],2 => [],3 => [],4 => [],5 => []), "CIFAR" => Dict(1 => [],2 => [],3 => [],4 => [],5 => [])), "BCNN" => Dict("MNIST" => Dict(1 => [],2 => [],3 => [],4 => [],5 => []), "CIFAR" => Dict(1 => [],2 => [],3 => [],4 => [],5 => []))) delta2_vectors = Dict("LeNet" => Dict("MNIST" => Dict(1 => [],2 => [],3 => [],4 => [],5 => []), "CIFAR" => Dict(1 => [],2 => [],3 => [],4 => [],5 => [])), "BCNN" => Dict("MNIST" => Dict(1 => [],2 => [],3 => [],4 => [],5 => []), "CIFAR" => Dict(1 => [],2 => [],3 => [],4 => [],5 => []))) =# delta_values = Dict("LeNet" => Dict("MNIST" => Dict(1 => 0.0,2 => 0.0,3 => 0.0,4 => 0.0,5 => 0.0), "CIFAR" => Dict(1 => 0.0,2 => 0.0,3 => 0.0,4 => 0.0,5 => 0.0)), "BCNN" => Dict("MNIST" => Dict(1 => 0.0,2 => 0.0,3 => 0.0,4 => 0.0,5 => 0.0), "CIFAR" => Dict(1 => 0.0,2 => 0.0,3 => 0.0,4 => 0.0,5 => 0.0))) for i in 1:5 original_vectors["LeNet"]["MNIST"][i] = (mni_100_fre_exp[i]["acc"] ./ ene_data["mni"]["fre"][i]) * 100 original_vectors["BCNN"]["MNIST"][i] = (mni_100_bay_exp[i]["acc"] ./ ene_data["mni"]["bay"][i]) * 100 original_vectors["LeNet"]["CIFAR"][i] = (cif_100_fre_exp[i]["acc"] ./ ene_data["cif"]["fre"][i]) * 100 original_vectors["BCNN"]["CIFAR"][i] = (cif_100_bay_exp[i]["acc"] ./ ene_data["cif"]["bay"][i]) * 100 end for i in 1:5 delta_values["LeNet"]["MNIST"][i] = mean(approx_δ(original_vectors["LeNet"]["MNIST"][i])) delta_values["BCNN"]["MNIST"][i] = mean(approx_δ(original_vectors["BCNN"]["MNIST"][i])) delta_values["LeNet"]["CIFAR"][i] = mean(approx_δ(original_vectors["LeNet"]["CIFAR"][i])) delta_values["BCNN"]["CIFAR"][i] = mean(approx_δ(original_vectors["BCNN"]["CIFAR"][i])) end lenet_mnist = zeros(5) bcnn_mnist = zeros(5) lenet_cifar = zeros(5) bcnn_cifar = zeros(5) #= for i in 1:5 println("LeNet MNIST Size $(i): $(delta_values["LeNet"]["MNIST"][i])") println("BCNN MNIST Size $(i): $(delta_values["BCNN"]["MNIST"][i])") println("LeNet CIFAR Size $(i): $(delta_values["LeNet"]["CIFAR"][i])") println("BCNN CIFAR Size $(i): $(delta_values["BCNN"]["CIFAR"][i])") end =# for i in 1:5 lenet_mnist[i] = delta_values["LeNet"]["MNIST"][i] bcnn_mnist[i] = delta_values["BCNN"]["MNIST"][i] lenet_cifar[i] = delta_values["LeNet"]["CIFAR"][i] bcnn_cifar[i] = delta_values["BCNN"]["CIFAR"][i] end println("MNIST LeNet Δ: $(mean(lenet_mnist))") println("MNIST BCNN Δ: $(mean(bcnn_mnist))") println("CIFAR LeNet Δ: $(mean(lenet_cifar))") println("CIFAR BCNN Δ: $(mean(bcnn_cifar))") #= en_plot = plot( [ scatter( #x = ["1", "2", "3", "4", "5"], y = delta_vectors["LeNet"]["MNIST"][1], name = "LeNet 1 MNIST", marker = attr(symbol = 4, color = "rgb(211,120,000)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = delta_vectors["LeNet"]["MNIST"][2], name = "LeNet 2 MNIST", marker = attr(symbol = 17, color = "rgb(255,170,017)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = delta_vectors["LeNet"]["MNIST"][3], name = "LeNet 3 MNIST", marker = attr(symbol = 2, color = "rgb(255,187,034)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = delta_vectors["LeNet"]["MNIST"][4], name = "LeNet 4 MNIST", marker = attr(symbol = 0, color = "rgb(255,204,051)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = delta_vectors["LeNet"]["MNIST"][5], name = "LeNet 5 MNIST", marker = attr(symbol = 4, color = "rgb(255,195,001)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = delta_vectors["LeNet"]["CIFAR"][1], name = "LeNet 1 CIFAR", marker = attr(symbol = 4, color = "rgb(055,033,240)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = delta_vectors["LeNet"]["CIFAR"][2], name = "LeNet 2 CIFAR", marker = attr(symbol = 4, color = "rgb(018,094,219)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = delta_vectors["LeNet"]["CIFAR"][3], name = "LeNet 3 CIFAR", marker = attr(symbol = 4, color = "rgb(018,126,219)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = delta_vectors["LeNet"]["CIFAR"][4], name = "LeNet 4 CIFAR", marker = attr(symbol = 4, color = "rgb(018,150,219)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = delta_vectors["LeNet"]["CIFAR"][5], name = "LeNet 5 CIFAR", marker = attr(symbol = 4, color = "rgb(018,167,219)", line_width = 1.0), ), ], Layout( mode = "overlay", xaxis_tickangle = -45, yaxis_title_text = "ΔEfficency", xaxis_title_text = "Epoch"; opacity = 0.9, xaxis_range = [0, 20], #xaxis_range = [-1, 5], #xaxis_type = "category", ), ) savefig(en_plot, "lenet_dE_epoch.png") en_plot = plot( [ scatter( #x = ["1", "2", "3", "4", "5"], y = delta_vectors["BCNN"]["MNIST"][1], name = "BCNN 1 MNIST", marker = attr(symbol = 4, color = "rgb(211,120,000)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = delta_vectors["BCNN"]["MNIST"][2], name = "BCNN 2 MNIST", marker = attr(symbol = 17, color = "rgb(255,170,017)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = delta_vectors["BCNN"]["MNIST"][3], name = "BCNN 3 MNIST", marker = attr(symbol = 2, color = "rgb(255,187,034)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = delta_vectors["BCNN"]["MNIST"][4], name = "BCNN 4 MNIST", marker = attr(symbol = 0, color = "rgb(255,204,051)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = delta_vectors["BCNN"]["MNIST"][5], name = "BCNN 5 MNIST", marker = attr(symbol = 4, color = "rgb(255,195,001)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = delta_vectors["BCNN"]["CIFAR"][1], name = "BCNN 1 CIFAR", marker = attr(symbol = 4, color = "rgb(055,033,240)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = delta_vectors["BCNN"]["CIFAR"][2], name = "BCNN 2 CIFAR", marker = attr(symbol = 4, color = "rgb(018,094,219)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = delta_vectors["BCNN"]["CIFAR"][3], name = "BCNN 3 CIFAR", marker = attr(symbol = 4, color = "rgb(018,126,219)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = delta_vectors["BCNN"]["CIFAR"][4], name = "BCNN 4 CIFAR", marker = attr(symbol = 4, color = "rgb(018,150,219)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = delta_vectors["BCNN"]["CIFAR"][5], name = "BCNN 5 CIFAR", marker = attr(symbol = 4, color = "rgb(018,167,219)", line_width = 1.0), ), ], Layout( mode = "overlay", xaxis_tickangle = -45, yaxis_title_text = "ΔEfficency", xaxis_title_text = "Epoch"; opacity = 0.9, xaxis_range = [0, 20], #xaxis_range = [-1, 5], #xaxis_type = "category", ), ) savefig(en_plot, "bcnn_dE_epoch.png") en_plot = plot( [ scatter( #x = ["1", "2", "3", "4", "5"], y = delta2_vectors["LeNet"]["MNIST"][1], name = "LeNet 1 MNIST", marker = attr(symbol = 4, color = "rgb(211,120,000)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = delta2_vectors["LeNet"]["MNIST"][2], name = "LeNet 2 MNIST", marker = attr(symbol = 17, color = "rgb(255,170,017)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = delta2_vectors["LeNet"]["MNIST"][3], name = "LeNet 3 MNIST", marker = attr(symbol = 2, color = "rgb(255,187,034)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = delta2_vectors["LeNet"]["MNIST"][4], name = "LeNet 4 MNIST", marker = attr(symbol = 0, color = "rgb(255,204,051)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = delta2_vectors["LeNet"]["MNIST"][5], name = "LeNet 5 MNIST", marker = attr(symbol = 4, color = "rgb(255,195,001)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = delta2_vectors["LeNet"]["CIFAR"][1], name = "LeNet 1 CIFAR", marker = attr(symbol = 4, color = "rgb(055,033,240)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = delta2_vectors["LeNet"]["CIFAR"][2], name = "LeNet 2 CIFAR", marker = attr(symbol = 4, color = "rgb(018,094,219)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = delta2_vectors["LeNet"]["CIFAR"][3], name = "LeNet 3 CIFAR", marker = attr(symbol = 4, color = "rgb(018,126,219)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = delta2_vectors["LeNet"]["CIFAR"][4], name = "LeNet 4 CIFAR", marker = attr(symbol = 4, color = "rgb(018,150,219)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = delta2_vectors["LeNet"]["CIFAR"][5], name = "LeNet 5 CIFAR", marker = attr(symbol = 4, color = "rgb(018,167,219)", line_width = 1.0), ), ], Layout( mode = "overlay", xaxis_tickangle = -45, yaxis_title_text = "ΔΔEfficency", xaxis_title_text = "Epoch"; opacity = 0.9, xaxis_range = [0, 20], #xaxis_range = [-1, 5], #xaxis_type = "category", ), ) savefig(en_plot, "lenet_ddE_epoch.png") en_plot = plot( [ scatter( #x = ["1", "2", "3", "4", "5"], y = delta2_vectors["BCNN"]["MNIST"][1], name = "BCNN 1 MNIST", marker = attr(symbol = 4, color = "rgb(211,120,000)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = delta2_vectors["BCNN"]["MNIST"][2], name = "BCNN 2 MNIST", marker = attr(symbol = 17, color = "rgb(255,170,017)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = delta2_vectors["BCNN"]["MNIST"][3], name = "BCNN 3 MNIST", marker = attr(symbol = 2, color = "rgb(255,187,034)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = delta2_vectors["BCNN"]["MNIST"][4], name = "BCNN 4 MNIST", marker = attr(symbol = 0, color = "rgb(255,204,051)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = delta2_vectors["BCNN"]["MNIST"][5], name = "BCNN 5 MNIST", marker = attr(symbol = 4, color = "rgb(255,195,001)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = delta2_vectors["BCNN"]["CIFAR"][1], name = "BCNN 1 CIFAR", marker = attr(symbol = 4, color = "rgb(055,033,240)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = delta2_vectors["BCNN"]["CIFAR"][2], name = "BCNN 2 CIFAR", marker = attr(symbol = 4, color = "rgb(018,094,219)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = delta2_vectors["BCNN"]["CIFAR"][3], name = "BCNN 3 CIFAR", marker = attr(symbol = 4, color = "rgb(018,126,219)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = delta2_vectors["BCNN"]["CIFAR"][4], name = "BCNN 4 CIFAR", marker = attr(symbol = 4, color = "rgb(018,150,219)", line_width = 1.0), ), scatter( #x = ["1", "2", "3", "4", "5"], y = delta2_vectors["BCNN"]["CIFAR"][5], name = "BCNN 5 CIFAR", marker = attr(symbol = 4, color = "rgb(018,167,219)", line_width = 1.0), ), ], Layout( mode = "overlay", xaxis_tickangle = -45, yaxis_title_text = "ΔΔEfficency", xaxis_title_text = "Epoch"; opacity = 0.9, xaxis_range = [0, 20], #xaxis_range = [-1, 5], #xaxis_type = "category", ), ) savefig(en_plot, "bcnn_ddE_epoch.png") =#