diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 0a5c349..67ff683 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -18,8 +18,13 @@ jobs: with: python-version: ${{ matrix.python-version }} - - name: Install the project - run: uv pip install -r pyproject.toml --all-extras + - name: Build the project + run: uv build + + - name: Install the project and dependencies + run: uv sync --all-extras + + # - uses: astral-sh/ruff-action@v3 - name: Run tests with coverage run: uv run pytest tests diff --git a/src/ConditionalGMM/UnivariateGMM.py b/src/ConditionalGMM/UnivariateGMM.py index 41804c3..14edfb9 100644 --- a/src/ConditionalGMM/UnivariateGMM.py +++ b/src/ConditionalGMM/UnivariateGMM.py @@ -3,7 +3,7 @@ import numpy as np import scipy as sp -from .condGMM import * +from ConditionalGMM.condGMM import * class UniGMM(object): diff --git a/src/ConditionalGMM/__init__.py b/src/ConditionalGMM/__init__.py index 7cc312f..e755c38 100644 --- a/src/ConditionalGMM/__init__.py +++ b/src/ConditionalGMM/__init__.py @@ -1,6 +1,2 @@ -from .condGMM import * -from .MNorm import * -from .UnivariateGMM import * - __author__ = "Tom McClintock " __version__ = "0.1.1" diff --git a/src/ConditionalGMM/condGMM.py b/src/ConditionalGMM/condGMM.py index 900d181..031a840 100644 --- a/src/ConditionalGMM/condGMM.py +++ b/src/ConditionalGMM/condGMM.py @@ -3,7 +3,7 @@ import numpy as np import scipy as sp -from .MNorm import * +from ConditionalGMM.MNorm import * class CondGMM(object): diff --git a/tests/test_cGMM.py b/tests/test_cGMM.py index 2f53502..91fe927 100644 --- a/tests/test_cGMM.py +++ b/tests/test_cGMM.py @@ -4,7 +4,7 @@ import numpy.testing as npt import pytest -import ConditionalGMM as cgmm +from ConditionalGMM.condGMM import CondGMM def test_cGMM_basic(): @@ -14,14 +14,14 @@ def test_cGMM_basic(): means = [[0.5, -0.2]] covs = [[[2.0, 0.3], [0.3, 0.5]]] fixed_inds = [1] - cGMM = cgmm.CondGMM(weights, means, covs, fixed_inds) + cGMM = CondGMM(weights, means, covs, fixed_inds) # 2d - 2 component weights = [0.5, 0.5] means = [[0.5, -0.2], [0.2, -0.2]] covs = [[[2.0, 0.3], [0.3, 0.5]], [[2.0, 0.3], [0.3, 0.5]]] fixed_inds = [1] - cGMM = cgmm.CondGMM(weights, means, covs, fixed_inds) + CondGMM(weights, means, covs, fixed_inds) def test_conditionals_moments(): @@ -29,7 +29,7 @@ def test_conditionals_moments(): means = np.array([[0.5, -0.2], [0.2, -0.2]]) covs = np.array([[[2.0, 0.3], [0.3, 0.5]], [[2.0, 0.3], [0.3, 0.5]]]) fixed_inds = [1] - cGMM = cgmm.CondGMM(weights, means, covs, fixed_inds) + cGMM = CondGMM(weights, means, covs, fixed_inds) mu2 = cGMM.conditional_component_means() npt.assert_equal(np.squeeze(mu2), means[:, 0]) @@ -42,9 +42,8 @@ def test_cGMM_exceptions(): weights = [1.0] means = [[0.5, -0.2]] covs = [[[2.0, 0.3], [0.3, 0.5]]] - fixed_inds = [1] with pytest.raises(AssertionError): - cGMM = cgmm.CondGMM(weights, means, covs, 1) + CondGMM(weights, means, covs, 1) def test_rvs(): @@ -53,7 +52,7 @@ def test_rvs(): means = [[0.5, -0.2, 1.0]] cov = [[[2.0, 0.3, 0.0], [0.3, 0.5, 0.0], [0.0, 0.0, 1.0]]] ind = [2] - cGMM = cgmm.CondGMM(weights, means, cov, ind) + cGMM = CondGMM(weights, means, cov, ind) N = 10000 x1_realizations = cGMM.rvs([1], size=N, random_state=42) npt.assert_equal(x1_realizations.shape, [N, 2]) @@ -66,7 +65,7 @@ def test_rvs(): [[2.0, 0.3, 0.0], [0.3, 0.5, 0.0], [0.0, 0.0, 1.0]], ] ind = [2] - cGMM = cgmm.CondGMM(weights, means, cov, ind) + cGMM = CondGMM(weights, means, cov, ind) N = 10000 x1_realizations, labels = cGMM.rvs( [1], size=N, random_state=42, component_labels=True @@ -80,7 +79,3 @@ def test_rvs(): [1], size=1, random_state=42, component_labels=True ) npt.assert_equal([1, 2], x1_realizations.shape) - - -if __name__ == "__main__": - test_rvs() diff --git a/tests/test_cMVN.py b/tests/test_cMVN.py index 02a528b..e152b9f 100644 --- a/tests/test_cMVN.py +++ b/tests/test_cMVN.py @@ -4,7 +4,7 @@ import pytest import scipy.stats as ss -import ConditionalGMM as cGMM +from ConditionalGMM.MNorm import CondMNorm def test_cMN_basic(): @@ -13,13 +13,13 @@ def test_cMN_basic(): means = [0.5, -0.2] cov = [[2.0, 0.3], [0.3, 0.5]] ind = [0] - cMN = cGMM.CondMNorm(means, cov, ind) + cMN = CondMNorm(means, cov, ind) # 3D means = [0.5, -0.2, 1.0] cov = [[2.0, 0.3, 0.0], [0.3, 0.5, 0.0], [0.0, 0.0, 1.0]] inds = [1, 2] - cMN = cGMM.CondMNorm(means, cov, inds) + cMN = CondMNorm(means, cov, inds) def test_cMN_exceptions(): @@ -29,25 +29,25 @@ def test_cMN_exceptions(): inds = [1, 2] with pytest.raises(AssertionError): - cGMM.CondMNorm(means, cov, [-1]) + CondMNorm(means, cov, [-1]) with pytest.raises(AssertionError): - cGMM.CondMNorm(means, cov, [3]) + CondMNorm(means, cov, [3]) with pytest.raises(AssertionError): - cGMM.CondMNorm(123, cov, [1, 2]) + CondMNorm(123, cov, [1, 2]) with pytest.raises(AssertionError): - cGMM.CondMNorm(means, 123, [1, 2]) + CondMNorm(means, 123, [1, 2]) with pytest.raises(AssertionError): - cGMM.CondMNorm(means[:2], cov, [1, 2]) + CondMNorm(means[:2], cov, [1, 2]) with pytest.raises(AssertionError): - cGMM.CondMNorm(means, cov[:2], [1, 2]) + CondMNorm(means, cov[:2], [1, 2]) with pytest.raises(AssertionError): - cGMM.CondMNorm(means, cov, 2) + CondMNorm(means, cov, 2) with pytest.raises(AssertionError): - cGMM.CondMNorm(means, cov, 2) + CondMNorm(means, cov, 2) with pytest.raises(AssertionError): - cGMM.CondMNorm(means, cov, [0, 1, 2, 2]) + CondMNorm(means, cov, [0, 1, 2, 2]) with pytest.raises(AssertionError): - cGMM.CondMNorm(means, cov, [2, 2]) + CondMNorm(means, cov, [2, 2]) def test_conditional_mean_and_cov(): @@ -55,7 +55,7 @@ def test_conditional_mean_and_cov(): means = [0.5, -0.2] cov = [[2.0, 0.0], [0.0, 0.5]] ind = [1] - cMN = cGMM.CondMNorm(means, cov, ind) + cMN = CondMNorm(means, cov, ind) Sigma11 = cMN.conditional_cov() npt.assert_array_equal(Sigma11, [2.0]) mu1 = cMN.conditional_mean([1]) @@ -65,7 +65,7 @@ def test_conditional_mean_and_cov(): means = [0.5, -0.2, 1.0] cov = [[2.0, 0.3, 0.0], [0.3, 0.5, 0.0], [0.0, 0.0, 1.0]] ind = [2] - cMN = cGMM.CondMNorm(means, cov, ind) + cMN = CondMNorm(means, cov, ind) Sigma11 = cMN.conditional_cov() npt.assert_array_equal(Sigma11, [[2.0, 0.3], [0.3, 0.5]]) mu1 = cMN.conditional_mean([1]) @@ -78,7 +78,7 @@ def test_conditional_probs(): means = [0.5, -0.2, 1.0] cov = [[2.0, 0.3, 0.0], [0.3, 0.5, 0.0], [0.0, 0.0, 1.0]] ind = [2] - cMN = cGMM.CondMNorm(means, cov, ind) + cMN = CondMNorm(means, cov, ind) mu1 = cMN.conditional_mean([1]) Sigma11 = cMN.conditional_cov() @@ -99,7 +99,7 @@ def test_rvs(): means = [0.5, -0.2, 1.0] cov = [[2.0, 0.3, 0.0], [0.3, 0.5, 0.0], [0.0, 0.0, 1.0]] ind = [2] - cMN = cGMM.CondMNorm(means, cov, ind) + cMN = CondMNorm(means, cov, ind) N = 10000 x1_realizations = cMN.rvs([1], size=N, random_state=42) @@ -110,7 +110,7 @@ def test_jointpdfs(): means = [0.5, -0.2, 1.0] cov = [[2.0, 0.3, 0.0], [0.3, 0.5, 0.0], [0.0, 0.0, 1.0]] ind = [2] - cMN = cGMM.CondMNorm(means, cov, ind) + cMN = CondMNorm(means, cov, ind) x = [0.2, 0.0, 0.0] x1 = x[:2] x2 = x[2:] @@ -128,7 +128,7 @@ def test_pdf(): means = [0.5, -0.2, 1.0] cov = [[2.0, 0.3, 0.0], [0.3, 0.5, 0.0], [0.0, 0.0, 1.0]] ind = [2] - cMN = cGMM.CondMNorm(means, cov, ind) + cMN = CondMNorm(means, cov, ind) x = [0.2, 0.0, 0.0] x1 = x[:2] x2 = x[2:] @@ -144,11 +144,7 @@ def test_conditional_mean(): means = [0.5, -0.2, 1.0] cov = [[2.0, 0.3, 0.1], [0.3, 0.5, 0.1], [0.1, 0.1, 1.0]] ind = [2] - cMN = cGMM.CondMNorm(means, cov, ind) + cMN = CondMNorm(means, cov, ind) x2 = [1.0] cmean = cMN.conditional_mean(x2) npt.assert_array_equal(means[:2], cmean) - - -if __name__ == "__main__": - test_conditional_probs()