@@ -44,36 +44,46 @@ def indicator(self, cutoff=-2500, show=False):
44
44
print ('Wetland cells: {}' .format (np .count_nonzero (~ np .isnan (self .mat_wetlands ))))
45
45
return mat_indicator
46
46
47
- ### REFACTOR THIS FOR SPEED ###
47
+ mask_wet = np .isnan (self .mat_wetlands .reshape (- 1 ))
48
+ mat_ind = mat_indicator [~ mask_wet & ~ np .isnan (mat_indicator )]
49
+
48
50
df_ind = pd .DataFrame (mat_indicator .reshape (- 1 )).dropna ()
49
51
df_wet = pd .DataFrame (self .mat_wetlands .reshape (- 1 )).dropna ()
50
52
51
53
## get count of how many correct
52
- count_correct = (sum ( df_wet . index . isin ( df_ind . index ) ))
54
+ count_correct = (len ( mat_ind ))
53
55
## get count of how many incorrect
54
- count_incorrect = (len (df_ind ) - count_correct )
56
+ count_incorrect = (len (mat_indicator [ ~ np . isnan ( mat_indicator )]) - len ( mat_ind ) )
55
57
# print ('Correct: {}'.format(count_correct))
56
58
# print ('Incorrect: {}'.format(count_incorrect))
57
59
58
-
59
- ## performance
60
- performance = (count_correct - count_incorrect ) / float (len (df_wet )) * 100
61
- # print ('Percent correctly identified: {} %\n'.format(round(performance, 3)))
62
- return performance
60
+ # performance = (float(count_correct) / float(count_incorrect) * 100.
61
+ performance = (count_correct - count_incorrect ) / float (np .count_nonzero (~ mask_wet )) * 100
62
+ # print ('Percent corretly identified: {} %\n'.format(round(performance, 3)))
63
+ return (performance , count_correct , count_incorrect )
63
64
64
65
def optimize (self , increment = 1 ):
65
66
""" Maximize the percent correctly identiified """
66
- optimal = []
67
- cutoff = []
67
+ optimal = []
68
+ cutoff = []
69
+ n_correct = []
70
+ n_incorrect = []
68
71
for test in np .arange (np .floor (np .nanmin (self .mat_dtw_sum )), 0 , increment ):
69
72
# print('Cutoff: {}'.format(test))
70
- result = self .indicator (test )
73
+ result , n_corr , n_incorr = self .indicator (test )
71
74
optimal .append (result )
75
+ n_correct .append (n_corr )
76
+ n_incorrect .append (n_incorr )
72
77
cutoff .append (test )
73
78
74
- res_pairs = list (zip (optimal , cutoff ))
75
- optimal = (max (res_pairs , key = lambda item :item [0 ]))
76
- print (round (optimal [0 ], 4 ), optimal [1 ])
79
+ results = list (zip (optimal , n_correct , n_incorrect , cutoff ))
80
+ optimal = (max (results , key = lambda item :item [0 ]))
81
+ # sorted_by_incorrect = sorted(results, reverse=True, key=lambda item: item[0])
82
+
83
+ print ('Performance? {}' .format (round (optimal [0 ], 4 )))
84
+ print ('Correct: {}' .format (optimal [1 ]))
85
+ print ('Incorrect: {}' .format (optimal [2 ]))
86
+ print ('Cutoff: {}' .format (optimal [3 ]))
77
87
78
88
def plot_indicators (self , cut = - 2500 ):
79
89
"""
@@ -166,5 +176,4 @@ def dtw_wet_avg_ann(self):
166
176
PATH_res = op .join (op .expanduser ('~' ), 'Google_Drive' ,
167
177
'WNC' , 'Wetlands_Paper' , 'Results_Default' )
168
178
res = Wetlands (PATH_res )
169
- # res.optimize()
170
- res .plot_indicators ()
179
+ res .optimize (increment = 10 )
0 commit comments