def anomalies(log_z, row_label=None, prefix=''):
from scipy.special import erf
ns = log_z.shape[1]
if row_label is None:
row_label = list(map(str, range(ns)))
a_score = np.sum(log_z[:, :, 0], axis=0)
mean, std = np.mean(a_score), np.std(a_score)
a_score = (a_score - mean) / std
percentile = 1. / ns
anomalies = np.where(0.5 * (1 - erf(a_score / np.sqrt(2)) ) < percentile)[0]
f = safe_open(prefix + '/text_files/anomalies.txt', 'w+')
for i in anomalies:
f.write(row_label[i] + ', %0.1f\n' % a_score[i])
f.close()
评论列表
文章目录