예제 #1
0
    def test__trasnform(self):
        # setup
        instance = MagicMock()
        trials = np.array([[0.1, 0.8, 0.2], [0.7, 0.6, 0.4], [0.4, 0.2, 0.3],
                           [0.7, 0.8, 0.9], [0.2, 0.3, 0.4]])

        distributions = []
        for column in trials.T:
            distribution = Univariate()
            distribution.fit(column)
            distributions.append(distribution)

        instance._distributions = distributions

        # run
        result = GaussianCopulaProcessMetaModel._transform(instance, trials)

        # assert
        expected_result = np.array([[-0.93051407, 0.72584367, -1.05823838],
                                    [0.78865964, 0.1155097, 0.3732126],
                                    [-0.04619363, -0.96388991, -0.49278658],
                                    [0.78865964, 0.72584367, 1.82607428],
                                    [-0.60472608, -0.66069297, 0.3732126]])

        np.testing.assert_allclose(result, expected_result)
예제 #2
0
    def from_dict(cls, copula_dict):
        """Create a new instance from a parameters dictionary.

        Args:
            params (dict):
                Parameters of the distribution, in the same format as the one
                returned by the ``to_dict`` method.

        Returns:
            Multivariate:
                Instance of the distribution defined on the parameters.
        """
        instance = cls()
        instance.univariates = []
        instance.columns = copula_dict['columns']

        for parameters in copula_dict['univariates']:
            instance.univariates.append(Univariate.from_dict(parameters))

        instance.covariance = np.array(copula_dict['covariance'])
        instance.fitted = True
        warnings.warn('`covariance` will be renamed to `correlation` in v0.4.0',
                      DeprecationWarning)

        return instance
예제 #3
0
    def from_dict(cls, copula_dict):
        """Set attributes with provided values."""
        instance = cls()
        instance.univariates = []
        instance.columns = copula_dict['columns']

        for parameters in copula_dict['univariates']:
            instance.univariates.append(Univariate.from_dict(parameters))

        instance.covariance = np.array(copula_dict['covariance'])
        instance.fitted = copula_dict['fitted']
        instance.distribution = copula_dict['distribution']
        if isinstance(instance.distribution, dict):
            for k, v in instance.distribution.items():
                instance.distribution[k] = Univariate.from_dict(v)
        return instance
예제 #4
0
    def test_fit_sample_distribution_dict_multiple(self):
        data = sample_trivariate_xyz()
        model = GaussianMultivariate(
            distribution={
                'x': Univariate(parametric=ParametricType.PARAMETRIC),
                'y': BetaUnivariate(),
                'z': GaussianKDE()
            })
        model.fit(data)

        sampled_data = model.sample(10)
        assert sampled_data.shape == (10, 3)
예제 #5
0
    def from_dict(cls, copula_dict):
        """Set attributes with provided values."""
        instance = cls()
        instance.distribs = {}

        for name, parameters in copula_dict['distribs'].items():
            instance.distribs[name] = Univariate.from_dict(parameters)

        instance.covariance = np.array(copula_dict['covariance'])
        instance.fitted = copula_dict['fitted']
        instance.distribution = copula_dict['distribution']
        return instance
예제 #6
0
    def _fit(self, trials, scores):
        self._distributions = []
        for column in trials.T:
            distribution = Univariate()
            distribution.fit(column)
            self._distributions.append(distribution)

        distribution = Univariate()
        distribution.fit(scores)
        self._score_distribution = distribution

        trans_trials = self._transform(trials)
        trans_scores = scipy.stats.norm.ppf(
            self._score_distribution.cdf(scores).clip(0 + EPSILON, 1 - EPSILON)
        )

        super()._fit(trans_trials, trans_scores)