-
Notifications
You must be signed in to change notification settings - Fork 0
/
binary_inputs.py
47 lines (33 loc) · 1.25 KB
/
binary_inputs.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
import numpy as np
import itertools
class b_input:
def __init__(self, size):
'''
Object that holds all possible binary inputs of size n and maps them.
size - size of the input
'''
self.n = size
self.inputs = self.generate_inputs()
self.inputs.sort(key = lambda x: sum(x))
#self.class_to_output, self.output_to_class = self.generate_output_class_maps()
def generate_inputs(self):
'''
Generates all the possible inputs of size n.
'''
return list(itertools.product([0, 1], repeat=self.n))
def generate_output_class_maps(self):
'''
Generates output class and class output maps.
There are 2^2^n possible output classes.
'''
output_class_map = {}
class_output_map = {}
outputs = list(itertools.product([0, 1], repeat=2**self.n))
classes = list(range(0,2**(2**self.n)))
output_to_class = dict(zip(outputs,classes))
class_to_output = dict(zip(classes, outputs))
return class_to_output, output_to_class
def get_output_from_class(self, clas):
return self.class_to_output[clas]
def get_class_from_output(self, output):
return self.output_to_class[output]