-
Notifications
You must be signed in to change notification settings - Fork 1
/
stats_pentanomial.py
53 lines (39 loc) · 1013 Bytes
/
stats_pentanomial.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
from __future__ import division
import random
def var(probs):
l = len(probs)
s = score(probs) * (l - 1) / 2
v = sum([probs[i] * (i / 2 - s) ** 2 for i in range(0, l)])
return v / ((l - 1) / 2)
def score(probs):
l = len(probs)
s = sum([probs[i] * (i / 2) for i in range(0, l)])
return s / ((l - 1) / 2)
def add(lists):
l = len(lists)
l1 = len(lists[0])
s = l1 * [0]
for i in range(0, l1):
s[i] = 0
for j in range(0, l):
s[i] += lists[j][i]
return s
def mult_scalar(scalar, l):
return [scalar * ll for ll in l]
def avg(lists):
l = add(lists)
return mult_scalar(1 / len(lists), l)
def pick(probs):
s = random.random()
p = 0
for i in range(0, len(probs)):
pp = probs[i]
p += pp
if p >= s:
return i
def trinomial_to_pentanomial(ldw1, ldw2):
p = 5 * [0]
for i in range(0, 3):
for j in range(0, 3):
p[i + j] += ldw1[i] * ldw2[j]
return p