def test_sample(self, uniform_mock): """Sample use the inverse-transform method to generate new samples.""" # Setup instance = Bivariate(CopulaTypes.FRANK) instance.tau = 0.5 instance.theta = instance.compute_theta() uniform_mock.return_value = np.array([0.1, 0.2, 0.4, 0.6, 0.8]) expected_result = np.array([[6.080069565509917e-06, 0.1], [6.080069565509917e-06, 0.2], [6.080069565509917e-06, 0.4], [6.080069565509917e-06, 0.6], [4.500185268624483e-06, 0.8]]) expected_uniform_call_args_list = [((0, 1, 5), {}), ((0, 1, 5), {})] # Run result = instance.sample(5) # Check assert isinstance(result, np.ndarray) assert result.shape == (5, 2) compare_nested_iterables(result, expected_result) assert uniform_mock.call_args_list == expected_uniform_call_args_list
def test_cdf_value_if_all_other_arg_are_one(self): """Test of the analytical properties of copulas on a range of values of theta.""" # Setup instance = Bivariate(CopulaTypes.FRANK) tau_values = np.linspace(-1.0, 1.0, 20)[1:-1] # Run/Check for tau in tau_values: instance.tau = tau instance.theta = instance.compute_theta() copula_single_arg_not_one(instance, tolerance=1E-03)
def test_cdf_zero_if_single_arg_is_zero(self): """Test of the analytical properties of copulas on a range of values of theta.""" # Setup instance = Bivariate(CopulaTypes.FRANK) tau_values = np.linspace(-1.0, 1.0, 20)[1:-1] # Run/Check for tau in tau_values: instance.tau = tau instance.theta = instance.compute_theta() copula_zero_if_arg_zero(instance)
def test_sample_random_state(self): """If random_state is set, the samples are the same.""" # Setup instance = Bivariate(CopulaTypes.FRANK, random_seed=0) instance.tau = 0.5 instance.theta = instance.compute_theta() expected_result = np.array([[3.66330927e-06, 5.48813504e-01], [6.08006957e-06, 7.15189366e-01], [5.27582646e-06, 6.02763376e-01], [5.58315848e-06, 5.44883183e-01], [6.08006957e-06, 4.23654799e-01]]) # Run result = instance.sample(5) # Check compare_nested_iterables(result, expected_result)
def test_sample_random_state(self): """If random_state is set, the samples are the same.""" # Setup instance = Bivariate(CopulaTypes.CLAYTON, random_seed=0) instance.tau = 0.5 instance.theta = instance.compute_theta() expected_result = np.array([[0.68627770, 0.54881350], [0.64059280, 0.71518937], [0.90594782, 0.60276338], [0.96040856, 0.54488318], [0.40876969, 0.42365480]]) # Run result = instance.sample(5) # Check compare_nested_iterables(result, expected_result)
def test_sample(self, uniform_mock): """Sample use the inverse-transform method to generate new samples.""" # Setup instance = Bivariate(CopulaTypes.CLAYTON) instance.tau = 0.5 instance.theta = instance.compute_theta() uniform_mock.return_value = np.array([0.1, 0.2, 0.4, 0.6, 0.8]) expected_result = np.array([[0.05233100, 0.1], [0.14271095, 0.2], [0.39959746, 0.4], [0.68567125, 0.6], [0.89420523, 0.8]]) expected_uniform_call_args_list = [((0, 1, 5), {}), ((0, 1, 5), {})] # Run result = instance.sample(5) # Check assert isinstance(result, np.ndarray) assert result.shape == (5, 2) compare_nested_iterables(result, expected_result) assert uniform_mock.call_args_list == expected_uniform_call_args_list