-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnalysis.py
124 lines (96 loc) · 4.21 KB
/
Analysis.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
__author__ = 'cyberbeast'
__author__ = 'Sandesh'
from CustomClasses.Chromosome import *
import glob
from bokeh.plotting import figure, output_file, show
from mpl_toolkits.mplot3d import Axes3D
import matplotlib as mpl
import matplotlib.pyplot as plt
from numpy.random import rand
from multiprocessing import Pool, Process, Manager
import numpy
import pandas as pd
filelist = []
y_val_imag = []
y_val_real = []
y_val = []
x_val = []
x1_val = [x for x in range(22)]
def plot1():
mpl.rcParams['legend.fontsize'] = 10
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(y_val_real, y_val_imag, x_val, c='r', marker='o')
ax.set_xlabel("Real")
ax.set_ylabel("Imaginary")
ax.set_zlabel("Chromosome")
ax.set_zlim3d(1, 22)
plt.show()
for name in glob.glob('GenomeDataset/Processing/*pChromosome'):
filelist.append(name)
if len(filelist) == 0:
for name in glob.glob('GenomeDataset/Processing/*pTREE'):
filelist.append(name)
df_vis1 = pd.DataFrame(columns=('Real', 'Imaginary'))
df_vis2 = pd.DataFrame()
rows = []
i = 1
with open('Visualizer/output-file.txt', 'w') as outf:
for infile in filelist:
if "pChromosome" not in infile:
ch = Chromosome()
ch.analyze(infile)
else:
with open(infile, 'rb') as in_fh:
ch = Chromosome()
ch = pickle.load(in_fh)
y_val = ch.calculate_eigen_values()
y_val_real.append(y_val.real)
y_val_imag.append(y_val.imag)
x_val.append([i for _ in range(len(y_val))])
y_r = [y.real for y in y_val.tolist()] # List of all real values from EV calculation for current chromosome
y_i = [y.imag for y in y_val.tolist()] # List of all imaginary values from EV calculation for current chromosome
# Populate intermediate list to store Analysis 1 DataFrame data
for rr, ri in zip(y_r, y_i):
rows.append((str(rr), str(ri)))
y_r_square = [real**2 for real in y_r]
y_i_square = [imag**2 for imag in y_i]
# Define and populate list of data for Analysis 2 DataFrame
y_sqrt_of_sum_of_R_I_list = []
for rr2, ri2 in zip(y_r_square, y_i_square):
y_sqrt_of_sum_of_R_I_list.append(np.sqrt(rr2 + ri2))
# Populate Analysis 2 DataFrame with current chromosome
df_vis2["C" + str(i)] = y_sqrt_of_sum_of_R_I_list
i += 1
# Analysis 1 DataFrame Operations
for row in rows:
df_vis1.loc[len(df_vis1)] = row
df_vis1.to_csv('Visualizer/real-vs-imaginary.csv')
# ---------------------------------------------------------------------------------------------------------------------
# Analysis 2 DataFrame Operations
df_vis2.to_csv('Visualizer/squareroot-of-sum-of-squares-of-real-and-imaginary.csv')
# ---------------------------------------------------------------------------------------------------------------------
# Uncomment next line for 3D plot of preliminary results
# plot1()
# ********************************************************************************************************************
# ********************************************************************************************************************
# ********************************************************************************************************************
# ********************************************************************************************************************
# ********************************************************************************************************************
# ********************************************************************************************************************
# Alpha Build Code from here onwards (18/09/2015)
data_collection_vis2 = pd.read_csv(open("Visualizer/squareroot-of-sum-of-squares-of-real-and-imaginary.csv"),)
y = data_collection_vis2.as_matrix
x = np.array([val1 for val1 in range(0, 340)])
# y_temp = np.array(np.sqrt(np.square(y_val_real) + np.square(y_val_imag)))
# y = y_temp[0]
# y = y_temp
# print(len(y))
# x = temp_x.flatten()
# print(x.shape)
p = np.poly2d(np.polyfit(x, y, 50))
p30 = np.poly2d(np.polyfit(x, y, 100))
xp = np.linspace(0, 340)
print(p)
_ = plt.plot(x, y, '.', xp, p(xp), '-', xp, p30(xp), '--')
plt.show()