Skip to content

Commit

Permalink
fix bug in mixuture copula parameter init
Browse files Browse the repository at this point in the history
  • Loading branch information
wgurecky committed Jul 25, 2020
1 parent f1c6658 commit 0db86ac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion starvine/bvcopula/copula/mixture_copula.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 9 additions & 6 deletions starvine/bvcopula/tests/test_mixture_copula.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 0db86ac

Please sign in to comment.