Skip to content

Commit e4b6a23

Browse files
committed
Indicator1: Max hours/min dtw done
1 parent 10dd34f commit e4b6a23

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

utils/AnalysisObjs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import os
99
import os.path as op
1010
import swmmtoolbox as swmtbx
11-
from components import bcpl
11+
from components import bcpl
1212

1313
from collections import OrderedDict
1414
import random

utils/Wetlands.py

+25-16
Original file line numberDiff line numberDiff line change
@@ -44,36 +44,46 @@ def indicator(self, cutoff=-2500, show=False):
4444
print ('Wetland cells: {}'.format(np.count_nonzero(~np.isnan(self.mat_wetlands))))
4545
return mat_indicator
4646

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+
4850
df_ind = pd.DataFrame(mat_indicator.reshape(-1)).dropna()
4951
df_wet = pd.DataFrame(self.mat_wetlands.reshape(-1)).dropna()
5052

5153
## get count of how many correct
52-
count_correct = (sum(df_wet.index.isin(df_ind.index)))
54+
count_correct = (len(mat_ind))
5355
## 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))
5557
# print ('Correct: {}'.format(count_correct))
5658
# print ('Incorrect: {}'.format(count_incorrect))
5759

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)
6364

6465
def optimize(self, increment=1):
6566
""" Maximize the percent correctly identiified """
66-
optimal = []
67-
cutoff = []
67+
optimal = []
68+
cutoff = []
69+
n_correct = []
70+
n_incorrect = []
6871
for test in np.arange(np.floor(np.nanmin(self.mat_dtw_sum)), 0, increment):
6972
# print('Cutoff: {}'.format(test))
70-
result = self.indicator(test)
73+
result, n_corr, n_incorr = self.indicator(test)
7174
optimal.append(result)
75+
n_correct.append(n_corr)
76+
n_incorrect.append(n_incorr)
7277
cutoff.append(test)
7378

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]))
7787

7888
def plot_indicators(self, cut=-2500):
7989
"""
@@ -166,5 +176,4 @@ def dtw_wet_avg_ann(self):
166176
PATH_res = op.join(op.expanduser('~'), 'Google_Drive',
167177
'WNC', 'Wetlands_Paper', 'Results_Default')
168178
res = Wetlands(PATH_res)
169-
# res.optimize()
170-
res.plot_indicators()
179+
res.optimize(increment=10)

0 commit comments

Comments
 (0)