From 8ad82552caf2fc87f04a0bc48bdf713bdf7b9928 Mon Sep 17 00:00:00 2001 From: William Gurecky Date: Sat, 25 Jul 2020 05:55:48 -0500 Subject: [PATCH] fix bug in mixuture copula parameter init --- starvine/bvcopula/copula/mixture_copula.py | 2 +- starvine/bvcopula/tests/test_mixture_copula.py | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/starvine/bvcopula/copula/mixture_copula.py b/starvine/bvcopula/copula/mixture_copula.py index 10a5e87..bb6428d 100644 --- a/starvine/bvcopula/copula/mixture_copula.py +++ b/starvine/bvcopula/copula/mixture_copula.py @@ -20,7 +20,7 @@ def __init__(self, copula_a, wt_a, copula_b, wt_b): self._name = copula_a.name + '-' + copula_b.name self._thetaBounds = tuple(list(copula_a.thetaBounds) + list(copula_b.thetaBounds) + [(0.,1.), (0.,1.)]) self._theta0 = tuple(list(copula_a.theta0) + list(copula_b.theta0) + [wt_a, wt_b]) - self.fittedParams = list(copula_a.theta0) + list(copula_b.theta0) + [wt_a, wt_b] + self.fittedParams = list(copula_a.fittedParams) + list(copula_b.fittedParams) + [wt_a, wt_b] self._copula_a = copula_a self._copula_b = copula_b self._n_params_a = len(copula_a.thetaBounds) diff --git a/starvine/bvcopula/tests/test_mixture_copula.py b/starvine/bvcopula/tests/test_mixture_copula.py index 2dec675..b6d503a 100644 --- a/starvine/bvcopula/tests/test_mixture_copula.py +++ b/starvine/bvcopula/tests/test_mixture_copula.py @@ -6,7 +6,7 @@ # COPULA IMPORTS from starvine.bvcopula.copula.mixture_copula import MixtureCopula as mc import numpy as np -import matplotlib.pyplot as plt +from starvine.bvcopula import bv_plot import os pwd_ = os.path.dirname(os.path.abspath(__file__)) from starvine.bvcopula.copula.gumbel_copula import GumbelCopula @@ -17,14 +17,17 @@ class TestMixtureCopula(unittest.TestCase): def setUp(self): - self._mix_copula = mc(GumbelCopula(1), 0.5, - GumbelCopula(2), 0.5) + self._mix_copula = mc(GumbelCopula(2, [2.1]), 0.5, + GumbelCopula(3, [2.7]), 0.5) def testMixCoplulaPdf(self): - u = np.linspace(1.0e-8, 1.0-1e-8, 50) - v = np.linspace(1.0e-8, 1.0-1e-8, 50) - c_pdf = self._mix_copula.pdf(u, v) + u = np.linspace(6.0e-2, 1.0-6e-2, 50) + v = np.linspace(6.0e-2, 1.0-6e-2, 50) + uu, vv = np.meshgrid(u, v) + c_pdf = self._mix_copula.pdf(uu.flatten(), vv.flatten()) self.assertTrue(np.all(c_pdf >= 0)) + # plot mixture pdf + bv_plot.bvContourf(uu.flatten(), vv.flatten(), c_pdf, savefig="mix.png") def testMixCoplulaCdf(self): u = np.linspace(1.0e-8, 1.0-1e-8, 50)