Browse Source

Splitted READMEs

root 8 years ago
parent
commit
36e5c51b8b
3 changed files with 376 additions and 376 deletions
  1. 174
    0
      README-en.md
  2. 200
    0
      README-es.md
  3. 2
    376
      README.md

+ 174
- 0
README-en.md View File

@@ -0,0 +1,174 @@
1
+
2
+#Arrays - Benford's Law
3
+
4
+![main1.png](images/main1.png)
5
+![main2.png](images/main2.png)
6
+![main3.png](images/main3.png)
7
+
8
+
9
+Arrays help us to store and work with groups of data of the same type. The data is stored in consecutive memory spaces which can be accessed by using the name of the array and indexes or subscripts that indicate the position where the data is stored. Repetition structures provide us a simple way of accessing the data within an array. In today's laboratory experience you will practice the use of counters and one dimensional arrays to implement a program in which you will use Benford’s Law to detect files with bogus data.
10
+
11
+
12
+
13
+## Objectives:
14
+
15
+1. Practice using arrays of counters to determine data frequency in a file.
16
+
17
+2. Detect the use of bogus data using Benford's Law and the leading digit frequency distribution.
18
+
19
+3. Practice reading data from text files.
20
+
21
+
22
+## Pre-Lab
23
+
24
+Before coming to the laboratory, you should have:
25
+
26
+1. Learned how to extract the leading digit (first digit from left to right) of an integer read from a file.
27
+
28
+2. Reviewed basic array and counter concepts.
29
+
30
+3. Reviewed text file input in C++.
31
+
32
+4. Studied the concepts and instructions for this laboratory session.
33
+
34
+5. Taken the Pre-Lab quiz found in Moodle.
35
+ 
36
+
37
+---
38
+
39
+---
40
+
41
+
42
+
43
+
44
+
45
+As part of your new job as IT auditor you suspect that someone in the Chicago Transit Authority (CTA) has been tampering with the information systems and changing the data files that contain the bus route daily totals. You are given five text files that contain daily totals for each of the CTA’s bus routes and must determine if one or more of the files contain bogus data. In this laboratory experience you will implement a program that will help you determine which of the file(s) contain bogus data using Benford's Law, a property that is observed in many real-life sources of data. 
46
+
47
+---
48
+
49
+## What is Benford’s Law? (copied from the ISACA journal)
50
+
51
+Benford’s Law, named for physicist Frank Benford, who worked on the theory in 1938, is the mathematical theory of leading digits. Specifically, in data sets, the leading digit(s) is (are) distributed in a specific, non uniform way. While one might think that the number 1 would appear as the first digit 11 percent of the time (i.e., one of nine possible numbers), it actually appears about 30 percent of the time (see Figure 1). The number 9, on the other hand, is the first digit less than 5 percent of the time. The theory covers the first digit, second digit, first two digits, last digit and other combinations of digits because the theory is based on a logarithm of probability of occurrence of digits.
52
+
53
+---
54
+
55
+![figure1.png](images/figure1.png)
56
+
57
+**Figure 1.** Distribution of the leading digit in a real data set according to Benford’s Law. Taken from [1]. 
58
+
59
+---
60
+
61
+
62
+### How to use Benford's Law to spot bogus data
63
+
64
+
65
+In this laboratory experience you will use Benford's Law applied only to the leading digit. To do this, you need to determine the frequency of each leading digit in the numbers of the file. Suppose that you are given a file that contains the following integer numbers:
66
+
67
+```
68
+890 3412 234 143 112 178 112 842 5892 19 
69
+777 206 156 900 1138 438 158 978 238 192
70
+```
71
+
72
+As you read each number $$n$$, you determine its leading digit (how to extract the leading digit is left as an exercise for you). You must also keep track of how many times the same leading digit appears in the data set. The easiest way to keep track of how many times you find a leading 1, a leading 2, ... a leading 9, is to use an *array of counters*. This array of counters is simply an array of integers where each element is incremented whenever you find a certain leading digit. For instance, for this exercise the array of counters can be an array of 10 integers, initialized to `0`. 
73
+
74
+---
75
+
76
+![figure2.png](images/figure2.png)
77
+
78
+**Figure 2.** Array of 10 integers initialized to `0`.
79
+
80
+---
81
+
82
+
83
+Every time a leading digit `d` is found, the element with index `d` is incremented. For example, after reading the numbers  `890`, `3412`, `234`, `143`, and `112`, the array content would be:
84
+
85
+----
86
+
87
+![figure3.png](images/figure3.png)
88
+
89
+**Figure 3.** Contents of the array after reading 890, 3412, 234, 143, 112 and counting their leading digits.
90
+
91
+---
92
+
93
+
94
+After reading through all the data, the content of each array element will be the number of times that leading digit appears in the data.
95
+
96
+---
97
+
98
+![figure4.png](images/figure4.png)
99
+
100
+**Figure 4.** Contents of the array after reading all the data.
101
+
102
+---
103
+
104
+The **frequency of occurrence** is defined as the ratio of times that a digit appears divided by the total number of data.  For example, the frequency of leading digit `1` in the example would computed as $$9 / 20 = 0.45$$.  **Histograms** are the preferred visualization of frequency distributions in a data set. In essence, a histogram is a bar chart where the $$y$$-axis is the frequency and a vertical bar is drawn for each of the counted classifications (in our case, for each digit). 
105
+
106
+---
107
+
108
+![figure5.png](images/figure5.png)
109
+
110
+**Figure 5.** Histogram of the frequency of leading digits in the example data.
111
+
112
+---
113
+
114
+---
115
+
116
+!INCLUDE "../../eip-diagnostic/benfords-law/en/diag-benford-law-01.html"
117
+
118
+!INCLUDE "../../eip-diagnostic/benfords-law/en/diag-benford-law-02.html"
119
+
120
+!INCLUDE "../../eip-diagnostic/benfords-law/en/diag-benford-law-03.html"
121
+
122
+!INCLUDE "../../eip-diagnostic/benfords-law/en/diag-benford-law-04.html"
123
+
124
+---
125
+
126
+---
127
+
128
+##Laboratory session
129
+
130
+###Exercise 1: Familiarizing yourself with the data files and the provided code 
131
+
132
+####Instructions
133
+
134
+1. Load the project `BenfordsLaw` onto QtCreator by double clicking the file `BenfordsLaw.pro` in the folder `Documents/eip/Arrays-BenfordsLaw` on your computer. You can also go to `http://bitbucket.org/eip-uprrp/arrays-benfordslaw` to download the `Arrays-BenfordsLaw` folder to your computer.
135
+
136
+2. The text files `cta-a.txt`, `cta-b.txt`,  `cta-c.txt`,  `cta-d.txt`,  and `cta-e.txt` in the `data` directory contain either real or bogus data. Each line of the file specifies the bus route code and the number of users for that route on a certain day. Open the file `cta-a.txt` to understand the data format. This will be important when reading the file sequentially using C++. Notice that some of the route codes contain characters.
137
+
138
+3. Open the `main.cpp` file. Study the `main` function and make sure that you understand all of its parts. In essence, the provided `main` function creates a window that displays a histogram like the one shown in Figure 6.
139
+
140
+ ---
141
+
142
+  ![figure6.png](images/figure6.png)
143
+
144
+    **Figure 6.** Result of running the provided program. A histogram is displayed using the data in the arguments `histoNames` and `histoValues`.
145
+
146
+    ---
147
+
148
+In the provided code, notice that the data in the arrays `histoNames` and `histoValues` were assigned directly in their declarations. For the provided files, your program should compute the frequency of occurrence of the leading digits and then display their histogram by using the `histo` method.  
149
+
150
+###Exercise 2: Implement a program to detect bogus data in the data files
151
+
152
+####Instructions
153
+
154
+1. Using the provided `main` function as inspiration, add the necessary code to implement a program that reads a text data file like the ones in the `data` folder and determines the frequency of occurrence of the leading digits of the second column of the files. Compute the frequency of occurrence as it was explained before Figure 5.
155
+
156
+2. Once your program has the frequency of occurrence of the leading digits, use the method `histo` to display the histogram. Run the program for each of the text files. Based on the leading digit frequency distribution for each file, decide if (according to Benford’s Law) the file contains real or bogus data.
157
+
158
+---
159
+
160
+---
161
+
162
+##Deliverables
163
+
164
+1. Use "Deliverables 1" in Moodle to upload the `main.cpp` file with the modifications you made in **Exercise 2**. Remember to use good programming techniques, include the names of the programmers involved, and to document your program.
165
+
166
+2. Use "Deliverables 2" in Moodle to upload a **pdf** file that contains screen shots of the histograms produced after analyzing each text file. Please caption each figure with the name of the text file and provide your decision as to whether the file contained real or bogus data.
167
+
168
+---
169
+
170
+---
171
+
172
+##References
173
+
174
+[1] http://www.isaca.org/Journal/archives/2011/Volume-3/Pages/Understanding-and-Applying-Benfords-Law.aspx

