def test_lagged_iterator_1d(self): n = 57 chunksize = 10 lag = 1 data = [np.arange(n), np.arange(50), np.arange(30)] input_lens = [x.shape[0] for x in data] reader = DataInMemory(data) reader.chunksize = chunksize self.assertEqual(reader.n_frames_total(), sum(input_lens)) # store results by traj chunked_trajs = [[] for _ in range(len(data))] chunked_lagged_trajs = [[] for _ in range(len(data))] # iterate over data for itraj, X, Y in reader.iterator(lag=lag): chunked_trajs[itraj].append(X) chunked_lagged_trajs[itraj].append(Y) trajs = [np.vstack(ichunks) for ichunks in chunked_trajs] lagged_trajs = [np.vstack(ichunks) for ichunks in chunked_lagged_trajs] # unlagged data for traj, input_traj in zip(trajs, data): np.testing.assert_equal(traj.reshape(input_traj.shape), input_traj) # lagged data lagged_0 = [d[lag:] for d in data] for traj, input_traj in zip(lagged_trajs, lagged_0): np.testing.assert_equal(traj.reshape(input_traj.shape), input_traj)
def test_lagged_iterator_2d(self): chunksize = 10 lag = 1 data = [ np.arange(300).reshape((100, 3)), np.arange(29 * 3).reshape((29, 3)), np.arange(150).reshape(50, 3) ] input_lens = [x.shape[0] for x in data] # print data[0].shape reader = DataInMemory(data) reader.chunksize = chunksize self.assertEqual(reader.n_frames_total(), sum(input_lens)) # store results by traj chunks = [[] for _ in range(len(data))] lagged_chunks = [[] for _ in range(len(data))] # iterate over data for itraj, X, Y in reader.iterator(lag=lag): chunks[itraj].append(X) lagged_chunks[itraj].append(Y) trajs = [np.vstack(ichunks) for ichunks in chunks] lagged_trajs = [np.vstack(ichunks) for ichunks in lagged_chunks] # unlagged data for traj, input_traj in zip(trajs, data): # do not consider chunks that have no lagged counterpart input_shape = input_traj.shape np.testing.assert_equal(traj.reshape((input_shape[0] - lag, 3)), input_traj[:len(input_traj) - lag]) # lagged data lagged_0 = [d[lag:] for d in data] for traj, input_traj in zip(lagged_trajs, lagged_0): np.testing.assert_equal(traj.reshape(input_traj.shape), input_traj)
def testChunksizeResultsTica(self): chunk = 40 lag = 100 np.random.seed(0) X = np.random.randn(23000, 3) # un-chunked d = DataInMemory(X) tica_obj = api.tica(data=d, lag=lag, dim=1) cov = tica_obj.cov.copy() mean = tica_obj.mean.copy() # ------- run again with new chunksize ------- d = DataInMemory(X) d.chunksize = chunk tica_obj = tica(data=d, lag=lag, dim=1) np.testing.assert_allclose(tica_obj.mean, mean) np.testing.assert_allclose(tica_obj.cov, cov)
def testChunksizeResultsTica(self): chunk = 40 lag = 100 np.random.seed(0) X = np.random.randn(23000, 3) # un-chunked d = DataInMemory(X) tica_obj = api.tica(data=d, lag=lag, dim=1) cov = tica_obj.cov.copy() mean = tica_obj.mu.copy() # ------- run again with new chunksize ------- d = DataInMemory(X) d.chunksize = chunk tica_obj = tica(data=d, lag=lag, dim=1) np.testing.assert_allclose(tica_obj.mu, mean) np.testing.assert_allclose(tica_obj.cov, cov)
def test_lagged_iterator_2d(self): n = 57 chunksize = 10 lag = 1 # data = [np.random.random((n, 3)), # np.zeros((29, 3)), # np.random.random((n - 50, 3))] data = [np.arange(300).reshape((100, 3)), np.arange(29 * 3).reshape((29, 3)), np.arange(150).reshape(50, 3)] input_lens = [x.shape[0] for x in data] # print data[0].shape reader = DataInMemory(data) reader.chunksize = chunksize self.assertEqual(reader.n_frames_total(), sum(input_lens)) # store results by traj chunks = [[] for _ in xrange(len(data))] lagged_chunks = [[] for _ in xrange(len(data))] # iterate over data for itraj, X, Y in reader.iterator(lag=lag): chunks[itraj].append(X) lagged_chunks[itraj].append(Y) trajs = [np.vstack(ichunks) for ichunks in chunks] lagged_trajs = [np.vstack(ichunks) for ichunks in lagged_chunks] # unlagged data for traj, input_traj in zip(trajs, data): np.testing.assert_equal(traj.reshape(input_traj.shape), input_traj) # lagged data lagged_0 = [d[lag:] for d in data] for traj, input_traj in zip(lagged_trajs, lagged_0): np.testing.assert_equal(traj.reshape(input_traj.shape), input_traj)