@EricHolloway/

Probability of Positive Generalized Information

Python 2.7

Use binomial coefficient to calculate probability of positive generalized information.

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
import math
def nCk(n,k):
    f = math.factorial
    return f(n) / f(k) / f(n-k)

def log2(n): return math.log(n,2)

bits = 8

model_size = (bits+1)*4+1

bs_len = 2**bits
n = bs_len

expt_gi = 0
prob_pos_gi = 0
for k in range(n):
    gi_prob = nCk(n,k)/float(2**n)
    act_prob = k/float(n)
    act_prob = max(act_prob, 1-act_prob)
    act_info = (1+log2(act_prob))*n
    gen_info = act_info - model_size
    if gen_info > 0:
        prob_pos_gi += gi_prob
    expt_gi += gi_prob*gen_info

print "Expected generalized information: " + str(round(expt_gi,2))
print "Probability of positive GI: " + str(round(prob_pos_gi*100,2))+"%"