+ 200
- 0
README-es.md View File

@@ -0,0 +1,200 @@
1
+
2
+#Arreglos - Ley de Benford
3
+
4
+![main1.png](images/main1.png)
5
+![main2.png](images/main2.png)
6
+![main3.png](images/main3.png)
7
+
8
+Los arreglos de datos (*arrays*) nos facilitan guardar y trabajar con grupos de datos del mismo tipo. Los datos se guardan en espacios de memoria consecutivos a los que se puede acceder utilizando el nombre del arreglo e índices o suscritos que indican la posición en que se encuentra el dato. Las estructuras de repetición nos proveen una manera simple de acceder a los datos de un arreglo. En la experiencia de laboratorio de hoy practicarás el uso de contadores y arreglos de una dimensión para implementar un programa en el que usarás la Ley de Benford para detectar   archivos con datos falsificados.
9
+
10
+
11
+
12
+##Objetivos:
13
+
14
+1. Practicar el  uso de un arreglo de contadores para determinar la frecuencia de los datos de un archivo.
15
+
16
+2. Detectar el uso de datos falsificados utilizando la distribución de frecuencia y la Ley de Benford.
17
+
18
+3. Practicar la lectura de datos de un archivo de texto.
19
+
20
+
21
+
22
+
23
+##Pre-Lab:
24
+
25
+Antes de llegar al laboratorio debes haber:
26
+
27
+
28
+1. Aprendido cómo extraer el dígito líder (primer dígito) de un número. 
29
+
30
+2. Repasado los conceptos relacionados a arreglos y contadores.
31
+
32
+3. Repasado cómo leer datos de un archivo en C++.
33
+
34
+4. Estudiado los conceptos e instrucciones para la sesión de laboratorio.
35
+
36
+5. Tomado el quiz Pre-Lab que se encuentra en Moodle.
37
+
38
+---
39
+
40
+---
41
+
42
+
43
+
44
+Como parte de tu nuevo trabajo de auditora de tecnología de información, tienes la sospecha de que alguien en la Autoridad Metropolitana de Autobuses (AMA) de Puerto Rico ha estado manipulando los sistemas de información y cambiando los archivos de datos que contienen los totales de pasajeros de las rutas diarias de las guaguas. Te han dado 5 archivos de texto que contienen los totales diarios de cada una de las rutas de las guaguas de la AMA y debes determinar si uno o más archivos contienen datos falsos. Para detectar cuál(es) archivos tienen datos falsos  implementarás un programa en el que usarás la Ley de Benford.
45
+
46
+
47
+---
48
+
49
+## ¿Qué es la Ley de Benford? (adaptado del ISACA Journal [1])
50
+
51
+
52
+La Ley de Benford es la teoría matemática de los dígitos líderes de un número, y fue llamada así en honor al físico Frank Benford, quién trabajó en esta teoría en 1938. Específicamente, en conjuntos de datos, los dígitos líderes están distribuidos de forma no uniforme. Uno podría pensar que el número 1 aparece como primer dígito el 11% del tiempo (esto es, uno de 9 números posibles), sin embargo, este número aparece como líder alrededor del 30% del tiempo (vea la Figura 1). Por otro lado, el número 9 es el primer dígito menos del 5% del tiempo. La teoría cubre las ocurrencias del primer dígito, el segundo dígito, los primeros dos dígitos, el último dígito y otras combinaciones de dígitos porque la teoría está basada en un logaritmo de probabilidad de ocurrencia de dígitos.
53
+
54
+
55
+---
56
+
57
+![figure1.png](images/figure1.png)
58
+
59
+
60
+**Figura 1.** Distribución del primer dígito en un conjunto de datos real según la Ley de Benford. Tomado de [1]. 
61
+
62
+---
63
+
64
+
65
+## Cómo usar la Ley de Benford para detectar datos falsificados 
66
+
67
+En esta experiencia de laboratorio usarás la Ley de Benford aplicada solamente al primer dígito (el dígito líder). Para hacer esto, necesitas determinar la frecuencia de cada dígito líder en los números en un archivo. Supón que te dan un archivo que contiene los siguientes números enteros:
68
+
69
+
70
+
71
+
72
+```
73
+890 3412 234 143 112 178 112 842 5892 19 
74
+777 206 156 900 1138 438 158 978 238 192
75
+```
76
+
77
+
78
+Según vas leyendo cada número $$n$$, determinas su dígito líder (la manera de extraer el dígito líder de un número se deja como un ejercicio para tí). También debes estar pendiente de cuántas veces sale el dígito líder en el conjunto de datos. La manera más fácil de llevar cuenta de la cantidad de veces que aparece el 1 como líder, el 2 como líder, ... , el 9 como líder, es utilizando un *arreglo de contadores*. Este arreglo de contadores es sencillamente un arreglo de enteros en el que un elemento del arreglo se incrementa cada vez que se encuentra cierto dígito líder. Por ejemplo, para este ejercicio el arreglo de contadores puede ser un arreglo de 10 enteros, inicializado a `0`.
79
+
80
+
81
+
82
+---
83
+
84
+![figure2.png](images/figure2.png)
85
+
86
+**Figura 2.** Arreglo de 10 enteros inicializado a `0`.
87
+
88
+
89
+---
90
+
91
+Cada vez que se encuentra el dígito líder `d`, el elemento con índice `d` se incrementa. Por ejemplo, luego de leer los números `890` `3412` `234` `143` `112`, el contenido del arreglo sería el siguiente:
92
+
93
+
94
+----
95
+
96
+![figure3.png](images/figure3.png)
97
+
98
+**Figura 3.** Contenido del arreglo luego de leer `890` `3412` `234` `143` `112`, y contar sus dígitos líderes.
99
+
100
+---
101
+
102
+Al finalizar de examinar el archivo, el contenido de cada elemento en el arreglo será el número de veces que el dígito líder aparece en los datos.
103
+
104
+
105
+
106
+---
107
+
108
+![figure4.png](images/figure4.png)
109
+
110
+**Figura 4.** Contenido del arreglo de contadores luego de examinar todos los datos. 
111
+
112
+---
113
+
114
+### Frecuencia de ocurrencia
115
+
116
+La **frecuencia de ocurrencia** se define como la razón del número de veces que un dígito aparece sobre el número total de datos. Por ejemplo, la frecuencia del dígito líder `1` en el ejemplo de la Figura 4 se computa como $$9/20 = 0.45$$. La manera común de visualizar las distribuciones de frecuencia de un conjunto de datos es utilizando un **histograma**. En esencia, un histograma es una gráfica de barras en la que el eje de $$y$$ es la frecuencia de ocurrencia y se dibuja una barra para cada una de las clasificaciones que se cuenta (en nuestro caso, una barra para cada dígito líder).
117
+
118
+
119
+---
120
+
121
+![figure5.png](images/figure5.png)
122
+
123
+**Figura 5.** Histograma para la frecuencia de los dígitos líderes en los datos de muestra.
124
+
125
+---
126
+
127
+---
128
+
129
+!INCLUDE "../../eip-diagnostic/benfords-law/es/diag-benford-law-01.html"
130
+
131
+!INCLUDE "../../eip-diagnostic/benfords-law/es/diag-benford-law-02.html"
132
+
133
+!INCLUDE "../../eip-diagnostic/benfords-law/es/diag-benford-law-03.html"
134
+
135
+!INCLUDE "../../eip-diagnostic/benfords-law/es/diag-benford-law-04.html"
136
+
137
+---
138
+
139
+---
140
+
141
+
142
+##Sesión de laboratorio:
143
+
144
+###Ejercicio 1: Entender los archivos de datos y el código provisto
145
+
146
+####Instrucciones
147
+
148
+
149
+1. Carga a QtCreator el proyecto `BenfordsLaw`  haciendo doble "click" en el archivo `BenfordsLaw.pro` en el directorio `Documents/eip/Arrays-BenfordsLaw` de tu computadora. También puedes ir a `http://bitbucket.org/eip-uprrp/arrays-benfordslaw` para descargar la carpeta `Arrays-BenfordsLaw` a tu computadora.
150
+
151
+2. Los archivos de datos  `cta-a.txt`, `cta-b.txt`,  `cta-c.txt`,  `cta-d.txt`,  y `cta-e.txt` en el directorio `data` contienen datos reales o datos falsos. Cada línea del archivo especifica el código de una ruta de guagua seguido por el número de personas que usaron la guagua en cierto día. Abre el archivo  `cta-a.txt` para que entiendas el formato de los datos. Esto será importante cuando leas los datos desde tu programa. Nota que algunos de los códigos de ruta contienen caracteres.
152
+
153
+3.  Abre el archivo `main.cpp`. Estudia la función `main` para que te asegures de que entiendes todas las partes. En esencia, la función `main` que te proveemos crea una pantalla y dibuja un histograma parecido al que se muestra en la Figura 6.
154
+    
155
+    ---
156
+
157
+     ![figure6.png](images/figure6.png)
158
+
159
+    **Figura 6.** Ventana del resultado del ejemplo provisto en el proyecto `BenfordLaw`. Se despliega un histograma utilizando los datos de los argumentos   `histoNames` e `histoValues`.
160
+
161
+    ---
162
+
163
+    Nota que los datos para los arreglos `histoNames` e `histoValues` utilizados en la invocación al método `histo` fueron asignados directamente en la declaración de cada arreglo. Para cada uno de los archivos en el directorio `data`, tu programa deberá computar la frecuencia de ocurrencia de los dígitos líderes y luego desplegar su histograma utilizando  el método `histo`.
164
+
165
+
166
+
167
+###Ejercicio 2: Implementar código para detectar datos falsificados en un archivo
168
+
169
+####Instrucciones
170
+
171
+1. Utilizando como inspiración la función `main` que te proveemos, añade funcionalidad a la función `main` para leer archivos como los provistos en el directorio `data` y determinar la frecuencia de ocurrencia de dígitos líderes  en los datos que aparecen en la segunda columna de los archivos. Computa la frecuencia de ocurrencia como se explica antes de la Figura 5.
172
+
173
+2. Una vez tu programa haya obtenido las frecuencias de los dígitos líderes, utiliza el método `histo` para desplegar un histograma. Corre el programa para cada uno de los archivos. Basado en la gráfica de distribución de frecuencia de los dígitos líderes en los datos en cada uno de los archivos, podrás determinar si (de acuerdo a la Ley de Benford)  el archivo contiene datos reales o datos falsos.
174
+
175
+---
176
+
177
+---
178
+
179
+##Entregas
180
+
181
+1. Utiliza "Entrega 1" en Moodle para entregar el archivo `main.cpp` que modificaste en el Ejercicio 2. Recuerda utilizar buenas prácticas de programación, incluir el nombre de los programadores y documentar tu programa.
182
+
183
+2. Utiliza "Entrega 2" en Moodle para entregar un archivo **pdf** que muestre fotos de los histogramas para cada uno de los archivos. Por favor, subtitula cada figura especificando el archivo que se utilizó para generarla y tu decisión sobre si el archivo contiene data real o falsificada.
184
+
185
+---
186
+
187
+---
188
+
189
+##Referencias
190
+
191
+
192
+
193
+[1] http://www.isaca.org/Journal/archives/2011/Volume-3/Pages/Understanding-and-Applying-Benfords-Law.aspx
194
+
195
+---
196
+
197
+---
198
+
199
+----
200
+

