def test_rvs(self):
        """Test simulation."""

        eta = 100
        ndim = 2
        mvst = MvSt(ndim=ndim, eta=eta)
        size = 10
        rvs = mvst.rvs(size=size)

        self.assertEqual(rvs.shape, (size, ndim))
Exemple #2
0
    def test_rvs(self):
        """Test simulation."""

        eta = 100
        ndim = 2
        mvst = MvSt(ndim=ndim, eta=eta)
        size = 10
        rvs = mvst.rvs(size=size)

        self.assertEqual(rvs.shape, (size, ndim))
    def test_likelihood(self):
        """Test log-likelihood."""

        eta = 100
        size = (10, 2)
        data = np.random.normal(size=size)
        mvst = MvSt(ndim=size[1], eta=eta, data=data)
        logl1 = mvst.likelihood(eta)
        logl2 = mvst.likelihood(eta * 2)

        self.assertIsInstance(logl1, float)
        self.assertNotEqual(logl1, logl2)
        npt.assert_array_equal(mvst.data, data)
Exemple #4
0
    def test_likelihood(self):
        """Test log-likelihood."""

        eta = 100
        size = (10, 2)
        data = np.random.normal(size=size)
        mvst = MvSt(ndim=size[1], eta=eta, data=data)
        logl1 = mvst.likelihood(eta)
        logl2 = mvst.likelihood(eta * 2)

        self.assertIsInstance(logl1, float)
        self.assertNotEqual(logl1, logl2)
        npt.assert_array_equal(mvst.data, data)
Exemple #5
0
    def test_cdf(self):
        """Test cdf."""

        eta = 20
        ndim = 3
        mvst = MvSt(ndim=ndim, eta=eta)
        cdf = mvst.cdf(np.zeros(1))

        self.assertIsInstance(cdf, float)

        eta = 20
        mvst = MvSt(ndim=ndim, eta=eta)
        cdf = mvst.cdf(np.zeros(ndim) - 10)

        self.assertIsInstance(cdf, float)
Exemple #6
0
    def test_quantile(self):
        """Test quantile."""

        eta = 20
        ndim = 1
        mvst = MvSt(ndim=ndim, eta=eta)
        arg = -2.0
        cdf = mvst.cdf(arg)
        ppf = mvst.ppf(cdf)

        self.assertAlmostEqual(ppf, arg)

        arg = -0.1 * np.ones(ndim)
        cdf = mvst.cdf_vec(arg)
        quantiles = mvst.ppf_vec(cdf)

        npt.assert_array_almost_equal(arg, quantiles)
Exemple #7
0
    def test_init(self):
        """Test __init__."""

        mvst = MvSt(ndim=3)

        self.assertIsInstance(mvst.eta, np.ndarray)

        eta = 10
        mvst = MvSt(ndim=1, eta=eta)

        npt.assert_array_equal(mvst.eta, np.array(eta))

        mu, sigma = [0.5, 0.4], np.ones((2, 2))
        mvst = MvSt(ndim=len(mu), eta=eta, mu=mu, sigma=sigma)

        npt.assert_array_equal(mvst.mu, np.array(mu))
        npt.assert_array_equal(mvst.sigma, np.array(sigma))
        npt.assert_array_equal(mvst.const_mu(), np.array(mu))
        npt.assert_array_equal(mvst.const_sigma(), np.array(sigma))

        eta = 15
        mvst.from_theta(eta)

        self.assertEqual(mvst.eta, eta)

        ndim = 2
        size = (10, ndim)
        data = np.random.normal(size=size)
        skst = MvSt(ndim=ndim, data=data)

        npt.assert_array_equal(skst.data, data)
