diff --git a/src/flowsom/models/batch/_som.py b/src/flowsom/models/batch/_som.py index e9b1447..71ab5e4 100644 --- a/src/flowsom/models/batch/_som.py +++ b/src/flowsom/models/batch/_som.py @@ -1,4 +1,4 @@ -from __future__ import annotations +"""Code adapted from student assignment Computational Biology 2024, Ghent University.""" from typing import Callable diff --git a/src/flowsom/models/batch/som_estimator.py b/src/flowsom/models/batch/som_estimator.py index 7a13a4d..d857417 100644 --- a/src/flowsom/models/batch/som_estimator.py +++ b/src/flowsom/models/batch/som_estimator.py @@ -8,6 +8,7 @@ from . import SOM_Batch, map_data_to_codes +# TODO: try to use the same code for both SOMEstimator and BatchSOMEstimator class BatchSOMEstimator(BaseClusterEstimator): """Estimate a Self-Organizing Map (SOM) clustering model.""" diff --git a/tests/models/test_BatchFlowSOM.py b/tests/models/test_BatchFlowSOM.py new file mode 100644 index 0000000..7284123 --- /dev/null +++ b/tests/models/test_BatchFlowSOM.py @@ -0,0 +1,35 @@ +from sklearn.metrics import v_measure_score + +from flowsom.models import BatchFlowSOMEstimator + + +def test_clustering(X): + fsom = BatchFlowSOMEstimator(n_clusters=10) + y_pred = fsom.fit_predict(X) + assert y_pred.shape == (100,) + + +def test_clustering_v_measure(X_and_y): + som = BatchFlowSOMEstimator(n_clusters=10) + X, y_true = X_and_y + y_pred = som.fit_predict(X) + score = v_measure_score(y_true, y_pred) + assert score > 0.7 + + +def test_reproducibility_no_seed(X): + fsom_1 = BatchFlowSOMEstimator(n_clusters=10) + fsom_2 = BatchFlowSOMEstimator(n_clusters=10) + y_pred_1 = fsom_1.fit_predict(X) + y_pred_2 = fsom_2.fit_predict(X) + + assert not all(y_pred_1 == y_pred_2) + + +def test_reproducibility_seed(X): + fsom_1 = BatchFlowSOMEstimator(n_clusters=10, seed=0) + fsom_2 = BatchFlowSOMEstimator(n_clusters=10, seed=0) + y_pred_1 = fsom_1.fit_predict(X) + y_pred_2 = fsom_2.fit_predict(X) + + assert all(y_pred_1 == y_pred_2)