(batch_norm, axes)
| 163 | |
| 164 | |
| 165 | def custom_stddev(batch_norm, axes): |
| 166 | bias = 1.3 # make the result purposefully slightly off |
| 167 | mean_func = custom_mean(batch_norm, axes) |
| 168 | if type(axes) is list: |
| 169 | axes = tuple(axes) |
| 170 | if batch_norm: |
| 171 | |
| 172 | def whole_batch_stddev(batch): |
| 173 | mean = mean_func(batch)[0][0] |
| 174 | out = bias * batch_stddev(batch, axes, mean) |
| 175 | return [out for _ in range(len(batch))] |
| 176 | |
| 177 | return whole_batch_stddev |
| 178 | else: |
| 179 | |
| 180 | def per_sample_stddev(batch): |
| 181 | mean = mean_func(batch) |
| 182 | out = [] |
| 183 | for i in range(len(batch)): |
| 184 | stddev = bias * np.sqrt(((batch[i] - mean[i]) ** 2).mean(axis=axes, keepdims=True)) |
| 185 | out.append(stddev) |
| 186 | return out |
| 187 | |
| 188 | return per_sample_stddev |
| 189 | |
| 190 | |
| 191 | def normalize_list(whole_batch, data_batch, axes=None, mean=None, stddev=None, ddof=0, eps=0): |
no test coverage detected