Skip to content

Commit

Permalink
update plotting
Browse files Browse the repository at this point in the history
  • Loading branch information
nhatminh committed Jul 5, 2018
1 parent 5a90454 commit 6978a0d
Show file tree
Hide file tree
Showing 25 changed files with 157 additions and 28 deletions.
Binary file modified data.h5
Binary file not shown.
Binary file added figs/Scale_obj_E.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added figs/Scale_obj_T.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figs/Sub1_N.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figs/Sub1_T.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figs/Sub1_f.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figs/Sub2_Tau.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figs/Sub2_p.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figs/Sub3_eq.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified figs/Sub3_obj.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 14 additions & 11 deletions julia/Main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ end
function main()
#Generate data
dist_list, gain_list, ratios, D_n = mobile_gen()
# kaps = [5e-5, 8e-5, 1e-4, 3e-4, 5e-4, 7e-4, 1e-3, 3e-3, 5e-3, 7e-3, 1e-2, 3e-2, 5e-2, 7e-2, 1e-1, 0.3, 0.5, 0.7, 1.,3., 5., 7., 1e1, 5e1, 1e2]
kaps = [5e-5, 8e-5, 1e-4, 3e-4, 5e-4, 7e-4, 1e-3, 3e-3, 5e-3, 7e-3, 1e-2, 3e-2, 5e-2, 7e-2, 1e-1, 0.3, 0.5, 0.7, 1.,3., 5., 7., 1e1, 5e1, 7e1, 1e2]
Numb_kaps = size(kaps)[1]
T_cmp, T_cmp1 = zeros(Numb_kaps), zeros(Numb_kaps)
E_cmp, E_cmp1 = zeros(Numb_kaps), zeros(Numb_kaps)
Expand Down Expand Up @@ -66,14 +64,19 @@ function main()
end
end

plot_sub1_T(kaps, T_cmp, T_cmp1, Tcmp_N1, Tcmp_N2, Tcmp_N3)
plot_sub1_N(kaps, N1, N2, N3)
plot_sub1_f(kaps, f, f1)
plot_sub2_tau(kaps, tau, tau1)
plot_sub2_p(kaps, p, p1)
save_result(Theta1, Obj1, Obj_E, Obj_T, T_cmp1, E_cmp1, T_com1, E_com1, N1, N2, N3, f1, tau1, p1, d_eta)

plot_sub3_equation(kaps, d_eta)
plot_sub3_cvx(kaps, Theta, Theta1, Obj, Obj1, T_cmp1, E_cmp1, T_com1, E_com1)
plot_sub1_T(T_cmp, T_cmp1, Tcmp_N1, Tcmp_N2, Tcmp_N3)
plot_sub1_N(N1, N2, N3)

if(NumbDevs <=5)
plot_sub1_f(f, f1)
plot_sub2_tau(tau, tau1)
plot_sub2_p(p, p1)
end

plot_sub3_equation(d_eta)
plot_sub3_cvx(Theta, Theta1, Obj, Obj1, T_cmp1, E_cmp1, T_com1, E_com1)
end

function main1()
Expand Down Expand Up @@ -103,5 +106,5 @@ function main1()
end
end

main()
# main1()
# main()
plot_scale_result()
140 changes: 128 additions & 12 deletions julia/Plots_Figs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ markers = ["x","o",">","^", "."]

folder = string("figs//")

function plot_sub1_T(kaps, T_cmp, T_cmp1, Tcmp_N1, Tcmp_N2, Tcmp_N3)
function plot_sub1_T(T_cmp, T_cmp1, Tcmp_N1, Tcmp_N2, Tcmp_N3)
clf()
figure(1,figsize=fig_size)
# plot(kaps,T_cmp,color=colors[1],linestyle="-",linewidth=l_width,label="Solver")
Expand All @@ -35,9 +35,9 @@ function plot_sub1_T(kaps, T_cmp, T_cmp1, Tcmp_N1, Tcmp_N2, Tcmp_N3)
savefig(string(folder,"Sub1_T.png"))
end

function plot_sub1_N(kaps, N1, N2, N3)
function plot_sub1_N(N1, N2, N3)
clf()
figure(1,figsize=fig_size)
figure(2,figsize=fig_size)
# plot(kaps,T_cmp,color=colors[1],linestyle="-",linewidth=l_width,label="Solver")
plot(kaps,N1,color=colors[2],linestyle="--",linewidth=l_width,label="N1")
plot(kaps,N2,color=colors[4],linestyle="--",linewidth=l_width,label="N2")
Expand All @@ -51,9 +51,9 @@ function plot_sub1_N(kaps, N1, N2, N3)
savefig(string(folder,"Sub1_N.png"))
end

