-
Notifications
You must be signed in to change notification settings - Fork 0
/
gaussian.py
57 lines (51 loc) · 1.83 KB
/
gaussian.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
import numpy as np
import argparse
import pandas as pd
import matplotlib.pyplot as plt
from scipy import optimize
import model
def gaussian(training_data):
columns = np.zeros((21,2))
rows = np.zeros((21,2))
for i in range(len(training_data)):
for j in range(len(training_data[i])):
if (not np.isnan(training_data[i][j])):
columns[j,0] += training_data[i][j]
columns[j,1] += 1
rows[i,0] += training_data[i][j]
rows[i,1] += 1
for i in columns:
i[0] = i[0] / i[1]
for i in rows:
i[0] = i[0] / i[1]
print(columns)
print(rows)
results = np.zeros((21,21))
for i in range(len(training_data)):
for j in range(len(training_data)):
if(np.isnan(training_data[i][j])):
results[i][j] = (columns[i,0] + rows[j,0]) / 2
else:
results[i][j] = (columns[i,0] + rows[j,0] + training_data[i][j] * 5)/7
return results
def main():
"""Fill in a multiplication table and visualize it. """
parser = argparse.ArgumentParser("Get predicted multiplication times.")
parser.add_argument('filename', nargs='?', default='data.csv', type=str)
args = parser.parse_args()
training_data = pd.read_csv(args.filename)
training_table = model.to_table(training_data)
reconstructed = gaussian(training_table)
#print(matrix1)
#print(matrix2)
print(training_table)
fig, (axes1, axes2) = plt.subplots(1, 2, figsize=(20, 20), sharex=True, sharey=True)
fig2, (axes3, axes4) = plt.subplots(1, 2, figsize=(20, 20))
model.plot_table(training_table, axes1)
model.plot_table(reconstructed, axes2)
#model.plot_table(matrix1, axes3)
#model.plot_table(matrix2, axes4)
# fig.savefig('reconstructed.png')
plt.show()
if __name__ == '__main__':
main()