Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/ConditionalGMM/UnivariateGMM.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
import scipy as sp

from .condGMM import *
from ConditionalGMM.condGMM import *


class UniGMM(object):
Expand Down
4 changes: 0 additions & 4 deletions src/ConditionalGMM/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
from .condGMM import *
from .MNorm import *
from .UnivariateGMM import *

__author__ = "Tom McClintock <thmsmcclintock@gmail.com>"
__version__ = "0.1.1"
2 changes: 1 addition & 1 deletion src/ConditionalGMM/condGMM.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
import scipy as sp

from .MNorm import *
from ConditionalGMM.MNorm import *


class CondGMM(object):
Expand Down
19 changes: 7 additions & 12 deletions tests/test_cGMM.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy.testing as npt
import pytest

import ConditionalGMM as cgmm
from ConditionalGMM.condGMM import CondGMM


def test_cGMM_basic():
Expand All @@ -14,22 +14,22 @@ 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():
weights = [0.5, 0.5]
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])

Expand All @@ -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():
Expand All @@ -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])
Expand All @@ -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
Expand All @@ -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()
44 changes: 20 additions & 24 deletions tests/test_cMVN.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest
import scipy.stats as ss

import ConditionalGMM as cGMM
from ConditionalGMM.MNorm import CondMNorm


def test_cMN_basic():
Expand All @@ -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():
Expand All @@ -29,33 +29,33 @@ 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():
# 2D
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])
Expand All @@ -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])
Expand All @@ -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()

Expand All @@ -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)

Expand All @@ -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:]
Expand All @@ -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:]
Expand All @@ -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()
Loading