-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCombineAlgorithm.py
86 lines (65 loc) · 2.85 KB
/
CombineAlgorithm.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from SamplesXY import SamplesXY
from Source import Source
from CombinedSample import CombinedSample
class CombineAlgorithm:
def __init__(self):
self.next_value_x = 0
self.next_value_y = 0
self.next_value = None
self.next_value_source_sample = None
self.attributions_list = []
self.combined_sample_list = []
self.x_index = 0
self.y_index = 0
self.samples_x_y_object: SamplesXY | None = None
def are_there_more_items_left(self):
return self.x_index + self.y_index < self.samples_x_y_object.sample_size_x_y
def increment_x_index(self):
self.x_index += 1
def increment_y_index(self):
self.y_index += 1
def order(self):
self.samples_x_y_object.sample_x.sort()
self.samples_x_y_object.sample_y.sort()
@staticmethod
def get_next_value(sample, sample_size, index):
return sample[index] if index < sample_size else float('inf')
def append_to_test_sample(self, next_value, from_sample):
self.combined_sample_list.append(next_value)
self.attributions_list.append(from_sample)
def get_next_value_x(self):
self.next_value_x = self.get_next_value(self.samples_x_y_object.sample_x, self.samples_x_y_object.sample_size_x,
self.x_index)
def get_next_value_y(self):
self.next_value_y = self.get_next_value(self.samples_x_y_object.sample_y, self.samples_x_y_object.sample_size_y,
self.y_index)
def is_next_x_less_than_y(self):
return self.next_value_x <= self.next_value_y
def append_next_x_value_to_test_sample(self):
self.append_to_test_sample(self.next_value_x, Source.FORM_SAMPLE_X)
def append_next_y_value_to_test_sample(self):
self.append_to_test_sample(self.next_value_y, Source.FORM_SAMPLE_Y)
def combine_samples(self):
self.order()
while self.are_there_more_items_left():
self.get_next_value_x()
self.get_next_value_y()
if self.is_next_x_less_than_y():
self.append_next_x_value_to_test_sample()
self.increment_x_index()
else:
self.append_next_y_value_to_test_sample()
self.increment_y_index()
def visit(self, samples_x_y_object):
self.samples_x_y_object = samples_x_y_object
self.combine_samples()
def output_test_sample(self):
print(self.combined_sample_list)
print(self.attributions_list)
def get_combined_sample(self):
return CombinedSample(self.combined_sample_list, self.attributions_list)
if __name__ == '__main__':
algorithm = CombineAlgorithm()
samples_x_y = SamplesXY(sample_x=[3, 3, 5, 7], sample_y=[3, 4, 4, 6])
samples_x_y.run(algorithm)
algorithm.output_test_sample()