Esempio n. 1
0
    def test_get_knots_2d(self):
        expected = np.linspace(0, 5, 3, endpoint=True)
        actual = _get_knotlocs(np.array([3, 5, 4, 0]).reshape((-1, 1)),
                               3,
                               uniform=True)

        assert actual.ndim == 1
        np.testing.assert_array_equal(actual, expected)
Esempio n. 2
0
    def test_get_knots_unique(self, seed: int, n_knots: int):
        np.random.seed(seed)
        x = np.random.normal(size=(100,))
        actual = _get_knotlocs(x, n_knots=n_knots)

        assert actual.shape == (n_knots,)
        np.testing.assert_array_equal(actual, np.sort(actual))
        assert len(np.unique(actual)) == len(actual), actual
        assert (np.min(actual), np.max(actual)) == (np.min(x), np.max(x))
Esempio n. 3
0
    def test_get_knots_heavy_tail(self):
        x = np.array([0] * 30 + list(np.linspace(0.1, 0.9, 30)) + [1] * 30)
        expected = np.array([
            0.0,
            0.02222222,
            0.04444444,
            0.06666667,
            0.36360153,
            0.63639847,
            0.93333333,
            0.95555556,
            0.97777778,
            1.0,
        ])

        actual = _get_knotlocs(x, 10, uniform=False)

        np.testing.assert_almost_equal(actual, expected)
Esempio n. 4
0
    def test_get_knots_1_knot(self):
        actual = _get_knotlocs(np.array([3, 5, 4, 0]), 1, uniform=False)

        np.testing.assert_array_equal(actual, [5])
Esempio n. 5
0
    def test_get_knots_uniform(self):
        expected = np.linspace(0, 5, 3, endpoint=True)
        actual = _get_knotlocs(np.array([3, 5, 4, 0]), 3, uniform=True)

        np.testing.assert_array_equal(actual, expected)
Esempio n. 6
0
 def test_get_knots_empty_pseudotime(self):
     with pytest.raises(ValueError):
         _get_knotlocs(np.array([]), 2)
Esempio n. 7
0
 def test_get_knots_only_same_value(self):
     with pytest.raises(ValueError):
         _get_knotlocs(np.array([42] * 10), 1)
Esempio n. 8
0
 def test_get_knots_wrong_shape(self):
     with pytest.raises(ValueError):
         _get_knotlocs(np.array([0, 1, 2, 3]).reshape((2, 2)), 1)
Esempio n. 9
0
 def test_get_knots_non_finite_values(self):
     x = np.array([0, 1, 2, 3], dtype=np.float64)
     x[-1] = np.inf
     with pytest.raises(ValueError):
         _get_knotlocs(x, 1)
Esempio n. 10
0
 def test_get_knots_invalid_n_knots(self):
     with pytest.raises(ValueError):
         _get_knotlocs([0, 1, 2], 0)