Introduction to NS-2
Min Chen School of Computer Science and Engineering Seoul National University
Part 6. Confidence Interval
1
Part 6. Confidence Interval Min Chen School of Computer Science and - - PowerPoint PPT Presentation
Introduction to NS-2 Part 6. Confidence Interval Min Chen School of Computer Science and Engineering Seoul National University 1 Outline Definitions Normal Distribution Confidence Interval Central Limit Theorem Error-Bar
Min Chen School of Computer Science and Engineering Seoul National University
1
Definitions Normal Distribution Confidence Interval Central Limit Theorem Error-Bar An Example
2
Population
The set of elements we are inteseted in
Sample
A subset of the Population
Population Mean μ
Always stands for the everage value
Sample Mean X
The Mean for the Sample subset
=∑ Xi N
3
Variance Sample Variance Standard Deviation : Sample Standard Deviation :
2=∑ Xi− 2
N S
2=∑ Xi−X 2
N
S=S
2
=
2
4
A continuous probability distribution that often
For
Probability Density Function(PDF) Cumulative Distribution Function(CDF)
2 e −x−
2
2
2
X~N ,
2
−t
2
2 dt
5
6
7
Confidence Interval (CI) is a particular kind of
If Probability{c1<=µ<=c2} = 1-α Then we call (c1,c2) Confidence Interval 1-α is the Confidence Coefficient
8
Central Limit Theorem (CLT) states conditions
This distribution is
X~N ,
M
9
According to CLT, we can calculate the
Define Z value: Frequently used Z:
Z(90%) = 1.645 Z(95%) = 1.96 Z(99%) = 2.33
Z= X−
n
10
With the value of Z, the confidence interval can
X−Z× S
M ,
XZ× S
M
11
Error Bar is used on graphs to indicate the
In simulation result figures, error bar represents
The error bar in the figure are the variance of
12
n1 n2 n3 n6 n7 n8 n4 n5
Random: [3,4] s
0.0 s 0.0 s
1Mb 10ms 1Mb 10ms 10Mb 1ms 10Mb 1ms UDP: Controlable Data Rate 100 ~ 500 UDP: Controlable Data Rate 100 ~ 500 13 TCP: TCP: UDP: Controlable Data Rate 100 ~ 500 step 100 UDP: Controlable Data Rate 100 ~ 500 step 100 Throughput in 5s ~ 10s Throughput in 5s ~ 10s Each simulation will be repeated for 30 times with different seeds
if {$argc != 2} { puts "Usage: ns errorbar.tcl rate_ no_" exit } #=================================== # Simulation parameters setup #=================================== set par1 [lindex $argv 0] ;# date rate for the interference flow set par2 [lindex $argv 1] ;# the number of the experiments set val(stop) 12.0 ;# time of simulation end #=================================== # Initialization #=================================== #Create a ns simulator set ns [new Simulator] #Open the NS trace file set tracefile [open out$par1-$par2.tr w] $ns trace-all $tracefile #Open the NAM trace file set namfile [open out.nam w] $ns namtrace-all $namfile 14
#=================================== # Nodes Definition #=================================== #Create 8 nodes set n0 [$ns node] set n1 [$ns node] ... set n7 [$ns node] #=================================== # Links Definition #=================================== #Createlinks between nodes $ns duplex-link $n0 $n3 10.0Mb 1ms DropTail $ns queue-limit $n0 $n3 50 ... $ns duplex-link $n3 $n4 1.0Mb 10ms DropTail $ns queue-limit $n3 $n4 50 #Give node position (for NAM) $ns duplex-link-op $n0 $n3 orient right-down ... $ns duplex-link-op $n4 $n7 orient right-down $ns duplex-link-op $n3 $n4 orient right 15
#=================================== # Agents Definition #=================================== #Setup a TCP connection set tcp0 [new Agent/TCP] $ns attach-agent $n0 $tcp0 set sink3 [new Agent/TCPSink] $ns attach-agent $n5 $sink3 $ns connect $tcp0 $sink3 #Setup a TCP connection set tcp1 [new Agent/TCP] $ns attach-agent $n1 $tcp1 set sink4 [new Agent/TCPSink] $ns attach-agent $n6 $sink4 $ns connect $tcp1 $sink4 #Setup a UDP connection set udp [new Agent/UDP] $ns attach-agent $n2 $udp set null [new Agent/Null] $ns attach-agent $n7 $null $ns connect $udp $null 16
#=================================== # Applications Definition #=================================== #Setup a FTP Application over TCP connection set ftp0 [new Application/FTP] $ftp0 attach-agent $tcp0 $ftp0 set type_ FTP set ftp1 [new Application/FTP] $ftp1 attach-agent $tcp1 $ftp1 set type_ FTP set traffic [new Application/Traffic/Exponential] $traffic set packetSize_ 1000 $traffic set burst_time_ 0.5 $traffic set idle_time_ 0 $traffic set rate_ [expr $par1*1000] $traffic attach-agent $udp 17
#=================================== # Traffic Running Time #=================================== set rng [new RNG] $rng seed 0 set RVstart [new RandomVariable/Uniform] $RVstart set min_ 3 $RVstart set max_ 4 $RVstart use-rng $rng set startT [expr [$RVstart value]] puts "startT $startT sec" $ns at 0.0 "$ftp1 start" $ns at 0.0 "$traffic start" $ns at $startT "$ftp0 start" $ns at 11.0 "$ftp0 stop" $ns at 11.5 "$ftp1 stop" $ns at 11.5 "$traffic stop" 18
#=================================== # Termination #=================================== #Define a 'finish' procedure proc finish {} { global ns tracefile namfile $ns flush-trace close $tracefile close $namfile # exec nam out.nam & exit 0 } $ns at $val(stop) "$ns nam-end-wireless $val(stop)" $ns at $val(stop) "finish" $ns at $val(stop) "puts \"done\" ; $ns halt" $ns run 19
BEGIN { Init = 0; startT = 0; endT = 0; } { Action = $1; time= $2; From = $3; to = $4; Type = $5; pktsize = $6; flow_id = $8; src = $9; dst = $10; seq_no = $11; packet_id = $12; if ( action == "r" && type == "tcp" && time>=5.0 $$ time <=10.0 && from == 4 && to == 5 ) { if(init == 0) { start_time = time; Init =1; } pkt_byte_sum += pktsize; endT = time; } } END{ time=endT-startT; throughput=pkt_byte_sum*8/time/1000; printf("%f\n",throughput); } 20
BEGIN { FS="\t"; } { ln++; throughput[ln]=$1; sum=sum+throughput[ln]; } END{ average=sum/ln; for(i=1;i<=ln;i++) { gap=throughput[ln]-average; sum2=sum2+gap*gap; } variance=sqrt(sum2/(ln-1)); confidence_interval=1.96*variance/sqrt(ln); printf("%f %f %f\n",t,average,confidence_interval); } 21
The use of parameters
awk -v t=100 -f errorbar.awk result100 >> errorbar.txt
Three columns
1 : the data rate 2 : the mean throughput 3 : the confidence interval variance
22
set title "Impact of Data Rate on the Throughput" set xlabel "On-Off Flow Rate Setting (kbps)" set ylabel "Flow Throughput (kbps)" set xrange [0:600] set terminal png set output "throughput.png" plot "errorbar.txt" using 1:2:3 with errorbars 1, "errorbar.txt" with lines 1
23
for($i=100; $i<=500; $i=$i+100) { for($j=1; $j<=30; $j++) { system("ns errorbar.tcl $i $j"); $f1="out$i-$j.tr"; $f2="result$i"; system("awk -f throughput.awk $f1 >> $f2"); print "\n"; } print "\n"; } for($i=100; $i<=500; $i=$i+100) { $f1="result$i"; $f2="errorbar.txt"; system("awk -v t=$i -f errorbar.awk $f1 >> $f2"); print "\n"; } system("gnuplot errorbar.gpl"); 24
Grant the privilege to the script file
Run the script
25
26