Exemple #8
0
    def test_pdf(self):
        """Test pdf."""

        eta = 30
        mvst = MvSt(ndim=1, eta=eta)
        size = (10, 1)
        data = np.random.normal(size=size)
        pdf = mvst.pdf(data)

        self.assertEqual(pdf.ndim, 1)
        self.assertEqual(pdf.shape, (size[0],))

        eta = 30
        ndim = 2
        mvst = MvSt(ndim=ndim, eta=eta)
        size = (10, ndim)
        data = np.random.normal(size=size)
        pdf = mvst.pdf(data)

        self.assertEqual(pdf.ndim, 1)
        self.assertEqual(pdf.shape, (size[0],))
    def test_cdf(self):
        """Test cdf."""

        eta = 20
        ndim = 3
        mvst = MvSt(ndim=ndim, eta=eta)
        cdf = mvst.cdf(np.zeros(1))

        self.assertIsInstance(cdf, float)

        eta = 20
        mvst = MvSt(ndim=ndim, eta=eta)
        cdf = mvst.cdf(np.zeros(ndim) - 10)

        self.assertIsInstance(cdf, float)
    def test_quantile(self):
        """Test quantile."""

        eta = 20
        ndim = 1
        mvst = MvSt(ndim=ndim, eta=eta)
        arg = -2.
        cdf = mvst.cdf(arg)
        ppf = mvst.ppf(cdf)

        self.assertAlmostEqual(ppf, arg)

        arg = -.1 * np.ones(ndim)
        cdf = mvst.cdf_vec(arg)
        quantiles = mvst.ppf_vec(cdf)

        npt.assert_array_almost_equal(arg, quantiles)
    def test_pdf(self):
        """Test pdf."""

        eta = 30
        mvst = MvSt(ndim=1, eta=eta)
        size = (10, 1)
        data = np.random.normal(size=size)
        pdf = mvst.pdf(data)

        self.assertEqual(pdf.ndim, 1)
        self.assertEqual(pdf.shape, (size[0], ))

        eta = 30
        ndim = 2
        mvst = MvSt(ndim=ndim, eta=eta)
        size = (10, ndim)
        data = np.random.normal(size=size)
        pdf = mvst.pdf(data)

        self.assertEqual(pdf.ndim, 1)
        self.assertEqual(pdf.shape, (size[0], ))
Exemple #12
0
def plot_bidensity():

    lam = [1.5, -2]
    mvsn = MvSN(ndim=len(lam), lam=lam)
    mvsn.plot_bidensity()

    eta = 20
    skst = MvSt(ndim=2, eta=eta)
    skst.plot_bidensity()

    eta, lam = [20, 5], [1.5, .5]
    skst = SkStJR(ndim=len(lam), eta=eta, lam=lam)
    skst.plot_bidensity()

    eta, lam = 20, [1.5, .5]
    skst = SkStBL(ndim=len(lam), eta=eta, lam=lam)
    skst.plot_bidensity()

    eta, lam = 20, [1.5, -2]
    skst = SkStDM(ndim=len(lam), eta=eta, lam=lam)
    skst.plot_bidensity()

    eta, lam = 20, [1.5, -2]
    skst = SkStAC(ndim=len(lam), eta=eta, lam=lam)
    skst.plot_bidensity()
Exemple #13
0
def plot_bidensity_simulated():

    size = int(1e4)

    lam = [1.5, -2]
    mvsn = MvSN(ndim=len(lam), lam=lam)
    mvsn.plot_bidensity()

    rvs = mvsn.rvs(size=size)
    sns.kdeplot(rvs, shade=True)
    plt.axis('square')
    plt.xlim([-2, 2])
    plt.ylim([-2, 2])
    plt.show()

    eta = 20
    skst = MvSt(ndim=2, eta=eta)
    skst.plot_bidensity()

    rvs = skst.rvs(size=size)
    sns.kdeplot(rvs, shade=True)
    plt.axis('square')
    plt.xlim([-2, 2])
    plt.ylim([-2, 2])
    plt.show()

    eta, lam = [20, 5], [1.5, .5]
    skst = SkStJR(ndim=len(lam), eta=eta, lam=lam)
    skst.plot_bidensity()

    rvs = skst.rvs(size=size)
    sns.kdeplot(rvs, shade=True)
    plt.axis('square')
    plt.xlim([-2, 2])
    plt.ylim([-2, 2])
    plt.show()

    eta, lam = 20, [1.5, .5]
    skst = SkStBL(ndim=len(lam), eta=eta, lam=lam)
    skst.plot_bidensity()

    rvs = skst.rvs(size=size)
    sns.kdeplot(rvs, shade=True)
    plt.axis('square')
    plt.xlim([-2, 2])
    plt.ylim([-2, 2])
    plt.show()

    eta, lam = 20, [1.5, -2]
    skst = SkStDM(ndim=len(lam), eta=eta, lam=lam)
    skst.plot_bidensity()

    rvs = skst.rvs(size=size)
    sns.kdeplot(rvs, shade=True)
    plt.axis('square')
    plt.xlim([-2, 2])
    plt.ylim([-2, 2])
    plt.show()

    eta, lam = 20, [1.5, -2]
    skst = SkStAC(ndim=len(lam), eta=eta, lam=lam)
    skst.plot_bidensity()

    rvs = skst.rvs(size=size)
    sns.kdeplot(rvs, shade=True)
    plt.axis('square')
    plt.xlim([-2, 2])
    plt.ylim([-2, 2])
    plt.show()