+ 2
- 376
README.md View File

@@ -1,376 +1,2 @@
1
-[English](#markdown-header-arrays-benfords-law) | [Español](#markdown-header-arreglos-ley-de-benford)
2
-
3
-#Arreglos - Ley de Benford
4
-
5
-![main1.png](images/main1.png)
6
-![main2.png](images/main2.png)
7
-![main3.png](images/main3.png)
8
-
9
-Los arreglos de datos (*arrays*) nos facilitan guardar y trabajar con grupos de datos del mismo tipo. Los datos se guardan en espacios de memoria consecutivos a los que se puede acceder utilizando el nombre del arreglo e índices o suscritos que indican la posición en que se encuentra el dato. Las estructuras de repetición nos proveen una manera simple de acceder a los datos de un arreglo. En la experiencia de laboratorio de hoy practicarás el uso de contadores y arreglos de una dimensión para implementar un programa en el que usarás la Ley de Benford para detectar   archivos con datos falsificados.
10
-
11
-
12
-
13
-##Objetivos:
14
-
15
-1. Practicar el  uso de un arreglo de contadores para determinar la frecuencia de los datos de un archivo.
16
-
17
-2. Detectar el uso de datos falsificados utilizando la distribución de frecuencia y la Ley de Benford.
18
-
19
-3. Practicar la lectura de datos de un archivo de texto.
20
-
21
-
22
-
23
-
24
-##Pre-Lab:
25
-
26
-Antes de llegar al laboratorio debes haber:
27
-
28
-
29
-1. Aprendido cómo extraer el dígito líder (primer dígito) de un número. 
30
-
31
-2. Repasado los conceptos relacionados a arreglos y contadores.
32
-
33
-3. Repasado cómo leer datos de un archivo en C++.
34
-
35
-4. Estudiado los conceptos e instrucciones para la sesión de laboratorio.
36
-
37
-5. Tomado el quiz Pre-Lab que se encuentra en Moodle.
38
-
39
----
40
-
41
----
42
-
43
-
44
-
45
-Como parte de tu nuevo trabajo de auditora de tecnología de información, tienes la sospecha de que alguien en la Autoridad Metropolitana de Autobuses (AMA) de Puerto Rico ha estado manipulando los sistemas de información y cambiando los archivos de datos que contienen los totales de pasajeros de las rutas diarias de las guaguas. Te han dado 5 archivos de texto que contienen los totales diarios de cada una de las rutas de las guaguas de la AMA y debes determinar si uno o más archivos contienen datos falsos. Para detectar cuál(es) archivos tienen datos falsos  implementarás un programa en el que usarás la Ley de Benford.
46
-
47
-
48
----
49
-
50
-## ¿Qué es la Ley de Benford? (adaptado del ISACA Journal [1])
51
-
52
-
53
-La Ley de Benford es la teoría matemática de los dígitos líderes de un número, y fue llamada así en honor al físico Frank Benford, quién trabajó en esta teoría en 1938. Específicamente, en conjuntos de datos, los dígitos líderes están distribuidos de forma no uniforme. Uno podría pensar que el número 1 aparece como primer dígito el 11% del tiempo (esto es, uno de 9 números posibles), sin embargo, este número aparece como líder alrededor del 30% del tiempo (vea la Figura 1). Por otro lado, el número 9 es el primer dígito menos del 5% del tiempo. La teoría cubre las ocurrencias del primer dígito, el segundo dígito, los primeros dos dígitos, el último dígito y otras combinaciones de dígitos porque la teoría está basada en un logaritmo de probabilidad de ocurrencia de dígitos.
54
-
55
-
56
----
57
-
58
-![figure1.png](images/figure1.png)
59
-
60
-
61
-**Figura 1.** Distribución del primer dígito en un conjunto de datos real según la Ley de Benford. Tomado de [1]. 
62
-
63
----
64
-
65
-
66
-## Cómo usar la Ley de Benford para detectar datos falsificados 
67
-
68
-En esta experiencia de laboratorio usarás la Ley de Benford aplicada solamente al primer dígito (el dígito líder). Para hacer esto, necesitas determinar la frecuencia de cada dígito líder en los números en un archivo. Supón que te dan un archivo que contiene los siguientes números enteros:
69
-
70
-
71
-
72
-
73
-```
74
-890 3412 234 143 112 178 112 842 5892 19 
75
-777 206 156 900 1138 438 158 978 238 192
76
-```
77
-
78
-
79
-Según vas leyendo cada número $$n$$, determinas su dígito líder (la manera de extraer el dígito líder de un número se deja como un ejercicio para tí). También debes estar pendiente de cuántas veces sale el dígito líder en el conjunto de datos. La manera más fácil de llevar cuenta de la cantidad de veces que aparece el 1 como líder, el 2 como líder, ... , el 9 como líder, es utilizando un *arreglo de contadores*. Este arreglo de contadores es sencillamente un arreglo de enteros en el que un elemento del arreglo se incrementa cada vez que se encuentra cierto dígito líder. Por ejemplo, para este ejercicio el arreglo de contadores puede ser un arreglo de 10 enteros, inicializado a `0`.
80
-
81
-
82
-
83
----
84
-
85
-![figure2.png](images/figure2.png)
86
-
87
-**Figura 2.** Arreglo de 10 enteros inicializado a `0`.
88
-
89
-
90
----
91
-
92
-Cada vez que se encuentra el dígito líder `d`, el elemento con índice `d` se incrementa. Por ejemplo, luego de leer los números `890` `3412` `234` `143` `112`, el contenido del arreglo sería el siguiente:
93
-
94
-
95
-----
96
-
97
-![figure3.png](images/figure3.png)
98
-
99
-**Figura 3.** Contenido del arreglo luego de leer `890` `3412` `234` `143` `112`, y contar sus dígitos líderes.
100
-
101
----
102
-
103
-Al finalizar de examinar el archivo, el contenido de cada elemento en el arreglo será el número de veces que el dígito líder aparece en los datos.
104
-
105
-
106
-
107
----
108
-
109
-![figure4.png](images/figure4.png)
110
-
111
-**Figura 4.** Contenido del arreglo de contadores luego de examinar todos los datos. 
112
-
113
----
114
-
115
-### Frecuencia de ocurrencia
116
-
117
-La **frecuencia de ocurrencia** se define como la razón del número de veces que un dígito aparece sobre el número total de datos. Por ejemplo, la frecuencia del dígito líder `1` en el ejemplo de la Figura 4 se computa como $$9/20 = 0.45$$. La manera común de visualizar las distribuciones de frecuencia de un conjunto de datos es utilizando un **histograma**. En esencia, un histograma es una gráfica de barras en la que el eje de $$y$$ es la frecuencia de ocurrencia y se dibuja una barra para cada una de las clasificaciones que se cuenta (en nuestro caso, una barra para cada dígito líder).
118
-
119
-
120
----
121
-
122
-![figure5.png](images/figure5.png)
123
-
124
-**Figura 5.** Histograma para la frecuencia de los dígitos líderes en los datos de muestra.
125
-
126
----
127
-
128
----
129
-
130
-!INCLUDE "../../eip-diagnostic/benfords-law/es/diag-benford-law-01.html"
131
-
132
-!INCLUDE "../../eip-diagnostic/benfords-law/es/diag-benford-law-02.html"
133
-
134
-!INCLUDE "../../eip-diagnostic/benfords-law/es/diag-benford-law-03.html"
135
-
136
-!INCLUDE "../../eip-diagnostic/benfords-law/es/diag-benford-law-04.html"
137
-
138
----
139
-
140
----
141
-
142
-
143
-##Sesión de laboratorio:
144
-
145
-###Ejercicio 1: Entender los archivos de datos y el código provisto
146
-
147
-####Instrucciones
148
-
149
-
150
-1. Carga a QtCreator el proyecto `BenfordsLaw`  haciendo doble "click" en el archivo `BenfordsLaw.pro` en el directorio `Documents/eip/Arrays-BenfordsLaw` de tu computadora. También puedes ir a `http://bitbucket.org/eip-uprrp/arrays-benfordslaw` para descargar la carpeta `Arrays-BenfordsLaw` a tu computadora.
151
-
152
-2. Los archivos de datos  `cta-a.txt`, `cta-b.txt`,  `cta-c.txt`,  `cta-d.txt`,  y `cta-e.txt` en el directorio `data` contienen datos reales o datos falsos. Cada línea del archivo especifica el código de una ruta de guagua seguido por el número de personas que usaron la guagua en cierto día. Abre el archivo  `cta-a.txt` para que entiendas el formato de los datos. Esto será importante cuando leas los datos desde tu programa. Nota que algunos de los códigos de ruta contienen caracteres.
153
-
154
-3.  Abre el archivo `main.cpp`. Estudia la función `main` para que te asegures de que entiendes todas las partes. En esencia, la función `main` que te proveemos crea una pantalla y dibuja un histograma parecido al que se muestra en la Figura 6.
155
-    
156
-    ---
157
-
158
-     ![figure6.png](images/figure6.png)
159
-
160
-    **Figura 6.** Ventana del resultado del ejemplo provisto en el proyecto `BenfordLaw`. Se despliega un histograma utilizando los datos de los argumentos   `histoNames` e `histoValues`.
161
-
162
-    ---
163
-
164
-    Nota que los datos para los arreglos `histoNames` e `histoValues` utilizados en la invocación al método `histo` fueron asignados directamente en la declaración de cada arreglo. Para cada uno de los archivos en el directorio `data`, tu programa deberá computar la frecuencia de ocurrencia de los dígitos líderes y luego desplegar su histograma utilizando  el método `histo`.
165
-
166
-
167
-
168
-###Ejercicio 2: Implementar código para detectar datos falsificados en un archivo
169
-
170
-####Instrucciones
171
-
172
-1. Utilizando como inspiración la función `main` que te proveemos, añade funcionalidad a la función `main` para leer archivos como los provistos en el directorio `data` y determinar la frecuencia de ocurrencia de dígitos líderes  en los datos que aparecen en la segunda columna de los archivos. Computa la frecuencia de ocurrencia como se explica antes de la Figura 5.
173
-
174
-2. Una vez tu programa haya obtenido las frecuencias de los dígitos líderes, utiliza el método `histo` para desplegar un histograma. Corre el programa para cada uno de los archivos. Basado en la gráfica de distribución de frecuencia de los dígitos líderes en los datos en cada uno de los archivos, podrás determinar si (de acuerdo a la Ley de Benford)  el archivo contiene datos reales o datos falsos.
175
-
176
----
177
-
178
----
179
-
180
-##Entregas
181
-
182
-1. Utiliza "Entrega 1" en Moodle para entregar el archivo `main.cpp` que modificaste en el Ejercicio 2. Recuerda utilizar buenas prácticas de programación, incluir el nombre de los programadores y documentar tu programa.
183
-
184
-2. Utiliza "Entrega 2" en Moodle para entregar un archivo **pdf** que muestre fotos de los histogramas para cada uno de los archivos. Por favor, subtitula cada figura especificando el archivo que se utilizó para generarla y tu decisión sobre si el archivo contiene data real o falsificada.
185
-
186
----
187
-
188
----
189
-
190
-##Referencias
191
-
192
-
193
-
194
-[1] http://www.isaca.org/Journal/archives/2011/Volume-3/Pages/Understanding-and-Applying-Benfords-Law.aspx
195
-
196
----
197
-
198
----
199
-
200
-----
201
-
202
-[English](#markdown-header-arrays-benfords-law) | [Español](#markdown-header-arreglos-ley-de-benford)
203
-
204
-#Arrays - Benford's Law
205
-
206
-![main1.png](images/main1.png)
207
-![main2.png](images/main2.png)
208
-![main3.png](images/main3.png)
209
-
210
-
211
-Arrays help us to store and work with groups of data of the same type. The data is stored in consecutive memory spaces which can be accessed by using the name of the array and indexes or subscripts that indicate the position where the data is stored. Repetition structures provide us a simple way of accessing the data within an array. In today's laboratory experience you will practice the use of counters and one dimensional arrays to implement a program in which you will use Benford’s Law to detect files with bogus data.
212
-
213
-
214
-
215
-## Objectives:
216
-
217
-1. Practice using arrays of counters to determine data frequency in a file.
218
-
219
-2. Detect the use of bogus data using Benford's Law and the leading digit frequency distribution.
220
-
221
-3. Practice reading data from text files.
222
-
223
-
224
-## Pre-Lab
225
-
226
-Before coming to the laboratory, you should have:
227
-
228
-1. Learned how to extract the leading digit (first digit from left to right) of an integer read from a file.
229
-
230
-2. Reviewed basic array and counter concepts.
231
-
232
-3. Reviewed text file input in C++.
233
-
234
-4. Studied the concepts and instructions for this laboratory session.
235
-
236
-5. Taken the Pre-Lab quiz found in Moodle.
237
- 
238
-
239
----
240
-
241
----
242
-
243
-
244
-
245
-
246
-
247
-As part of your new job as IT auditor you suspect that someone in the Chicago Transit Authority (CTA) has been tampering with the information systems and changing the data files that contain the bus route daily totals. You are given five text files that contain daily totals for each of the CTA’s bus routes and must determine if one or more of the files contain bogus data. In this laboratory experience you will implement a program that will help you determine which of the file(s) contain bogus data using Benford's Law, a property that is observed in many real-life sources of data. 
248
-
249
----
250
-
251
-## What is Benford’s Law? (copied from the ISACA journal)
252
-
253
-Benford’s Law, named for physicist Frank Benford, who worked on the theory in 1938, is the mathematical theory of leading digits. Specifically, in data sets, the leading digit(s) is (are) distributed in a specific, non uniform way. While one might think that the number 1 would appear as the first digit 11 percent of the time (i.e., one of nine possible numbers), it actually appears about 30 percent of the time (see Figure 1). The number 9, on the other hand, is the first digit less than 5 percent of the time. The theory covers the first digit, second digit, first two digits, last digit and other combinations of digits because the theory is based on a logarithm of probability of occurrence of digits.
254
-
255
----
256
-
257
-![figure1.png](images/figure1.png)
258
-
259
-**Figure 1.** Distribution of the leading digit in a real data set according to Benford’s Law. Taken from [1]. 
260
-
261
----
262
-
263
-
264
-### How to use Benford's Law to spot bogus data
265
-
266
-
267
-In this laboratory experience you will use Benford's Law applied only to the leading digit. To do this, you need to determine the frequency of each leading digit in the numbers of the file. Suppose that you are given a file that contains the following integer numbers:
268
-
269
-```
270
-890 3412 234 143 112 178 112 842 5892 19 
271
-777 206 156 900 1138 438 158 978 238 192
272
-```
273
-
274
-As you read each number $$n$$, you determine its leading digit (how to extract the leading digit is left as an exercise for you). You must also keep track of how many times the same leading digit appears in the data set. The easiest way to keep track of how many times you find a leading 1, a leading 2, ... a leading 9, is to use an *array of counters*. This array of counters is simply an array of integers where each element is incremented whenever you find a certain leading digit. For instance, for this exercise the array of counters can be an array of 10 integers, initialized to `0`. 
275
-
276
----
277
-
278
-![figure2.png](images/figure2.png)
279
-
280
-**Figure 2.** Array of 10 integers initialized to `0`.
281
-
282
----
283
-
284
-
285
-Every time a leading digit `d` is found, the element with index `d` is incremented. For example, after reading the numbers  `890`, `3412`, `234`, `143`, and `112`, the array content would be:
286
-
287
-----
288
-
289
-![figure3.png](images/figure3.png)
290
-
291
-**Figure 3.** Contents of the array after reading 890, 3412, 234, 143, 112 and counting their leading digits.
292
-
293
----
294
-
295
-
296
-After reading through all the data, the content of each array element will be the number of times that leading digit appears in the data.
297
-
298
----
299
-
300
-![figure4.png](images/figure4.png)
301
-
302
-**Figure 4.** Contents of the array after reading all the data.
303
-
304
----
305
-
306
-The **frequency of occurrence** is defined as the ratio of times that a digit appears divided by the total number of data.  For example, the frequency of leading digit `1` in the example would computed as $$9 / 20 = 0.45$$.  **Histograms** are the preferred visualization of frequency distributions in a data set. In essence, a histogram is a bar chart where the $$y$$-axis is the frequency and a vertical bar is drawn for each of the counted classifications (in our case, for each digit). 
307
-
308
----
309
-
310
-![figure5.png](images/figure5.png)
311
-
312
-**Figure 5.** Histogram of the frequency of leading digits in the example data.
313
-
314
----
315
-
316
----
317
-
318
-!INCLUDE "../../eip-diagnostic/benfords-law/en/diag-benford-law-01.html"
319
-
320
-!INCLUDE "../../eip-diagnostic/benfords-law/en/diag-benford-law-02.html"
321
-
322
-!INCLUDE "../../eip-diagnostic/benfords-law/en/diag-benford-law-03.html"
323
-
324
-!INCLUDE "../../eip-diagnostic/benfords-law/en/diag-benford-law-04.html"
325
-
326
----
327
-
328
----
329
-
330
-##Laboratory session
331
-
332
-###Exercise 1: Familiarizing yourself with the data files and the provided code 
333
-
334
-####Instructions
335
-
336
-1. Load the project `BenfordsLaw` onto QtCreator by double clicking the file `BenfordsLaw.pro` in the folder `Documents/eip/Arrays-BenfordsLaw` on your computer. You can also go to `http://bitbucket.org/eip-uprrp/arrays-benfordslaw` to download the `Arrays-BenfordsLaw` folder to your computer.
337
-
338
-2. The text files `cta-a.txt`, `cta-b.txt`,  `cta-c.txt`,  `cta-d.txt`,  and `cta-e.txt` in the `data` directory contain either real or bogus data. Each line of the file specifies the bus route code and the number of users for that route on a certain day. Open the file `cta-a.txt` to understand the data format. This will be important when reading the file sequentially using C++. Notice that some of the route codes contain characters.
339
-
340
-3. Open the `main.cpp` file. Study the `main` function and make sure that you understand all of its parts. In essence, the provided `main` function creates a window that displays a histogram like the one shown in Figure 6.
341
-
342
- ---
343
-
344
-  ![figure6.png](images/figure6.png)
345
-
346
-    **Figure 6.** Result of running the provided program. A histogram is displayed using the data in the arguments `histoNames` and `histoValues`.
347
-
348
-    ---
349
-
350
-In the provided code, notice that the data in the arrays `histoNames` and `histoValues` were assigned directly in their declarations. For the provided files, your program should compute the frequency of occurrence of the leading digits and then display their histogram by using the `histo` method.  
351
-
352
-###Exercise 2: Implement a program to detect bogus data in the data files
353
-
354
-####Instructions
355
-
356
-1. Using the provided `main` function as inspiration, add the necessary code to implement a program that reads a text data file like the ones in the `data` folder and determines the frequency of occurrence of the leading digits of the second column of the files. Compute the frequency of occurrence as it was explained before Figure 5.
357
-
358
-2. Once your program has the frequency of occurrence of the leading digits, use the method `histo` to display the histogram. Run the program for each of the text files. Based on the leading digit frequency distribution for each file, decide if (according to Benford’s Law) the file contains real or bogus data.
359
-
360
----
361
-
362
----
363
-
364
-##Deliverables
365
-
366
-1. Use "Deliverables 1" in Moodle to upload the `main.cpp` file with the modifications you made in **Exercise 2**. Remember to use good programming techniques, include the names of the programmers involved, and to document your program.
367
-
368
-2. Use "Deliverables 2" in Moodle to upload a **pdf** file that contains screen shots of the histograms produced after analyzing each text file. Please caption each figure with the name of the text file and provide your decision as to whether the file contained real or bogus data.
369
-
370
----
371
-
372
----
373
-
374
-##References
375
-
376
-[1] http://www.isaca.org/Journal/archives/2011/Volume-3/Pages/Understanding-and-Applying-Benfords-Law.aspx
1
+## [\[English\]](README-en.md) - for README in English
2
+## [\[Spanish\]](README-es.md) - for README in Spanish