function plot_sub1_f(kaps, f, f1)
function plot_sub1_f(f, f1)
clf()
figure(2,figsize=fig_size)
figure(3,figsize=fig_size)
plot(kaps,f_min[1]*ones(size(kaps))*1e-9,linestyle=":",color=colors[6])

if (HETEROGENEOUS == 0) # Homogeneous
Expand All @@ -78,9 +78,9 @@ function plot_sub1_f(kaps, f, f1)
savefig(string(folder,"Sub1_f.png"))
end

function plot_sub2_tau(kaps, tau, tau1)
function plot_sub2_tau(tau, tau1)
clf()
figure(3,figsize=fig_size)
figure(4,figsize=fig_size)
for n = 1:NumbDevs
plot(kaps,tau1[:,n], color=colors[n], linestyle="-",linewidth=l_width,label=string("Dev ",n))
end
Expand All @@ -94,9 +94,9 @@ function plot_sub2_tau(kaps, tau, tau1)
savefig(string(folder,"Sub2_Tau.png"))
end

function plot_sub2_p(kaps, p, p1)
function plot_sub2_p(p, p1)
clf()
figure(4,figsize=fig_size)
figure(5,figsize=fig_size)
plot(kaps,Ptx_Max*ones(size(kaps)),linestyle=":",color=colors[6])
plot(kaps,Ptx_Min*ones(size(kaps)),linestyle=":",color=colors[6])
for n = 1:NumbDevs
Expand All @@ -112,9 +112,9 @@ function plot_sub2_p(kaps, p, p1)
savefig(string(folder,"Sub2_p.png"))
end

