Пример #1
0
 def test_select_univariate(self):
     """
     Suppose the data follows a bimodal distribution. The model selector should be able to
     figure out that the GaussianKDE is best.
     """
     model = select_univariate(self.bimodal_data, self.candidates)
     assert isinstance(model, GaussianKDE)
Пример #2
0
 def test_truncated(self):
     """
     Suppose the data follows a truncated normal distribution. The KS statistic should be
     larger for a Gaussian model than a TruncatedGaussian model (since the fit is worse).
     """
     model = select_univariate(
         self.truncated_data,
         [GaussianUnivariate(), TruncatedGaussian()])
     assert isinstance(model, TruncatedGaussian)
Пример #3
0
 def test_binary(self):
     """
     Suppose the data follows a Bernoulli distribution. The KS statistic should be larger
     for a TruncatedGaussian model than a GaussianKDE model which can somewhat capture a
     Bernoulli distribution as it resembles a bimodal distribution.
     """
     model = select_univariate(
         self.binary_data,
         [GaussianKDE(), TruncatedGaussian()])
     assert isinstance(model, GaussianKDE)
Пример #4
0
    def fit(self, X):
        """Fit the model to a random variable.

        Arguments:
            X (numpy.ndarray):
                Values of the random variable. It must have shape (n, 1).
        """
        self._instance = select_univariate(X, self.candidates)
        self._instance.fit(X)

        self.fitted = True
Пример #5
0
    def fit(self, X):
        """Fit the model to a random variable.

        Arguments:
            X (numpy.ndarray):
                Values of the random variable. It must have shape (n, 1).
        """
        if self.selection_sample_size and self.selection_sample_size < len(X):
            selection_sample = np.random.choice(X, size=self.selection_sample_size)
        else:
            selection_sample = X

        self._instance = select_univariate(selection_sample, self.candidates)
        self._instance.fit(X)

        self.fitted = True
Пример #6
0
    def fit(self, X):
        """Fits the model.

        Arguments:
            X: `np.ndarray` of shape (n, 1).

        Returns:
            None
        """
        self.constant_value = self._get_constant_value(X)
        if self.constant_value is None:
            self._instance = select_univariate(X, self.candidates)
            self._instance.fit(X)
        else:
            self._replace_constant_methods()

        self.fitted = True