def test_krandinit(self): data = TESTDATA_2D datas = [data.reshape((200, 2)), data.reshape((20, 20))[:10]] k = int(1e6) for data in datas: np.random.seed(1234) init = _krandinit(data, k) orig_cov = np.cov(data, rowvar=0) init_cov = np.cov(init, rowvar=0) assert_allclose(orig_cov, init_cov, atol=1e-2)
def test_krandinit(self): data = TESTDATA_2D datas = [data.reshape((200, 2)), data.reshape((20, 20))[:10]] k = int(1e6) for data in datas: np.random.seed(1234) init = _krandinit(data, k) orig_cov = np.cov(data, rowvar=0) init_cov = np.cov(init, rowvar=0) assert_allclose(orig_cov, init_cov, atol=1e-2)
def test_krandinit(self): data = TESTDATA_2D datas = [data.reshape((200, 2)), data.reshape((20, 20))[:10]] k = int(1e6) for data in datas: # check that np.random.Generator can be used (numpy >= 1.17) if hasattr(np.random, 'default_rng'): rng = np.random.default_rng(1234) else: rng = np.random.RandomState(1234) init = _krandinit(data, k, rng) orig_cov = np.cov(data, rowvar=0) init_cov = np.cov(init, rowvar=0) assert_allclose(orig_cov, init_cov, atol=1e-2)