function plot_sub3_cvx(kaps, Theta, Theta1, Obj, Obj1, T_cmp1, E_cmp1, T_com1, E_com1)
function plot_sub3_cvx(Theta, Theta1, Obj, Obj1, T_cmp1, E_cmp1, T_com1, E_com1)
clf()
figure(5,figsize=fig_size)
figure(6,figsize=fig_size)
# plot(Theta,Obj,color=colors[1],linestyle="-",linewidth=l_width,label="Solver")
# plot(Theta1,Obj1,color=colors[2],linestyle=":",linewidth=l_width,label="Closed-Form")
#
Expand Down Expand Up @@ -151,7 +151,7 @@ function plot_sub3_cvx(kaps, Theta, Theta1, Obj, Obj1, T_cmp1, E_cmp1, T_com1, E
println("Theta: ", minimum(Theta1), " - ", maximum(Theta1))
end

function plot_sub3_equation(kaps, d_eta)
function plot_sub3_equation(d_eta)
Numb_kaps = size(kaps)[1]
clf()
x = collect(1.e-6:0.001:0.999)
Expand All @@ -175,3 +175,119 @@ function plot_sub3_equation(kaps, d_eta)
tight_layout(pad=0.5, w_pad=0.5, h_pad=0.5)
savefig(string(folder,"Sub3_eq.png"))
end

function plot_scale_result()
Numb_kaps = size(kaps)[1]
Sims = 5
Thetas = zeros(Sims, Numb_kaps)
Objs = zeros(Sims, Numb_kaps)
Objs_E = zeros(Sims, Numb_kaps)
Objs_T = zeros(Sims, Numb_kaps)

for i = 1:Sims
Thetas[i,:], Objs[i,:], Objs_E[i,:], Objs_T[i,:], T_cmp1, E_cmp1, T_com1, E_com1,
N1, N2, N3, f1, tau1, p1,
d_eta = read_result(string("result",Numb_devs[i],".h5"))
end

# clf()
# figure(8,figsize=fig_size)
# plot(Numb_devs, Objs[:,11],linestyle="--",color=colors[1],marker=markers[1], markersize=marker_size, label=string("Objective: \$\\kappa\$ =", kaps[11]))
# plot(Numb_devs, Objs[:,15],linestyle="--",color=colors[2],marker=markers[2], markersize=marker_size, label=string("Objective: \$\\kappa\$ =", kaps[15]))
# plot(Numb_devs, Objs[:,19],linestyle="--",color=colors[3],marker=markers[3], markersize=marker_size, label=string("Objective: \$\\kappa\$ =", kaps[19]))
# plot(Numb_devs, Objs[:,23],linestyle="--",color=colors[4],marker=markers[4], markersize=marker_size, label=string("Objective: \$\\kappa\$ =", kaps[23]))
#
# legend(loc="best",fontsize=legend_fontsize-2)
# xlabel("Number of Devs",fontsize=label_fontsize1+1)
# # ylabel("Objective",fontsize=label_fontsize1+1)
# # yscale("log")
# tight_layout(pad=0.5, w_pad=0.5, h_pad=0.5)
# savefig(string(folder,"Scale_obj.png"))
#
# clf()
# figure(9,figsize=fig_size)
# plot(Numb_devs, Thetas[:,11],linestyle="--",color=colors[1],marker=markers[1], markersize=marker_size, label=string("\$\\Theta\$: \$\\kappa\$ =", kaps[11]))
# plot(Numb_devs, Thetas[:,15],linestyle="--",color=colors[2],marker=markers[2], markersize=marker_size, label=string("\$\\Theta\$: \$\\kappa\$ =", kaps[15]))
# plot(Numb_devs, Thetas[:,19],linestyle="--",color=colors[3],marker=markers[3], markersize=marker_size, label=string("\$\\Theta\$: \$\\kappa\$ =", kaps[19]))
# plot(Numb_devs, Thetas[:,23],linestyle="--",color=colors[4],marker=markers[4], markersize=marker_size, label=string("\$\\Theta\$: \$\\kappa\$ =", kaps[23]))
# # plot(Numb_devs, Thetas[:,id],linestyle="-",color="k", label="\$\\Theta\$")
#
# legend(loc="best",fontsize=legend_fontsize-2)
# xlabel("Number of Devs",fontsize=label_fontsize1+1)
# # ylabel("Objective",fontsize=label_fontsize1+1)
# # yscale("log")
# tight_layout(pad=0.5, w_pad=0.5, h_pad=0.5)
# savefig(string(folder,"Scale_theta.png"))

clf()
figure(10,figsize=fig_size)
# plot(Numb_devs, Objs_E[:,11],linestyle="--",color=colors[1],marker=markers[1], markersize=marker_size, label=string("\$\\kappa\$ =", kaps[11]))
plot(Numb_devs, Objs_E[:,15],linestyle="--",color=colors[2],marker=markers[2], markersize=marker_size, label=string("\$\\kappa\$ =", kaps[15]))
plot(Numb_devs, Objs_E[:,19],linestyle="--",color=colors[3],marker=markers[3], markersize=marker_size, label=string("\$\\kappa\$ =", kaps[19]))
plot(Numb_devs, Objs_E[:,23],linestyle="--",color=colors[4],marker=markers[4], markersize=marker_size, label=string("\$\\kappa\$ =", kaps[23]))

legend(loc="best",fontsize=legend_fontsize-2)
xlabel("Number of Devs",fontsize=label_fontsize1+1)
ylabel("Energy cost",fontsize=label_fontsize1+1)
# yscale("log")
tight_layout(pad=0.5, w_pad=0.5, h_pad=0.5)
savefig(string(folder,"Scale_obj_E.png"))

clf()
figure(11,figsize=fig_size)
# plot(Numb_devs, Objs_T[:,11],linestyle="--",color=colors[1],marker=markers[1], markersize=marker_size, label=string("\$\\kappa\$ =", kaps[11]))
plot(Numb_devs, Objs_T[:,15],linestyle="--",color=colors[2],marker=markers[2], markersize=marker_size, label=string("\$\\kappa\$ =", kaps[15]))
plot(Numb_devs, Objs_T[:,19],linestyle="--",color=colors[3],marker=markers[3], markersize=marker_size, label=string("\$\\kappa\$ =", kaps[19]))
plot(Numb_devs, Objs_T[:,23],linestyle="--",color=colors[4],marker=markers[4], markersize=marker_size, label=string("\$\\kappa\$ =", kaps[23]))

legend(loc="best",fontsize=legend_fontsize-2)
xlabel("Number of Devs",fontsize=label_fontsize1+1)
ylabel("Time cost",fontsize=label_fontsize1+1)
# yscale("log")
tight_layout(pad=0.5, w_pad=0.5, h_pad=0.5)
savefig(string(folder,"Scale_obj_T.png"))

end

function save_result(Theta1, Obj1, Obj_E, Obj_T, T_cmp1, E_cmp1, T_com1, E_com1, N1, N2, N3, f1, tau1, p1, d_eta)
h5open(string("result",NumbDevs,".h5"), "w") do file
# write(file,"kaps", kaps)
write(file,"Theta1", Theta1)
write(file,"Obj1", Obj1)
write(file,"Obj_E", Obj_E)
write(file,"Obj_T", Obj_T)
write(file,"T_cmp1", T_cmp1)
write(file,"E_cmp1", E_cmp1)
write(file,"T_com1", T_com1)
write(file,"E_com1", E_com1)
write(file,"N1", N1)
write(file,"N2", N2)
write(file,"N3", N3)
write(file,"f1", f1)
write(file,"tau1", tau1)
write(file,"p1", p1)
write(file,"d_eta", d_eta)
end
end

function read_result(filename)
h5open(filename, "r") do file
# kaps =read(file,"kaps")
Theta1 = read(file,"Theta1")
Obj1 = read(file,"Obj1")
Obj_E = read(file,"Obj_E")
Obj_T = read(file,"Obj_T")
T_cmp1 = read(file,"T_cmp1")
E_cmp1 = read(file,"E_cmp1")
T_com1 = read(file,"T_com1")
E_com1 = read(file,"E_com1")
N1 = read(file,"N1")
N2 = read(file,"N2")
N3 = read(file,"N3")
f1 = read(file,"f1")
tau1 = read(file,"tau1")
p1 = read(file,"p1")
d_eta = read(file,"d_eta")
return Theta1, Obj1, Obj_E, Obj_T, T_cmp1, E_cmp1, T_com1, E_com1, N1, N2, N3, f1, tau1, p1, d_eta
end
end
13 changes: 9 additions & 4 deletions julia/Setting.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
using Distributions
using HDF5

NumbDevs = 5
NumbDevs = 20 #1, 5, 10, 15, 20
Numb_devs = [1, 5, 10, 15, 20] #[1, 3, 5, 7, 10, 13, 15, 17, 20]

### PROGRAM SETTING ###
Numb_SIMs = 1 #Number of simulations
REUSED_TRAFFIC = false
READ_RESULT = false
DEBUG = 1 #LEVEL 0, 1, 2, 3
HETEROGENEOUS = 1 # 0: homogeneous, 1: heterogeneous, 2: reused
HETEROGENEOUS = 0 # 0: homogeneous, 1: heterogeneous, 2: reused
SCALE = true

### LEARNING PARAMS ###
D_min = 8* 1e6 #1 MB, datasize range (-> bits)
D_max = 8* 2e6 #2 MB (-> bits)
D_min = 8* 1e6 #1 MB, datasize range (-> bits)
D_max = 8* 2e6 #2 MB (-> bits)
D_Total = 8* 20e6 #20 MB (-> bits)
S_n = 10e3 *8 #10KB, weight params size (-> bits), and gradient => 10K nats (1bits/ln2)
# kappa = 0.001 #coeff of T_iter

Expand Down Expand Up @@ -69,3 +73,4 @@ println(f_min)
println(f_max)

alpha = 2e-28
kaps = [5e-5, 8e-5, 1e-4, 3e-4, 5e-4, 7e-4, 1e-3, 3e-3, 5e-3, 7e-3, 1e-2, 3e-2, 5e-2, 7e-2, 1e-1, 0.3, 0.5, 0.7, 1.,3., 5., 7., 1e1, 5e1, 7e1, 1e2]
7 changes: 6 additions & 1 deletion julia/TrafficGen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ function mobile_gen()
D_n = zeros(Numb_SIMs,NumbDevs)
for s =1:Numb_SIMs
dist_list[s,:] = rand(Dist_min:Dist_max,NumbDevs)
D_n[s,:] = rand(D_min:D_max,NumbDevs)
if(SCALE)
D_n[s,:] = D_Total/NumbDevs
else
D_n[s,:] = rand(D_min:D_max,NumbDevs)
end

for n=1:NumbDevs
gain_list[s,n] = exp_gain(dist_list[n])
ratios[s,n] = noise_per_gain(gain_list[n])
Expand Down
Binary file added result1.h5
Binary file not shown.
Binary file added result10.h5
Binary file not shown.
Binary file added result15.h5
Binary file not shown.
Binary file added result20.h5
Binary file not shown.
Binary file added result5.h5
Binary file not shown.
Binary file added scaleRS/result1.h5
Binary file not shown.
Binary file added scaleRS/result10.h5
Binary file not shown.
Binary file added scaleRS/result15.h5
Binary file not shown.
Binary file added scaleRS/result20.h5
Binary file not shown.
Binary file added scaleRS/result5.h5
Binary file not shown.
Binary file modified setting.h5
Binary file not shown.

0 comments on commit 6978a0d

Please sign in to comment.