def _calculate_pvalue_ranges(self, x: np.ndarray, batch_size: int = 128) -> np.ndarray:
        """
        Returns computed p-value ranges.

        :param x: Data being evaluated for anomalies.
        :return: p-value ranges.
        """
        bgd_activations = self.sorted_bgd_activations
        eval_activations = self._get_activations(x, self._layer_name, batch_size)

        if len(eval_activations.shape) == 4:
            dim2 = eval_activations.shape[1] * eval_activations.shape[2] * eval_activations.shape[3]
            eval_activations = np.reshape(eval_activations, (eval_activations.shape[0], dim2))

        bgrecords_n = bgd_activations.shape[0]
        records_n = eval_activations.shape[0]
        atrr_n = eval_activations.shape[1]

        pvalue_ranges = np.empty((records_n, atrr_n, 2))

        for j in range(atrr_n):
            pvalue_ranges[:, j, 0] = np.searchsorted(bgd_activations[:, j], eval_activations[:, j], side="right")
            pvalue_ranges[:, j, 1] = np.searchsorted(bgd_activations[:, j], eval_activations[:, j], side="left")

        pvalue_ranges = bgrecords_n - pvalue_ranges

        pvalue_ranges[:, :, 0] = np.divide(pvalue_ranges[:, :, 0], bgrecords_n + 1)
        pvalue_ranges[:, :, 1] = np.divide(pvalue_ranges[:, :, 1] + 1, bgrecords_n + 1)

        return pvalue_ranges

        Returns computed p-value ranges.

        :param x: Data being evaluated for anomalies.
        :return: p-value ranges.
        
art/defences/detector/evasion/subsetscanning/detector.py