@EricHolloway/

Random Generalized Information Only In Range

Python 2.7

Similar to other RGI script, except this only calculates GI for the range.

fork
loading
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
from random import randint
from random import sample
from math   import log, ceil

num_bits = 7
bs_len = 2**num_bits
bs = [randint(0,1) for _ in range(bs_len)]

acc = 0
active_info = 0
model_size = 0
def calcGI(bs, i, j):
    global acc
    global active_info
    global model_size

    acc = sum(bs[i:j])/float(j-i)
    acc = max(acc, 1-acc)

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

    GI = active_info - model_size
    return GI

total = 0
failures = 0
for i in range(bs_len):
    for j in range(i+1, bs_len):
        GI = calcGI(bs, i, j)
        if GI > 0:
            failures += 1
        total += 1
        
print failures,"/",total