示例#1
0
 def test_softmax(self, mocker, lineage: Lineage):
     try:
         _ = lineage.reduce("foo", "bar", normalize_weights="softmax", mode="dist")
     except ValueError:
         pass
     finally:
         mocker.assert_called_once()
示例#2
0
    def test_normal_run_combination_only_1(self, lineage: Lineage):
        lin = lineage.reduce("foo, bar")

        assert lin.shape == (10, 1)
        np.testing.assert_allclose(np.sum(lin, axis=1), 1.0)
        np.testing.assert_array_equal(lin.names, ["bar or foo"])
        np.testing.assert_array_equal(lin.colors, lineage[["foo, bar"]].colors)
示例#3
0
 def test_row_normalize(self, mocker, lineage: Lineage):
     try:
         _ = lineage.reduce("foo", "bar", mode="scale")
     except ValueError:
         pass
     finally:
         mocker.assert_called_once()
示例#4
0
 def test_mutual_info(self, mocker, lineage: Lineage):
     try:
         _ = lineage.reduce("foo", "bar", dist_measure="mutual_info", mode="dist")
     except ValueError:
         pass
     finally:
         mocker.assert_called_once()
示例#5
0
    def test_normal_run(self, lineage: Lineage):
        lin = lineage.reduce("foo", "bar")

        assert lin.shape == (10, 2)
        np.testing.assert_allclose(np.sum(lin, axis=1), 1.0)
        np.testing.assert_array_equal(lin.names, ["foo", "bar"])
        np.testing.assert_array_equal(lin.colors, lineage[["foo", "bar"]].colors)
示例#6
0
 def test_equal(self, mocker, lineage: Lineage):
     try:
         _ = lineage.reduce("foo", "bar", dist_measure="equal", mode="dist")
     except ValueError:
         pass
     finally:
         # should be twice, but we have extra check inside and we're mocking that does nothing
         mocker.assert_called_once()
示例#7
0
    def test_return_weights_mode_dist(self, lineage: Lineage):
        lin, weights = lineage.reduce("foo",
                                      "bar",
                                      mode="dist",
                                      return_weights=True)

        assert isinstance(lin, Lineage)
        assert isinstance(weights, DataFrame)
示例#8
0
    def test_return_weights_mode_scale(self, lineage: Lineage):
        lin, weights = lineage.reduce("foo",
                                      "bar",
                                      mode="scale",
                                      return_weights=True)

        assert isinstance(lin, Lineage)
        assert weights is None
示例#9
0
    def test_normal_run_combination_all(self, lineage: Lineage):
        assert lineage.shape == (10, 4)
        lin = lineage.reduce("foo, bar", "baz, quux")

        assert lin.shape == (10, 2)
        np.testing.assert_allclose(np.sum(lin, axis=1), 1.0)
        np.testing.assert_array_equal(lin.names, ["bar or foo", "baz or quux"])
        np.testing.assert_array_equal(
            lin.colors, lineage[["foo, bar", "baz or quux"]].colors)
示例#10
0
 def test_invalid_weight_normalize(self, lineage: Lineage):
     with pytest.raises(ValueError):
         lineage.reduce("foo", "bar", normalize_weights="foo")
示例#11
0
 def test_invalid_dist_measure(self, lineage: Lineage):
     with pytest.raises(ValueError):
         lineage.reduce("foo", "bar", dist_measure="foo")
示例#12
0
 def test_invalid_mode(self, lineage: Lineage):
     with pytest.raises(ValueError):
         lineage.reduce("foo", "bar", mode="foo")
示例#13
0
 def test_all_names(self, lineage: Lineage):
     lin = lineage.reduce(*lineage.names)
     np.testing.assert_array_equal(lin.X, lineage.X)
示例#14
0
 def test_invalid_key(self, lineage: Lineage):
     with pytest.raises(KeyError):
         lineage.reduce("non_existent")
示例#15
0
 def test_not_summing_to_1(self, lineage: Lineage):
     lineage[0, 0] = 0
     with pytest.raises(ValueError):
         lineage.reduce("foo")
示例#16
0
 def test_empty_keys(self, lineage: Lineage):
     with pytest.raises(ValueError):
         lineage.reduce()