SNABSuite  0.x
Spiking Neural Architecture Benchmark Suite
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Functions | Variables
show_csv Namespace Reference

Functions

def print_tabular ()
 
def plot_tabular ()
 

Variables

 parser = argparse.ArgumentParser()
 
 help
 
 required
 
 type
 
 int
 
 default
 
 bool
 
 str
 
 args = parser.parse_args()
 
 path = args.out
 
tuple figsize = (7, 8)
 
 cols = list(pd.read_csv(args.path, nrows=1))
 
list filter_in = [re.compile('[\w]*_weight'), re.compile('accuracy'), re.compile('pool_delay')]
 
 csv_data = pd.read_csv(args.path, usecols=[i for i in cols if any(re.match(fil, i) for fil in filter_in)])
 
list data = []
 
 uni_accuracies = np.unique(data[-1])
 

Function Documentation

def show_csv.plot_tabular ( )

Definition at line 103 of file show_csv.py.

104  for idx in range(len(cols)):
105  for idx2 in range(idx + 1, len(cols)):
106  unique1 = np.unique(data[idx])
107  unique2 = np.unique(data[idx2])
108  if len(unique2) < len(unique1):
109  tmp = idx
110  idx = idx2
111  idx2 = tmp
112  tmp = unique1
113  unique1 = unique2
114  unique2 = tmp
115  fig, axs = plt.subplots(nrows=len(unique2), ncols=len(unique1), sharex='all', sharey='all', figsize=figsize)
116  fig.suptitle(f'↓ {cols[idx2]} → {cols[idx]}')
117  for uni1_idx, uni1 in enumerate(unique1):
118  for uni2_idx, uni2 in enumerate(unique2):
119  acc_sum = list(np.zeros(uni_accuracies.shape))
120  for ind, acc in enumerate(uni_accuracies):
121  count_acc = [True for dat in data.transpose()
122  if dat[idx] == uni1 and dat[idx2] == uni2 and dat[-1] == acc]
123  acc_sum[ind] = len(count_acc)
124  avg_acc = uni_accuracies - uni_accuracies[0]
125  avg_acc = avg_acc/uni_accuracies[-1]
126  avg_acc = list(map(mul, acc_sum, avg_acc))
127  avg_acc = sum(avg_acc)/sum(acc_sum)
128  acc_sum = np.cumsum(acc_sum)
129  hue = (-(1/3)+avg_acc/3)+1
130  hsv_colors = (hue, 1, 1)
131  ax = axs[uni2_idx][uni1_idx]
132  ax.plot(uni_accuracies, acc_sum, c=mpc.hsv_to_rgb(hsv_colors))
133  ax.grid()
134  if uni2_idx == 0:
135  ax.set_title(f'{uni1:.4f}')
136  if uni1_idx == 0:
137  ax.set_ylabel(f'{uni2:.4f}')
138  os.makedirs(path, exist_ok=True)
139  plt.savefig(f'{path}/{cols[idx2]}_{cols[idx]}.png', bbox_inches='tight')
140 
141  if idx2 < idx:
142  tmp = idx
143  idx = idx2
144  idx2 = tmp
145 
146 
148 plot_tabular()
149 
def plot_tabular()
Definition: show_csv.py:103
def print_tabular()
Definition: show_csv.py:45
def show_csv.print_tabular ( )

Definition at line 45 of file show_csv.py.

46  if args.group:
47  best_accuracy = uni_accuracies[-1]
48  upper_thresh = np.floor(best_accuracy*10)/10
49  lower_thresh = upper_thresh - 0.1 * (args.num - 1) - 0.0001
50  i = lower_thresh
51  best_accs = []
52  while i < upper_thresh:
53  j = i
54  # avoid floating point error like 0.70001, which doesn't include 0.7 anymore
55  i += 0.099998
56  best_accs.append([acc for acc in uni_accuracies if j <= acc < i])
57  else:
58  best_accs = [[acc] for acc in uni_accuracies[-args.num:]]
59  indent = max(8, 4+2*args.num)
60 
61  word = 'accuracy groups' if args.group else 'accuracies'
62 
63  print(f'Count of best {args.num} {word} in the tables below from right to left:')
64  if not args.group:
65  print([x[0] for x in best_accs])
66  else:
67  print([(x[0], x[-1]) for x in best_accs])
68  if not args.group:
69  print(f'0+1+2 means 0 occurrences of {best_accs[0]}, 1 occurrence of {best_accs[1]} and 2 occurrences of '
70  f'{best_accs[2]} for this specific parameters')
71  else:
72  print(f'0+1+2 means 0 occurrences of {best_accs[0][0]}-{best_accs[0][-1]}, ', end='')
73  if len(best_accs) > 1:
74  print(f'1 occurrence of {best_accs[1][0]}-{best_accs[1][-1]} ', end='')
75  if len(best_accs) > 2:
76  print(f'and 2 occurrences of {best_accs[2][0]}-{best_accs[2][-1]} ', end='')
77  print(f'for this specific parameters')
78  print('')
79  for idx in range(len(cols)):
80  for idx2 in range(idx + 1, len(cols)):
81  print(f'↓ {cols[idx]} → {cols[idx2]}')
82  unique1 = np.unique(data[idx])
83  unique2 = np.unique(data[idx2])
84  print(f"{'':>{8}}", end='')
85  for uni2 in unique2:
86  print(f'{uni2.round(5):>{indent}}', end='')
87  print('')
88  for uni1 in unique1:
89  print(f'{uni1.round(5):>8}', end='')
90  for uni2 in unique2:
91  acc = [d[-1] for d in data.transpose() if d[idx] == uni1 and d[idx2] == uni2]
92  counts = []
93  for best_acc in best_accs:
94  counts.append(sum([x in best_acc for x in acc]))
95  count_str = ''
96  for count in counts:
97  count_str += str(count) + '+'
98  print(f'{count_str[:-1]:>{indent}}', end='')
99  print('')
100  print('')
101 
102 
def print_tabular()
Definition: show_csv.py:45

Variable Documentation

show_csv.args = parser.parse_args()

Definition at line 18 of file show_csv.py.

show_csv.bool

Definition at line 16 of file show_csv.py.

list show_csv.cols = list(pd.read_csv(args.path, nrows=1))

Definition at line 29 of file show_csv.py.

show_csv.csv_data = pd.read_csv(args.path, usecols=[i for i in cols if any(re.match(fil, i) for fil in filter_in)])

Definition at line 32 of file show_csv.py.

show_csv.data = []

Definition at line 35 of file show_csv.py.

show_csv.default

Definition at line 15 of file show_csv.py.

tuple show_csv.figsize = (7, 8)

Definition at line 26 of file show_csv.py.

list show_csv.filter_in = [re.compile('[\w]*_weight'), re.compile('accuracy'), re.compile('pool_delay')]

Definition at line 31 of file show_csv.py.

show_csv.help

Definition at line 14 of file show_csv.py.

show_csv.int

Definition at line 15 of file show_csv.py.

show_csv.parser = argparse.ArgumentParser()

Definition at line 13 of file show_csv.py.

show_csv.path = args.out

Definition at line 25 of file show_csv.py.

show_csv.required

Definition at line 14 of file show_csv.py.

show_csv.str

Definition at line 17 of file show_csv.py.

show_csv.type

Definition at line 15 of file show_csv.py.

show_csv.uni_accuracies = np.unique(data[-1])

Definition at line 42 of file show_csv.py.