@EricHolloway/

# Random Generalized Information

## An example showing that GI can be found in a random bitstring.

Files
• main.py
main.py
```1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
```
```from random import randint
from random import sample
from math   import log, ceil

num_bits = 8
bs_len = 2**num_bits
bs = set([(n, randint(0,1)) for n in range(bs_len)])

active_info = 0
model_size = 0
def calcGI(bs, i, j):
global active_info
global model_size
in_cls0 = 0
in_cls1 = 0
out_cls0 = 0
out_cls1 = 0

for b in bs:
if i <= b[0] <= j:
if b[1] == 0:
in_cls0 += 1
else:
in_cls1 += 1
else:
if b[1] == 0:
out_cls0 += 1
else:
out_cls1 += 1

in_max = max(in_cls0, in_cls1)
out_max = max(out_cls0, out_cls1)
acc = (in_max + out_max)/float(len(bs))

active_info = (1+log(acc,2))*len(bs)
model_size = (ceil(log(i+1,2)) + ceil(log(j-i,2)))*2 + 1 + (num_bits+1)*2

GI = active_info - model_size
return GI

max_GI = 0
max_AI = 0
for i in range(bs_len):
for j in range(i+1, bs_len):
GI = calcGI(bs, i, j)
if GI > max_GI:
max_GI = GI
print GI
```