-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtransmitter.py
More file actions
57 lines (45 loc) · 1.62 KB
/
transmitter.py
File metadata and controls
57 lines (45 loc) · 1.62 KB
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
'''
Module for class Transmitter. A transmitter is essentially a hypothesis
'''
import numpy as np
class Transmitter:
'''Encapsulate a transmitter
Attributes:
x (int): location - first dimension
y (int): location - second dimension
mean_vec (np.ndarray): mean vector, length is the number of sensors
mean_vec_sub (np.ndarray): mean vector for subset of sensors
multivariant_gaussian(scipy.stats.multivariate_normal):
each hypothesis corresponds to a multivariant guassian distribution
'''
def __init__(self, x, y):
self.x = x
self.y = y
self.hypothesis = 0
self.mean_vec = np.zeros(0)
self.mean_vec_sub = np.zeros(0)
self.multivariant_gaussian = None
self.error = 0
def set_mean_vec_sub(self, subset_index):
'''Given a subset_index list, set the mean_vec_sub
Attributes:
subset_index (list): a list of index
'''
self.mean_vec_sub = self.mean_vec[subset_index]
def write_mean_vec(self, filename):
'''append the mean vector to filename
'''
with open(filename, 'a') as f: # when the file already exists, it will not overwirte
f.write(str(self.mean_vec) + '\n')
def add_error(self):
'''Error counter
'''
self.error += 1
def __str__(self):
str1 = "(%d, %d) ".ljust(10) % (self.x, self.y)
return str1 + str(self.error)
if __name__ == '__main__':
transmitter = Transmitter(3, 5)
transmitter2 = Transmitter(7, 9)
print(transmitter)
print(transmitter2)