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 bf8d374 commit fa0f499
Show file tree
Hide file tree
Showing 31 changed files with 131 additions and 63 deletions.
Binary file modified data.h5
Binary file not shown.
Binary file added figs/Heterogeneous/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 added figs/Heterogeneous/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 added figs/Heterogeneous/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 added figs/Heterogeneous/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 added figs/Heterogeneous/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 added figs/Heterogeneous/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 added figs/Heterogeneous/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.
Binary file added figs/Homogeneous/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 added figs/Homogeneous/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 added figs/Homogeneous/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 added figs/Homogeneous/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 added figs/Homogeneous/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 added figs/Homogeneous/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 added figs/Homogeneous/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.
Binary file removed figs/Sub1.png
Binary file not shown.
Binary file added 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 added 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 added 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 added 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 added 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 removed figs/Sub2a.png
Binary file not shown.
Binary file removed figs/Sub2b.png
Binary file not shown.
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.
45 changes: 20 additions & 25 deletions julia/Main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,23 @@ end
function main()
#Generate data
dist_list, gain_list, ratios, D_n = mobile_gen()
# kaps = collect(0:.01:10)
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, 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 = zeros(Numb_kaps)
T_cmp1 = zeros(Numb_kaps)
E_cmp = zeros(Numb_kaps)
E_cmp1 = zeros(Numb_kaps)
f = zeros(Numb_kaps,NumbDevs)
f1 = zeros(Numb_kaps,NumbDevs)
T_cmp, T_cmp1 = zeros(Numb_kaps), zeros(Numb_kaps)
E_cmp, E_cmp1 = zeros(Numb_kaps), zeros(Numb_kaps)
f, f1 = zeros(Numb_kaps,NumbDevs), zeros(Numb_kaps,NumbDevs)
N1, N2, N3 = zeros(Numb_kaps), zeros(Numb_kaps), zeros(Numb_kaps)
Tcmp_N1, Tcmp_N2, Tcmp_N3 = zeros(Numb_kaps), zeros(Numb_kaps), zeros(Numb_kaps)

T_com = zeros(Numb_kaps)
T_com1 = zeros(Numb_kaps)
E_com = zeros(Numb_kaps)
E_com1 = zeros(Numb_kaps)
p = zeros(Numb_kaps,NumbDevs)
p1 = zeros(Numb_kaps,NumbDevs)
tau = zeros(Numb_kaps,NumbDevs)
tau1 = zeros(Numb_kaps,NumbDevs)

Theta = zeros(Numb_kaps)
Theta1 = zeros(Numb_kaps)
Obj = zeros(Numb_kaps)
Obj1 = zeros(Numb_kaps)
T_com, T_com1 = zeros(Numb_kaps),zeros(Numb_kaps)
E_com, E_com1 = zeros(Numb_kaps), zeros(Numb_kaps)
p, p1 = zeros(Numb_kaps,NumbDevs), zeros(Numb_kaps,NumbDevs)
tau, tau1 = zeros(Numb_kaps,NumbDevs), zeros(Numb_kaps,NumbDevs)

Theta, Theta1 = zeros(Numb_kaps), zeros(Numb_kaps)
Obj, Obj1 = zeros(Numb_kaps), zeros(Numb_kaps)
d_eta = zeros(Numb_kaps)

# println("Numb_kaps: ", Numb_kaps)
Expand All @@ -51,7 +45,7 @@ function main()
global kappa = kaps[k]
### Sub1 ###
T_cmp[k], f[k,:], E_cmp[k] = Solving_sub_prob1(D_n[s,:])
T_cmp1[k], f1[k,:], E_cmp1[k] = Solving_sub1(D_n[s,:])
T_cmp1[k], f1[k,:], E_cmp1[k], Tcmp_N1[k], Tcmp_N2[k], Tcmp_N3[k],N1[k], N2[k], N3[k] = Solving_sub1(D_n[s,:])
# println("\n---->> Check Sub1 Solution: ", check([T_cmp, f, E_cmp], [T_cmp1, f1, E_cmp1]))

### Sub2 ###
Expand All @@ -70,14 +64,15 @@ function main()
# println("\n---->> Check Global Solution: ", check(rs, rs2))
end
end
println(T_cmp)
println(T_cmp1)
plot_sub1(kaps, T_cmp, T_cmp1)

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)

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

