Coverage for tests/unit/test_initialization.py: 100%

14 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-02-11 20:12 +0100

1import pytest 

2import numpy as np 

3 

4from ParTIpy.initialize import furthest_sum_init, random_init 

5from ParTIpy.generate_test_data import simulate 

6 

7N_SAMPLES = 1_000 

8 

9X, A, Z = simulate(n_samples=N_SAMPLES, n_archetypes=5, n_dimensions=10, noise_std=0.0) 

10 

11 

12@pytest.mark.parametrize("init_func", [furthest_sum_init, random_init]) 

13@pytest.mark.parametrize("n_archetypes", list(range(2, 20))) 

14def test_that_initalized_B_fullfills_constraints( 

15 init_func, 

16 n_archetypes: int, 

17) -> None: 

18 B = init_func(X=X, n_archetypes=n_archetypes) 

19 assert B.shape[0] == n_archetypes 

20 assert B.shape[1] == N_SAMPLES 

21 assert np.all(np.isclose(B.sum(axis=1), 1)) 

22 assert np.all(B >= 0)