-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmmp.py
45 lines (29 loc) · 1.06 KB
/
mmp.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
import random as rand
from util import *
class MMP():
''' Abstract MMP class '''
def __init__(self):
raise Exception("abstract class")
def generate(self, k):
''' Generate k level-1 encodings '''
return [self.sample([i]) for i in range(k)]
def multiply(self, encodings, *args):
''' Multiplies encodings and args '''
result = 1
for c in encodings:
result *= c
return result
def run(self, k, of_zero = False):
''' Generates k level-1 encodings, multiplies them'''
''' Will return a level-k encoding of 0 if of_zero=True '''
encodings = self.generate(k - of_zero)
if of_zero:
encodings.append(self.zero([k-1]))
return self.multiply(encodings)
def test_mmap(self, k, no_tests):
passes = 0
for i in range(no_tests):
with_zero = rand.choice([True, False])
result = self.run(k, of_zero = with_zero)
passes += self.is_zero(result) == with_zero # add 1 if it passes
return passes