Пример #1
0
 def cdf(self, val):
     _cdf = (erf((val - self.mu) / 2**0.5 / self.sigma) - erf(
         (self.minimum - self.mu) / 2**0.5 /
         self.sigma)) / 2 / self.normalisation
     _cdf[val > self.maximum] = 1
     _cdf[val < self.minimum] = 0
     return _cdf
Пример #2
0
    def normalisation(self):
        """ Calculates the proper normalisation of the truncated Gaussian

        Returns
        -------
        float: Proper normalisation of the truncated Gaussian
        """
        return (erf((self.maximum - self.mu) / 2**0.5 / self.sigma) - erf(
            (self.minimum - self.mu) / 2**0.5 / self.sigma)) / 2
Пример #3
0
 def cdf(self, val):
     if isinstance(val, (float, int)):
         if val <= self.minimum:
             _cdf = 0.
         else:
             _cdf = 0.5 + erf((np.log(val) - self.mu) / self.sigma / np.sqrt(2)) / 2
     else:
         _cdf = np.zeros(val.size)
         _cdf[val > self.minimum] = 0.5 + erf((
             np.log(val[val > self.minimum]) - self.mu) / self.sigma / np.sqrt(2)) / 2
     return _cdf
 def theoretical_distribution(self):
     x = np.sort(self.sample)
     y = np.array([
         0.5 * (1 + erf((i - self.mean) / np.sqrt(2 * self.std**2)))
         for i in x
     ])
     plt.plot(x, y, 'r-')
Пример #5
0
    def rescale(self, val):
        """
        'Rescale' a sample from the unit line element to the appropriate truncated Gaussian prior.

        This maps to the inverse CDF. This has been analytically solved for this case.
        """
        return erfinv(2 * val * self.normalisation + erf(
            (self.minimum - self.mu) / 2 ** 0.5 / self.sigma)) * 2 ** 0.5 * self.sigma + self.mu
Пример #6
0
 def unify(outlying_scores: np.array) -> np.array:
     # =======================================================================================================================
     # Turn output into probability
     # Source: https://github.com/yzhao062/pyod/blob/8fafcbd7c441954b82db27bfd9cd7f0720974d9a/pyod/models/base.py
     # Reference:
     #   Hans-Peter Kriegel, etc. Interpreting and unifying outlier scores. SDM 2011
     # =======================================================================================================================
     mu = np.mean(outlying_scores)
     sigma = np.std(outlying_scores)
     if sigma !=0:
         pre_erf_score = (outlying_scores - mu) / (sigma * np.sqrt(2))
     else:
         pre_erf_score = (outlying_scores - mu)
     erf_score = erf(pre_erf_score)
     return erf_score.clip(0, 1).ravel()
Пример #7
0
 def cdf(self, val):
     return (1 - erf((self.mu - val) / 2**0.5 / self.sigma)) / 2