def plot_bidensity():

    lam = [1.5, -2]
    mvsn = MvSN(ndim=len(lam), lam=lam)
    mvsn.plot_bidensity()

    eta = 20
    skst = MvSt(ndim=2, eta=eta)
    skst.plot_bidensity()

    eta, lam = [20, 5], [1.5, .5]
    skst = SkStJR(ndim=len(lam), eta=eta, lam=lam)
    skst.plot_bidensity()

    eta, lam = 20, [1.5, .5]
    skst = SkStBL(ndim=len(lam), eta=eta, lam=lam)
    skst.plot_bidensity()

    eta, lam = 20, [1.5, -2]
    skst = SkStDM(ndim=len(lam), eta=eta, lam=lam)
    skst.plot_bidensity()

    eta, lam = 20, [1.5, -2]
    skst = SkStAC(ndim=len(lam), eta=eta, lam=lam)
    skst.plot_bidensity()
def plot_bidensity_simulated():

    size = int(1e4)

    lam = [1.5, -2]
    mvsn = MvSN(ndim=len(lam), lam=lam)
    mvsn.plot_bidensity()

    rvs = mvsn.rvs(size=size)
    sns.kdeplot(rvs, shade=True)
    plt.axis('square')
    plt.xlim([-2, 2])
    plt.ylim([-2, 2])
    plt.show()

    eta = 20
    skst = MvSt(ndim=2, eta=eta)
    skst.plot_bidensity()

    rvs = skst.rvs(size=size)
    sns.kdeplot(rvs, shade=True)
    plt.axis('square')
    plt.xlim([-2, 2])
    plt.ylim([-2, 2])
    plt.show()

    eta, lam = [20, 5], [1.5, .5]
    skst = SkStJR(ndim=len(lam), eta=eta, lam=lam)
    skst.plot_bidensity()

    rvs = skst.rvs(size=size)
    sns.kdeplot(rvs, shade=True)
    plt.axis('square')
    plt.xlim([-2, 2])
    plt.ylim([-2, 2])
    plt.show()

    eta, lam = 20, [1.5, .5]
    skst = SkStBL(ndim=len(lam), eta=eta, lam=lam)
    skst.plot_bidensity()

    rvs = skst.rvs(size=size)
    sns.kdeplot(rvs, shade=True)
    plt.axis('square')
    plt.xlim([-2, 2])
    plt.ylim([-2, 2])
    plt.show()

    eta, lam = 20, [1.5, -2]
    skst = SkStDM(ndim=len(lam), eta=eta, lam=lam)
    skst.plot_bidensity()

    rvs = skst.rvs(size=size)
    sns.kdeplot(rvs, shade=True)
    plt.axis('square')
    plt.xlim([-2, 2])
    plt.ylim([-2, 2])
    plt.show()

    eta, lam = 20, [1.5, -2]
    skst = SkStAC(ndim=len(lam), eta=eta, lam=lam)
    skst.plot_bidensity()

    rvs = skst.rvs(size=size)
    sns.kdeplot(rvs, shade=True)
    plt.axis('square')
    plt.xlim([-2, 2])
    plt.ylim([-2, 2])
    plt.show()
    def test_init(self):
        """Test __init__."""

        mvst = MvSt(ndim=3)

        self.assertIsInstance(mvst.eta, np.ndarray)

        eta = 10
        mvst = MvSt(ndim=1, eta=eta)

        npt.assert_array_equal(mvst.eta, np.array(eta))

        mu, sigma = [.5, .4], np.ones((2, 2))
        mvst = MvSt(ndim=len(mu), eta=eta, mu=mu, sigma=sigma)

        npt.assert_array_equal(mvst.mu, np.array(mu))
        npt.assert_array_equal(mvst.sigma, np.array(sigma))
        npt.assert_array_equal(mvst.const_mu(), np.array(mu))
        npt.assert_array_equal(mvst.const_sigma(), np.array(sigma))

        eta = 15
        mvst.from_theta(eta)

        self.assertEqual(mvst.eta, eta)

        ndim = 2
        size = (10, ndim)
        data = np.random.normal(size=size)
        skst = MvSt(ndim=ndim, data=data)

        npt.assert_array_equal(skst.data, data)