def test_pdf(): ''' Tests the probability density function. ''' samples = np.array([np.linspace(0, 1, 5), np.linspace(0.2, 0.8, 5)]).T # Independence copula independence_copula = IndependenceCopula() # Comparison values r_pdf = np.array([0.0, 1.0, 1.0, 1.0, 0.0]) p_pdf = independence_copula.pdf(samples) assert_allclose(p_pdf, r_pdf) # Gaussian copula family gaussian_copula = GaussianCopula(0.5) # Comparison values r_pdf = np.array([0.0, 1.2417679440, 1.1547005384, 1.2417679440, 0.0]) p_pdf = gaussian_copula.pdf(samples) assert_allclose(p_pdf, r_pdf) # Clayton copula family clayton_copula = ClaytonCopula(5) # Comparison values r_pdf = np.array([0.0, 2.1943031503, 2.7037217178, 1.9477508961, 0.0]) p_pdf = clayton_copula.pdf(samples) assert_allclose(p_pdf, r_pdf) # Frank copula family frank_copula = FrankCopula(5) # Comparison values r_pdf = np.array([0.0, 1.5167615765, 1.4735637246, 1.5167615765, 0.0]) p_pdf = frank_copula.pdf(samples) assert_allclose(p_pdf, r_pdf)
def test_rotation_180_deg(): ''' Tests the 180° copula rotation. ''' samples = np.array([np.linspace(0, 1, 5), np.linspace(0.2, 0.8, 5)]).T # Clayton copula family rotated 180° copula = ClaytonCopula(5, rotation='180°') # Comparison values r_logpdf = np.array( [-np.inf, 0.6666753203, 0.9946292379, 0.7858645247, -np.inf]) r_pdf = np.array([0.0, 1.9477508961, 2.7037217178, 2.1943031503, 0.0]) r_logcdf = np.array( [-np.inf, -1.5602819348, -0.8286269453, -0.4437013452, -0.2231435513]) r_cdf = np.array([0.0, 0.2100768349, 0.4366484171, 0.6416570262, 0.8]) r_ccdf = np.array([0.0, 0.3163606244, 0.5564206557, 0.8916601339, 1.0]) r_ppcf = np.array([0.0, 0.2140692068, 0.4788690972, 0.7005153398, 1.0]) p_logpdf = copula.logpdf(samples) p_pdf = copula.pdf(samples) p_logcdf = copula.logcdf(samples) p_cdf = copula.cdf(samples) p_ccdf = copula.ccdf(samples) p_ppcf = copula.ppcf(samples) assert_allclose(p_logpdf, r_logpdf) assert_allclose(p_pdf, r_pdf) assert_allclose(p_logcdf, r_logcdf) assert_allclose(p_cdf, r_cdf) assert_allclose(p_ccdf, r_ccdf) assert_allclose(p_ppcf, r_ppcf)
def test_rotation_270_deg(): ''' Tests the 270° copula rotation. ''' samples = np.array([np.linspace(0, 1, 5), np.linspace(0.2, 0.8, 5)]).T # Clayton copula family rotated 270° copula = ClaytonCopula(5, rotation='270°') # Comparison values r_logpdf = np.array( [-np.inf, -1.7680858282, 0.9946292379, -2.5713221880, -np.inf]) r_pdf = np.array([0.0, 0.1706593477, 2.7037217178, 0.0764344179, 0.0]) r_logcdf = np.array([ -38.123095, -6.7509119186, -2.7590553856, -0.9153652928, -0.2231435513 ]) r_cdf = np.array([0.0, 0.0011698124, 0.0633515829, 0.400370347, 0.8]) r_ccdf = np.array([0.0, 0.0198871044, 0.5564206557, 0.996791538, 1.0]) r_ppcf = np.array([0.0, 0.547275029, 0.4788690972, 0.4493004266, 1.0]) p_logpdf = copula.logpdf(samples) p_pdf = copula.pdf(samples) p_logcdf = copula.logcdf(samples) p_cdf = copula.cdf(samples) p_ccdf = copula.ccdf(samples) p_ppcf = copula.ppcf(samples) assert_allclose(p_logpdf, r_logpdf) assert_allclose(p_pdf, r_pdf) assert_allclose(p_logcdf, r_logcdf) assert_allclose(p_cdf, r_cdf, atol=1e-10) assert_allclose(p_ccdf, r_ccdf, atol=1e-10) assert_allclose(p_ppcf, r_ppcf, atol=1e-10)
def test_rotation_90_deg(): ''' Tests the 90° copula rotation. ''' samples = np.array([np.linspace(0, 1, 5), np.linspace(0.2, 0.8, 5)]).T # Clayton copula family rotated 90° copula = ClaytonCopula(5, rotation='90°') # Comparison values r_logpdf = np.array( [-np.inf, -2.571322188, 0.9946292379, -1.7680858282, -np.inf]) r_pdf = np.array([0.0, 0.0764344179, 2.7037217178, 0.1706593477, 0.0]) r_logcdf = np.array( [-np.inf, -7.9010702481, -2.7590553856, -0.9133704691, -0.2231435513]) r_cdf = np.array([0.0, 0.000370347, 0.0633515829, 0.4011698124, 0.8]) r_ccdf = np.array([0.0, 0.003208462, 0.4435793443, 0.9801128956, 1.0]) r_ppcf = np.array([0.0, 0.5506995734, 0.5211309028, 0.452724971, 1.0]) p_logpdf = copula.logpdf(samples) p_pdf = copula.pdf(samples) p_logcdf = copula.logcdf(samples) p_cdf = copula.cdf(samples) p_ccdf = copula.ccdf(samples) p_ppcf = copula.ppcf(samples) assert_allclose(p_logpdf, r_logpdf) assert_allclose(p_pdf, r_pdf) assert_allclose(p_logcdf, r_logcdf) assert_allclose(p_cdf, r_cdf) assert_allclose(p_ccdf, r_ccdf) assert_allclose(p_ppcf, r_ppcf)