def test_copulas_distr(case): # check ev copulas, cdf and transform against R `copula` package cop_tr, v1, v2, args, cdf2, pdf2 = case u = [v1, v2] ca = ArchimedeanCopula(cop_tr()) cdf1 = ca.cdf(u, args=args) pdf1 = ca.pdf(u, args=args) cad = CopulaDistribution([uniform, uniform], ca, copargs=args) cdfd = cad.cdf(np.array(u), args=args) assert_allclose(cdfd, cdf1, rtol=1e-13) assert cdfd.shape == () # check pdf pdfd = cad.pdf(np.array(u), args=args) assert_allclose(pdfd, pdf1, rtol=1e-13) assert cdfd.shape == () # using list u cdfd = cad.cdf(u, args=args) assert_allclose(cdfd, cdf1, rtol=1e-13) assert cdfd.shape == () assert_allclose(cdf1, cdf2, rtol=1e-13) assert_allclose(pdf1, pdf2, rtol=1e-13) # check vector values for u cdfd = cad.cdf(np.array(u) * np.ones((3, 1)), args=args) assert_allclose(cdfd, cdf2, rtol=1e-13) assert cdfd.shape == (3, ) # check mv, check at marginal cdf cdfmv = ca.cdf([v1, v2, 1], args=args) assert_allclose(cdfmv, cdf1, rtol=1e-13) assert cdfd.shape == (3, )
def test_ev_copula_distr(case): # check ev copulas, cdf and transform against R `evd` package ev_tr, v1, v2, args, res1 = case u = [v1, v2] res = copula_bv_ev(u, ev_tr, args=args) assert_allclose(res, res1, rtol=1e-13) ev = ExtremeValueCopula(ev_tr) cdf1 = ev.cdf(u, args) assert_allclose(cdf1, res1, rtol=1e-13) cev = CopulaDistribution([uniform, uniform], ev, copargs=args) cdfd = cev.cdf(np.array(u), args=args) assert_allclose(cdfd, res1, rtol=1e-13) assert cdfd.shape == () # using list u cdfd = cev.cdf(u, args=args) assert_allclose(cdfd, res1, rtol=1e-13) assert cdfd.shape == () # check vector values for u # bilogistic is not vectorized, uses integrate.quad if ev_tr != trev.transform_bilogistic: cdfd = cev.cdf(np.array(u) * np.ones((3, 1)), args=args) assert_allclose(cdfd, res1, rtol=1e-13) assert cdfd.shape == (3, )
def test_gev_genextreme(case): gev = stats.genextreme(0) # check ev copulas, cdf and transform against R `evt` package ev_tr, v1, v2, args, res0, res1, res2 = case y = [v1, v2] u = gev.cdf(y) res = copula_bv_ev(u, ev_tr, args=args) assert_allclose(res, res1, rtol=1e-13) ev = ExtremeValueCopula(ev_tr) # evaluated at using u = y cdf1 = ev.cdf(y, args) assert_allclose(cdf1, res0, rtol=1e-13) # evaluated at transformed u = F(y) cdf1 = ev.cdf(u, args) assert_allclose(cdf1, res1, rtol=1e-13) cev = CopulaDistribution([gev, gev], ev, copargs=args) cdfd = cev.cdf(np.array(y), args=args) assert_allclose(cdfd, res1, rtol=1e-13) pdfd = cev.pdf(np.array(y), args=args) assert_allclose(pdfd, res2, rtol=1e-13)