For do this experiment I use a combination between:
- Python that took for parameters:
- Size of the word
- frequency of succeed
- Probability for one that can transmit
- Probability for zero that can transmit
- Times that we want to do an experiment.
- In a Bash do:
- Change the frequency of succeed
- Change Probability for one and zero
- Call to the python script to change those variables
- In AWK I can:
- Obtain a mean and also an standard deviation.
Then we use gnuplot to interpret the data that we obtain, so in the following plot I will explain about who a noisy channel works and how all the data that we use in the experiment are connected each other and made that a channel fail or success in transmit binary data.
This is a graphic that I generated for demonstrate that, when I augmented the size of the binary word, the success for transmit is almost nothing, both if we have a word for example 2**0, the test only send 1 bit, so we have a many chances that this bit can transmit.
Also, this is another graphic that we can see that, when we have a large word we have a 0 probability to send the word correctly, so we can view the circle in black express the standard deviation that we can compute in the AWK script.
This are the same graphics but separated between the probability success 1 and 0.
We can notice that, when we have more frequency of zeros and more probability of success of 1, the probability of zeros is poor, so the standard deviation is going to down, that is because the word transmit more 1 than 0.
Code.
Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import numpy | |
import sys | |
def genera_bin(tam, prob): | |
palabra = "" | |
for i in xrange(tam): | |
x = random.random() | |
if (prob < x): | |
palabra = palabra + str(0) | |
else: | |
palabra = palabra + str(1) | |
return palabra | |
def transmite(palabra, Q): | |
""" | |
""" | |
palabra_trans = '' | |
for i in xrange(len(palabra)): | |
bit = palabra[i] | |
x = random.random() | |
if (x < Q[int(bit)]): | |
palabra_trans = palabra_trans + str(bit) | |
else: | |
if bit == "0": | |
palabra_trans = palabra_trans + str(1) | |
else: | |
palabra_trans = palabra_trans + str(0) | |
return palabra_trans | |
def repeticiones(num, palabra, Q): | |
mal = 0 | |
bien = 0 | |
for i in xrange(num): | |
transmitida = transmite(palabra, Q) | |
if transmitida != palabra: | |
mal = mal + 1 | |
else: | |
bien = bien + 1 | |
return (bien, mal) | |
def main(): | |
tam = int(sys.argv[1]) | |
frecuencia = float(sys.argv[2]) | |
Q0 = float(sys.argv[3]) | |
Q1 = float(sys.argv[4]) | |
rep = int(sys.argv[5]) | |
palabra = genera_bin(tam, frecuencia) | |
Q = [Q0, Q1] | |
(bien, mal) = repeticiones(rep, palabra, Q) | |
print float(bien * 100)/float(rep) | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
tam=1 | |
frec=0.5 | |
rep=30 | |
init=1 | |
count=0 | |
res=1 | |
lim=100 | |
pot=0 | |
palabras=30 | |
q0=0 | |
q1=0 | |
touch datos.dat | |
touch tmp.dat | |
rm datos.dat | |
rm tmp.dat | |
echo $tam | |
while [[ tam -le lim ]] | |
do | |
for frec in 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 | |
do | |
for q0 in 0.1 0.5 0.9 | |
do | |
for q1 in 0.1 0.5 0.9 | |
do | |
touch tmp.dat | |
rm tmp.dat | |
touch tmp.dat | |
conta=1 | |
while [[ conta -le palabras ]] | |
do | |
res=`python tarea_1.py $tam $frec $q0 $q1 $rep` | |
echo $conta $tam $frec $res $q0 $q1 >> tmp.dat | |
conta=$((1+$conta)) | |
done | |
resu=`./experimento.awk -v tam=$tam -v frec=$frec tmp.dat` | |
echo $pot $frec $resu $q0 $q1 >> datos.dat | |
rm tmp.dat | |
done | |
done | |
done | |
pot=$((1+$pot)) | |
tam=$((2*$tam)) | |
echo $tam | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set grid layerdefault | |
set term png | |
set title 'Probability success 1' | |
set ylabel 'Frequency' | |
set xlabel 'Word size, power of two' | |
set label "" | |
set output "grafica_4.png" | |
set key off | |
plot "datos.dat" using 1:6:4 with points palette pt 11 ps 3 | |
set grid layerdefault | |
set term png | |
set title 'Probability success 0' | |
set ylabel 'Frequency' | |
set xlabel 'Word size, power of two' | |
set label "" | |
set output "grafica_3.png" | |
set key off | |
plot "datos.dat" using 1:5:4 with points palette pt 13 ps 3 | |
set grid layerdefault | |
set term png | |
set title 'Word size vs Success Transmit' | |
set ylabel 'Frequency' | |
set xlabel 'Word size, power of two' | |
set label "" | |
set output "grafica_2.png" | |
set key off | |
plot "datos.dat" using 1:2:4 with points palette pt 7 ps 3 | |
set grid layerdefault | |
set term png | |
set title 'Word with Success Transmit' | |
set xlabel 'Power of 2' | |
set ylabel 'Probability of success to Transmit' | |
set label "" | |
set arrow from 0,0 to 6,0 | |
set output "grafica_1.png" | |
set key off | |
plot "datos.dat" using 1:2:3 with yerrorbars pt 7 ps 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/awk -f | |
{ | |
if($2 == tam && $3 == frec){ | |
suma+=$4 | |
conta+=1 | |
} | |
} | |
END{ | |
promedio = suma/conta | |
print promedio | |
} | |
{ | |
if($2 == tam && $3 == frec){ | |
dato = $4 | |
x = promedio - dato | |
suma_cuadrado+=x^2 | |
} | |
}END { | |
varianza = suma_cuadrado/(conta-1) | |
desviacion = sqrt(varianza) | |
print desviacion | |
} |
En el código faltó la desviación estándar y el reporte se pudiera haber mejorado en términos de claridad de análisis. 4+4.
ResponderEliminarCorrijo a mi misma. 5 pts por el código.
ResponderEliminar