예제 #1
0
    def test__rebuild_gaussian_copula(self):
        """Test the ``GaussianCopula._rebuild_gaussian_copula`` method.

        The ``test__rebuild_gaussian_copula`` method is expected to:
        - Rebuild a square covariance matrix out of a triangular one.

        Input:
        - numpy array, Triangular covariance matrix

        Expected Output:
        - numpy array, Square covariance matrix
        """
        # Setup
        gaussian_copula = Mock(autospec=GaussianCopula)
        gaussian_copula._rebuild_covariance_matrix.return_value = [[0.4, 0.17],
                                                                   [
                                                                       0.17,
                                                                       0.07
                                                                   ]]
        gaussian_copula._distribution = {'foo': 'GaussianUnivariate'}

        # Run
        model_parameters = {
            'univariates': {
                'foo': {
                    'scale': 0.0,
                    'loc': 5
                },
            },
            'covariance': [[0.1], [0.4, 0.1]],
            'distribution': 'GaussianUnivariate',
        }
        result = GaussianCopula._rebuild_gaussian_copula(
            gaussian_copula, model_parameters)

        # Asserts
        expected = {
            'univariates': [{
                'scale': 1.0,
                'loc': 5,
                'type': 'GaussianUnivariate'
            }],
            'columns': ['foo'],
            'distribution': 'GaussianUnivariate',
            'covariance': [[0.4, 0.17], [0.17, 0.07]]
        }
        assert result == expected
예제 #2
0
    def test__rebuild_gaussian_copula(self):
        """Test the ``GaussianCopula._rebuild_gaussian_copula`` method.

        The ``test__rebuild_gaussian_copula`` method is expected to:
        - Rebuild a square covariance matrix out of a triangular one.

        Input:
        - numpy array, Triangular correlation matrix

        Expected Output:
        - numpy array, Square correlation matrix
        """
        # Setup
        gaussian_copula = GaussianCopula()
        gaussian_copula._field_distributions = {
            'foo': 'GaussianUnivariate',
            'bar': 'GaussianUnivariate',
            'baz': 'GaussianUnivariate',
        }

        # Run
        model_parameters = {
            'univariates': {
                'foo': {
                    'scale': 0.0,
                    'loc': 0.0
                },
                'bar': {
                    'scale': 1.0,
                    'loc': 1.0
                },
                'baz': {
                    'scale': 2.0,
                    'loc': 2.0
                },
            },
            'covariance': [[0.1], [0.2, 0.3]],
            'distribution': 'GaussianUnivariate',
        }
        result = GaussianCopula._rebuild_gaussian_copula(
            gaussian_copula, model_parameters)

        # Asserts
        expected = {
            'univariates': [
                {
                    'scale': 0.0,
                    'loc': 0.0,
                    'type': 'GaussianUnivariate'
                },
                {
                    'scale': 1.0,
                    'loc': 1.0,
                    'type': 'GaussianUnivariate'
                },
                {
                    'scale': 2.0,
                    'loc': 2.0,
                    'type': 'GaussianUnivariate'
                },
            ],
            'covariance': [[1.0, 0.1, 0.2], [0.1, 1.0, 0.3], [0.2, 0.3, 1.0]],
            'distribution':
            'GaussianUnivariate',
            'columns': ['foo', 'bar', 'baz'],
        }
        assert result == expected