input_ = input_[np.newaxis,:] target = np.array([target])[np.newaxis,:] net.activation(input_, accumulate=True) errors_valid[i] = net.output - target i += 1 mean_valid, std_valid = (errors_valid.mean(), errors_valid.std()) # test p_anomaly_test = np.zeros(shape=len(X_test)) predictions = np.zeros(shape=len(X_test)) errors_test = np.zeros(shape=len(Y_test)) threshold = utils.gaussian_pdf(mean_valid-2*std_valid, mean_valid, std_valid) i = 0 for (input_, target) in zip(X_test, Y_test): # format input and prediction input_ = input_[np.newaxis,:] target = np.array([target])[np.newaxis,:] net.activation(input_, accumulate=True) prediction = net.output predictions[i] = prediction errors_test[i] = scistats.norm.ppf(prediction-target, mean_valid, std_valid) anomalies = np.argwhere(errors_test < threshold)
net.activation(input_, accumulate=True) # execute the backpropagation with the input that has been memorized previously net.backpropagation(target=target, loss='L2', optimizer='sgd', l_rate=1e-2, update=True) i += 1 # test p_anomaly_test = np.zeros(shape=len(X_test)) predictions = np.zeros(shape=len(X_test)) errors_test = np.zeros(shape=len(Y_test)) threshold = utils.gaussian_pdf(mean_valid - 2. * std_valid, mean_valid, std_valid) i = 0 for (input_, target) in zip(X_test, Y_test): # format input and prediction input_ = input_[np.newaxis, :] target = np.array([target])[np.newaxis, :] net.activation(input_, accumulate=True) prediction = net.output predictions[i] = prediction errors_test[i] = utils.gaussian_pdf(prediction - target, mean_valid, std_valid) anomalies = np.argwhere(errors_test < threshold)