From 6082f2e5d4ff2f07d3488614d0f596ed2d5f403e Mon Sep 17 00:00:00 2001 From: ernestoarbitrio Date: Fri, 10 Jul 2020 12:32:04 +0200 Subject: [PATCH] fix counts for mr mr augmented matrix --- src/cr/cube/matrix.py | 13 ++++++++----- tests/integration/test_multiple_response.py | 10 +++++----- tests/integration/test_pairwise_significance.py | 10 +++++----- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/cr/cube/matrix.py b/src/cr/cube/matrix.py index 979ddb35a..9f9ee7bec 100644 --- a/src/cr/cube/matrix.py +++ b/src/cr/cube/matrix.py @@ -268,13 +268,13 @@ def factory(cls, cube, dimensions, slice_idx): base_counts, counts_with_missings, ) - - # These are apparent dimensions which hide 'selections' dims behind 'MR' dimensions = cube.dimensions[:-1] - counts = np.sum(counts[:, :, :, 0], axis=3) - base_counts = np.sum(base_counts[:, :, :, 0], axis=3) - counts_with_missings = np.sum(counts_with_missings[:, :, :, 0], axis=3) if cube.dimension_types[0] == DT.MR: + counts = np.sum(counts[:, :, :, :, 0], axis=4) + base_counts = np.sum(base_counts[:, :, :, :, 0], axis=4) + counts_with_missings = np.sum( + counts_with_missings[:, :, :, :, 0], axis=4 + ) return _MrXMrMatrix( dimensions, counts, @@ -282,6 +282,9 @@ def factory(cls, cube, dimensions, slice_idx): counts_with_missings, overlap_tstats, ) + counts = np.sum(counts[:, :, :, 0], axis=3) + base_counts = np.sum(base_counts[:, :, :, 0], axis=3) + counts_with_missings = np.sum(counts_with_missings[:, :, :, 0], axis=3) return _CatXMrMatrix( dimensions, counts, base_counts, counts_with_missings, overlap_tstats ) diff --git a/tests/integration/test_multiple_response.py b/tests/integration/test_multiple_response.py index d379853e1..1463136ad 100644 --- a/tests/integration/test_multiple_response.py +++ b/tests/integration/test_multiple_response.py @@ -896,11 +896,11 @@ def test_mr_x_num_with_means_pruned(): def test_mr_x_mr_itself_zscore(): slice_ = Cube(CR.MR_X_MR_ITSELF).partitions[0] expected = [ - [-2.09809816e-01, -2.47663660e-01, 0.00000000e00], - [2.79428953e-01, 1.54988917e-01, 0.00000000e00], - [-2.15682422e-01, -6.37644486e-02, -3.01876861e-15], - [3.68523425e-01, 5.62052405e-01, 7.96003449e-15], - [-1.87152853e-01, -3.78529911e-01, 0.00000000e00], + [2.02358771, 4.40571894, -4.73781476], + [1.6374635, 2.98524415, -2.88925509], + [1.40611428, -0.26969232, -1.03556062], + [1.67279974, -0.46401375, 0.06965056], + [-3.37595335, -1.34855138, 3.10157807], ] np.testing.assert_almost_equal(slice_.zscore, expected) diff --git a/tests/integration/test_pairwise_significance.py b/tests/integration/test_pairwise_significance.py index 54be0240e..7c5fd6901 100644 --- a/tests/integration/test_pairwise_significance.py +++ b/tests/integration/test_pairwise_significance.py @@ -593,10 +593,10 @@ def test_mr_x_mr_itself_pairwise_compare_columns(self): np.testing.assert_array_almost_equal( actual.p_vals, [ - [3.00272449e-01, 1, 3.60013917e-01], - [3.03167992e-01, 1, 1.52766688e-13], - [5.63934548e-01, 1, 0.00000000e00], - [7.32894024e-01, 1, 0.00000000e00], - [3.68215623e-02, 1, 0.00000000e00], + [3.00368306e-01, 1.00000000e00, 3.60015180e-01], + [3.03263297e-01, 1.00000000e00, 1.53432822e-13], + [5.63984270e-01, 1.00000000e00, 0.00000000e00], + [7.32921470e-01, 1.00000000e00, 0.00000000e00], + [3.69178553e-02, 1.00000000e00, 0.00000000e00], ], )