@EricHolloway/

ASC AGI Violations

Python 2.7

Script to demonstrate that adjusted GI based on ASC is not easy to generate randomly.

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import sys
from random import randint
from random import sample
from math   import log, ceil

def calc_err_penalty(errs, num_bits):
    if errs == 0:
        return 0
    penalty = ceil(log(errs,2)+1)*2
    penalty += errs*num_bits
    return penalty

def calcAGI(bs, i, j, num_bits):
    err = 0
    ASC = 0
    model_size = 0

    err = sum(bs[i:j])
    err = min(err, j-i-err)

    I = j-i
    K = calc_err_penalty(err, num_bits)
    ASC = I - K
    
    model_size = ((ceil(log(i+1,2))+1) + (ceil(log(j-i,2))+1))*2 + 1

    resources = 2*(num_bits+1)
    
    AGI = ASC - model_size - resources

    if AGI > 0:
        print I, K, model_size, resources, AGI
    
    return AGI

if __name__ == "__main__":
    num_bits = 6
    if len(sys.argv) > 1:
        num_bits = int(sys.argv[1])
        
    bs_len = 2**num_bits
    bs = [randint(0,1) for _ in range(bs_len)]

    max_range_len = bs_len
    if len(sys.argv) > 2:
        max_range_len = int(sys.argv[2])
    
    total = 0
    failures = 0
    for i in range(bs_len):
        for j in range(1, min(bs_len-i, max_range_len)):
            AGI = calcAGI(bs, i, i+j, num_bits)
            if AGI > 0:
                failures += 1
            total += 1
            
    print "Violations:",failures,"/",total