function main1()
Expand Down
110 changes: 89 additions & 21 deletions julia/Plots_Figs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,69 @@ markers = ["x","o",">","^", "."]

folder = string("figs//")

function plot_sub1(kaps, T_cmp, T_cmp1)
function plot_sub1_T(kaps, 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")
plot(kaps,T_cmp1,color=colors[2],linestyle=":",linewidth=l_width,label="Closed-Form")
# plot(kaps,T_cmp,color=colors[1],linestyle="-",linewidth=l_width,label="Solver")
plot(kaps,T_cmp1,color=colors[6],linestyle="-",linewidth=l_width,label="T_cmp_opt")
plot(kaps,Tcmp_N1,color=colors[2],linestyle="-.",linewidth=l_width,label="Tcmp_N1")
plot(kaps,Tcmp_N2,color=colors[4],linestyle="-.",linewidth=l_width,label="Tcmp_N2")
plot(kaps,Tcmp_N3,color=colors[5],linestyle="-.",linewidth=l_width,label="Tcmp_N3")

legend(loc="best",fontsize=legend_fontsize-2)
xlabel("\$\\kappa\$",fontsize=label_fontsize1+1)
xscale("log")
ylabel("\$T_{cmp}\$",fontsize=label_fontsize1+1)
ylabel("\$T_{cmp}\$ (sec)",fontsize=label_fontsize1+1)
tight_layout(pad=0.5, w_pad=0.5, h_pad=0.5)
savefig(string(folder,"Sub1.png"))
savefig(string(folder,"Sub1_T.png"))
end

function plot_sub1_N(kaps, N1, N2, N3)
clf()
figure(1,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")
plot(kaps,N3,color=colors[5],linestyle="--",linewidth=l_width,label="N3")

function plot_sub2_tau(kaps, tau, tau1)
legend(loc="best",fontsize=legend_fontsize-2)
xlabel("\$\\kappa\$",fontsize=label_fontsize1+1)
xscale("log")
ylabel("Numb of Devs",fontsize=label_fontsize1+1)
tight_layout(pad=0.5, w_pad=0.5, h_pad=0.5)
savefig(string(folder,"Sub1_N.png"))
end

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

if (HETEROGENEOUS == 0) # Homogeneous
plot(kaps,f_max[1]*ones(size(kaps))*1e-9,linestyle="--",color=colors[6])
end

for n = 1:NumbDevs
if (HETEROGENEOUS > 0)
plot(kaps,f_max[n]*ones(size(kaps))*1e-9,linestyle="--",color=colors[n])
# plot(kaps,f_min[n]*ones(size(kaps))*1e-9,linestyle=":",color=colors[n])
end

plot(kaps,f1[:,n],color=colors[n],linestyle="-",linewidth=l_width,label=string("Dev ",n))
end
# plot(kaps,T_comps1,marker=markers[2],color=colors[2], markersize=marker_size,linestyle=":",linewidth=l_width,label="Tcmp1")

legend(loc="best",fontsize=legend_fontsize-2)
xlabel("\$\\kappa\$",fontsize=label_fontsize1+1)
xscale("log")
ylabel("f (GHz)",fontsize=label_fontsize1+1)
tight_layout(pad=0.5, w_pad=0.5, h_pad=0.5)
savefig(string(folder,"Sub1_f.png"))
end

function plot_sub2_tau(kaps, tau, tau1)
clf()
figure(3,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 @@ -44,14 +89,14 @@ function plot_sub2_tau(kaps, tau, tau1)
legend(loc="best",fontsize=legend_fontsize-2)
xlabel("\$\\kappa\$",fontsize=label_fontsize1+1)
xscale("log")
ylabel("\$\\tau_n\$",fontsize=label_fontsize1+1)
ylabel("\$\\tau_n\$ (sec)",fontsize=label_fontsize1+1)
tight_layout(pad=0.5, w_pad=0.5, h_pad=0.5)
savefig(string(folder,"Sub2a.png"))
savefig(string(folder,"Sub2_Tau.png"))
end

function plot_sub2_p(kaps, p, p1)
clf()
figure(3,figsize=fig_size)
figure(4,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 @@ -62,38 +107,61 @@ function plot_sub2_p(kaps, p, p1)
legend(loc="best",fontsize=legend_fontsize-2)
xlabel("\$\\kappa\$",fontsize=label_fontsize1+1)
xscale("log")
ylabel("p",fontsize=label_fontsize1+1)
ylabel("p (Watt)",fontsize=label_fontsize1+1)
tight_layout(pad=0.5, w_pad=0.5, h_pad=0.5)
savefig(string(folder,"Sub2b.png"))
savefig(string(folder,"Sub2_p.png"))
end

function plot_sub3_cvx(kaps, Theta, Theta1, Obj, Obj1)
function plot_sub3_cvx(kaps, Theta, Theta1, Obj, Obj1, T_cmp1, E_cmp1, T_com1, E_com1)
clf()
figure(4,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")
figure(5,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")
#
# legend(loc="best",fontsize=legend_fontsize-2)
# xlabel("\$\\Theta\$",fontsize=label_fontsize1+1)
# ylabel("Objective",fontsize=label_fontsize1+1)
# tight_layout(pad=0.5, w_pad=0.5, h_pad=0.5)
# savefig(string(folder,"Sub3_obj.png"))

x = collect(1.e-5:0.001:0.99)
obj = zeros(size(x)[1])
id = 9
println("Convex for kappa: ", kaps[id])
for i=1:size(x)[1]
obj[i] = 1/(1 - x[i])* (E_com1[id] - log(x[i])*E_cmp1[id] + kaps[id] * (T_com1[id] - log(x[i])*T_cmp1[id]))
end
plot(x, obj,linestyle="-",color="k", label=string("\$\\kappa\$ =", kaps[id]))
# println(x)
plot(Theta1[id], Obj1[id],color="r", marker=markers[1], markersize=marker_size)

legend(loc="best",fontsize=legend_fontsize-2)
xlabel("\$\\Theta\$",fontsize=label_fontsize1+1)
ylabel("Objective",fontsize=label_fontsize1+1)
tight_layout(pad=0.5, w_pad=0.5, h_pad=0.5)
savefig(string(folder,"Sub3_obj.png"))
println("Theta: ", minimum(Theta1), " - ", maximum(Theta1))
end

function plot_sub3_equation(kaps, d_eta)
Numb_kaps = size(kaps)[1]
clf()
x = collect(1e-6:0.0001:0.9999)
# println(x)
figure(5,figsize=fig_size)
plot(x,log.(e.^(1./x).*x),linestyle="-",color=colors[6])
# println(x)
println(log(e^(1/x[1])x[1]))
x = collect(1.e-6:0.001:0.999)

# if ((maximum(d_eta)>200) & (maximum(d_eta)< 500))
# x[1] = 2.5e-3
# elseif (maximum(d_eta)> 500)
# x[1] = 1.e-3
# end

figure(7,figsize=fig_size)
plot(x, 1./x + log.(x),linestyle="-",color=colors[6])
for k = 1:Numb_kaps
plot(x,d_eta[k]*ones(size(x)),linestyle=":",color="k")
end

legend(loc="best",fontsize=legend_fontsize-2)
ylim(0.98,maximum(d_eta)+0.1*maximum(d_eta))
xlabel("\$\\Theta\$",fontsize=label_fontsize1+1)
ylabel("\$\\log(e^{1/\\Theta} \\Theta)\$",fontsize=label_fontsize1+1)
tight_layout(pad=0.5, w_pad=0.5, h_pad=0.5)
Expand Down
31 changes: 16 additions & 15 deletions julia/Setting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ NumbDevs = 5
Numb_SIMs = 1 #Number of simulations
REUSED_TRAFFIC = false
DEBUG = 1 #LEVEL 0, 1, 2, 3
HETEROGENEOUS = 1 # 0: homogeneous:, 1: heterogeneous, 2: reused
HETEROGENEOUS = 1 # 0: homogeneous, 1: heterogeneous, 2: reused

### LEARNING PARAMS ###
D_min = 8* 1e6 #1 MB, datasize range (-> bits)
Expand All @@ -18,51 +18,52 @@ S_n = 10e3 *8 #10KB, weight params size (-> bits), and gradient => 10K nats
### COMMUNICATIONS PARAMS ###
Ptx_Max = 1.
Ptx_Min = 0.1
N0 = 1e-9 #
BW = 2e6 #Mhz
N0 = 1e-12 # -> Decrease BW -> Increase Theta
BW = 20e6 #Mhz -> Increase BW -> Increase Theta

Dist_min = 2 #2m
Dist_max = 50 #50m

### COMPUTING PARAMS ###
function save_setting(f_min, f_max, C_n)
function save_setting(f_max, C_n)
h5open("setting.h5", "w") do file
write(file,"f_min", f_min)
# write(file,"f_min", f_min)
write(file,"f_max", f_max)
write(file,"C_n", C_n)
end
end

function read_setting()
h5open("setting.h5", "r") do file
f_min =read(file,"f_min")
# f_min =read(file,"f_min")
f_max =read(file,"f_max")
C_n = read(file,"C_n")
return f_min, f_max, C_n
return f_max, C_n
end
end

if (HETEROGENEOUS == 0) # Homogeneous
cpu_min = .1 #GHz, cyles/1sec
cpu_max = 2. #GHz, cyles/1sec
f_min = cpu_min*ones(NumbDevs)*1e9 #Hz
# f_min = cpu_min*ones(NumbDevs)*1e9 #Hz
f_max = cpu_max*ones(NumbDevs)*1e9 #Hz
C_n = 100*ones(NumbDevs) #cycles/bits
save_setting(f_min,f_max,C_n)
save_setting(f_max,C_n)

elseif (HETEROGENEOUS == 1) # Heterogeneous
cpu_min1 = .1 #GHz, cyles/1sec
cpu_min2 = .2 #GHz, cyles/1sec
# cpu_min1 = .1 #GHz, cyles/1sec
# cpu_min2 = .2 #GHz, cyles/1sec
cpu_max1 = 1. #GHz, cyles/1sec
cpu_max2 = 2. #GHz, cyles/1sec
f_min = rand(Uniform(cpu_min1,cpu_min2),NumbDevs)*1e9 #Hz
# f_min = rand(Uniform(cpu_min1,cpu_min2),NumbDevs)*1e9 #Hz
f_max = rand(Uniform(cpu_max1,cpu_max2),NumbDevs)*1e9 #Hz
C_n = rand(50:150,NumbDevs) #cycles/bits
save_setting(f_min,f_max,C_n)
C_n = rand(80:120,NumbDevs) #cycles/bits
save_setting(f_max,C_n)

elseif (HETEROGENEOUS == 2) # Reused params
f_min, f_max, C_n = read_setting()
end
cpu_min = .1 #GHz, cyles/1sec
f_min = cpu_min*ones(NumbDevs)*1e9 #Hz
println(C_n)
println(f_min)
println(f_max)
Expand Down
6 changes: 4 additions & 2 deletions julia/Solving1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ function Solving_sub1(D_n)
println("Objective: ", rs_E_cmp + kappa*rs_T_cmp )
end

return rs_T_cmp, rs_f, rs_E_cmp
return rs_T_cmp, rs_f, rs_E_cmp, Tcmp_N1, Tcmp_N2, Tcmp_N3, size(N1)[1], size(N2)[1], size(N3)[1]
end

function inv_g_func(tau, ratio)
Expand Down Expand Up @@ -432,7 +432,7 @@ function Solving_sub3( T_cmp, E_cmp, T_com, E_com)
println("Eta: ", eta)
fx(x) = log(x) + 1/x - 1/eta

rs_Theta = find_zero(fx,1e-9)
rs_Theta = find_zero(fx,1e-6)
Thetas = find_zeros(fx, 0+0.00001, 1-0.00001)
println("Roots: ", Thetas)

Expand All @@ -444,5 +444,7 @@ function Solving_sub3( T_cmp, E_cmp, T_com, E_com)
println("Obj: ", Obj)
end

# println("Test sub3:", abs(log(rs_Theta) + 1/rs_Theta - 1/eta))

return rs_Theta, Obj, 1/eta
end
2 changes: 2 additions & 0 deletions julia/temp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@ savefig("plot.png")

x = collect(0:.1:10)
println(x.^2)

println(true & false)
Binary file modified setting.h5
Binary file not shown.

0 comments on commit fa0f499

Please sign in to comment.