def extract_anomalies(y_true, smoothed_errors, window_size, batch_size, error_buffer):
    """
        Extracts anomalies from the errors.
        Args:
            y_true ():
            smoothed_errors ():
            window_size (int):
            batch_size (int):
            error_buffer (int):
        Returns:
    """
    if len(y_true) <= batch_size * window_size:
        raise ValueError("Window size (%s) larger than y_true (len=%s)."
                         % (batch_size, len(y_true)))

    num_windows = int((len(y_true) - (batch_size * window_size)) / batch_size)

    anomalies_indices = []

    for i in range(num_windows + 1):
        prev_index = i * batch_size
        curr_index = (window_size * batch_size) + (i * batch_size)

        if i == num_windows + 1:
            curr_index = len(y_true)

        window_smoothed_errors = smoothed_errors[prev_index:curr_index]
        window_y_true = y_true[prev_index:curr_index]

        epsilon, sd_threshold = compute_threshold(window_smoothed_errors, error_buffer)

        window_anom_indices = get_anomalies(
            window_smoothed_errors,
            window_y_true,
            sd_threshold,
            i,
            anomalies_indices,
            error_buffer
        )

        # get anomalies from inverse of smoothed errors
        # This was done in the implementation of NASA paper but
        # wasn't referenced in the paper

        # we get the inverse by flipping around the mean
        mu = np.mean(window_smoothed_errors)
        smoothed_errors_inv = [mu + (mu - e) for e in window_smoothed_errors]
        epsilon_inv, sd_inv = compute_threshold(smoothed_errors_inv, error_buffer)
        inv_anom_indices = get_anomalies(
            smoothed_errors_inv,
            window_y_true,
            sd_inv,
            i,
            anomalies_indices,
            len(y_true)
        )

        anomalies_indices = list(set(anomalies_indices + inv_anom_indices))

        anomalies_indices.extend([i_a + i * batch_size for i_a in window_anom_indices])

    # group anomalies
    anomalies_indices = sorted(list(set(anomalies_indices)))
    anomalies_groups = [list(group) for group in mit.consecutive_groups(anomalies_indices)]
    anomaly_sequences = [(g[0], g[-1]) for g in anomalies_groups if not g[0] == g[-1]]

    # generate "scores" for anomalies based on the max distance from epsilon for each sequence
    anomalies_scores = []
    for e_seq in anomaly_sequences:
        denominator = np.mean(smoothed_errors) + np.std(smoothed_errors)
        score = max([
            abs(smoothed_errors[x] - epsilon) / denominator
            for x in range(e_seq[0], e_seq[1])
        ])

        anomalies_scores.append(score)

    return anomaly_sequences, anomalies_scores
Extracts anomalies from the errors.
        Args:
            y_true ():
            smoothed_errors ():
            window_size (int):
            batch_size (int):
            error_buffer (int):
        Returns: