-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathICA_inspect.py
90 lines (76 loc) · 3.19 KB
/
ICA_inspect.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
import ICAize
import stack
import matplotlib.pyplot as plt
import numpy as np
import random_forest_spectra as rfs
import sklearn.metrics as sm
import sys
import os.path
import pickle
path = '.'
if len(sys.argv) == 2:
path = sys.argv[1]
fastica = ICAize.unpickle_FastICA(target_type="combined", filter_str="both")
for comp_i in range(min(fastica.components_.shape[0], 25)):
scale_factor = 2.4/np.max(np.abs(fastica.components_[comp_i]))
plt.plot(stack.skyexp_wlen_out, (fastica.components_[comp_i]*scale_factor)+(5*comp_i) )
plt.show()
plt.close()
fastica = ICAize.unpickle_FastICA(target_type="combined", filter_str="em")
for comp_i in range(min(fastica.components_.shape[0], 25)):
scale_factor = 2.4/np.max(np.abs(fastica.components_[comp_i]))
plt.plot(stack.skyexp_wlen_out, (fastica.components_[comp_i]*scale_factor)+(5*comp_i) )
plt.show()
plt.close()
fastica = ICAize.unpickle_FastICA(target_type="combined", filter_str="nonem")
for comp_i in range(min(fastica.components_.shape[0], 25)):
scale_factor = 2.4/np.max(np.abs(fastica.components_[comp_i]))
plt.plot(stack.skyexp_wlen_out, (fastica.components_[comp_i]*scale_factor)+(5*comp_i) )
plt.show()
plt.close()
#c_sources, c_mixing, c_exposures, c_wavelengths = rfs.load_spectra_data('.',
# target_type='combined', use_spca=False)
'''
loaded_pickle = False
output = None
try:
output = open(os.path.join(path, 'combined_flux_arr.pkl'), 'rb')
comb_flux_arr = pickle.load(output)
loaded_pickle = True
except:
comb_flux_arr, comb_exposure_arr, comb_ivar_arr, comb_masks, comb_wavelengths = \
ICAize.load_all_in_dir(path, use_con_flux=False, recombine_flux=False,
pattern="stacked*exp??????.csv", ivar_cutoff=0)
finally:
if output is not None:
output.close()
if not loaded_pickle:
output = open(os.path.join(path, 'combined_flux_arr.pkl'), 'wb')
pickle.dump(comb_flux_arr, output)
output.close()
transformed = fastica.transform(comb_flux_arr)
recovered_sources = fastica.inverse_transform(transformed)
#vw_explvar = sm.explained_variance_score(comb_flux_arr, recovered_sources, multioutput="variance_weighted")
uw_explvar = sm.explained_variance_score(comb_flux_arr, recovered_sources) #, multioutput="uniform_average")
#vw_r2 = sm.r2_score(comb_flux_arr, recovered_sources, multioutput="variance_weighted")
uw_r2 = sm.r2_score(comb_flux_arr, recovered_sources) #, multioutput="uniform_average")
mse = sm.mean_squared_error(comb_flux_arr, recovered_sources) #, multioutput="uniform_average")
print transformed.shape
print uw_explvar #, vw_explvar
print uw_r2 #, vw_r2
print mse
'''
'''
fastica = ICAize.unpickle_PCA(target_type="combined")
for comp_i in range(min(fastica.components_.shape[0], 10)):
scale_factor = 2.4/np.max(np.abs(fastica.components_[comp_i]))
plt.plot(stack.skyexp_wlen_out, (fastica.components_[comp_i]*scale_factor)+(5*comp_i) )
plt.show()
plt.close()
fastica = ICAize.unpickle_SPCA(target_type="combined")
for comp_i in range(min(fastica.components_.shape[0], 10)):
scale_factor = 2.4/np.max(np.abs(fastica.components_[comp_i]))
plt.plot(stack.skyexp_wlen_out, (fastica.components_[comp_i]*scale_factor)+(5*comp_i) )
plt.show()
plt.close()
'''