def test_compute_b_2d(self): tail = LinearTail() y = np.random.rand(10) b = tail.compute_b(y, d=2) assert b.shape == (13, 1) z = np.zeros(13) z[:10] = y assert np.all(b == z.reshape((-1, 1)))
def test_to_dict(self): tail = LinearTail() tail.set_params([1, 1, 1]) output_dict = tail.to_dict() assert "class" in output_dict assert output_dict["class"] == "LinearTail" assert "params" in output_dict assert len(output_dict["params"]) == 3 assert output_dict["params"] == [1, 1, 1]
def test_evaluate(self): tail = LinearTail() tail.set_params([1, 1, 1]) x = np.random.rand(10, 2) y = tail.evaluate(x) assert y.shape == (10, ) assert np.allclose(y, x[:, 0].ravel() + x[:, 1].ravel() + np.ones(10)) tail.set_params([0, 0, 0]) x = np.random.rand(20, 2) y = tail.evaluate(x) assert y.shape == (20, ) assert np.all(y == np.zeros(20))
def test_compute_P_2d(self): tail = LinearTail() x = np.random.rand(10, 2) P = tail.compute_P(x) assert np.all(P == np.hstack((x, np.ones((10, 1)))))
def test_degree(self): tail = LinearTail() assert tail.degree == 1
def test_set_params(self): tail = LinearTail() tail.set_params([1, 1, 1]) assert tail.params == [1, 1, 1] assert np.all(tail._p == np.array([1, 1])) assert tail._c == 1
def test_params(self): tail = LinearTail() assert tail.params == [0, 0]
def test___init__(self): tail = LinearTail() assert True