def test_iterator(): """ Tests whether SparseDataset can be loaded and initializes iterator """ x = csr_matrix([[1, 2, 0], [0, 0, 3], [4, 0, 5]]) ds = SparseDataset(from_scipy_sparse_dataset=x) it = ds.iterator(mode='sequential', batch_size=1) it.next()
def test_training_a_model(): """ tests wether SparseDataset can be trained with a dummy model. """ dim = 3 m = 10 rng = np.random.RandomState([22, 4, 2014]) X = rng.randn(m, dim) ds = csr_matrix(X) dataset = SparseDataset(from_scipy_sparse_dataset=ds) model = SoftmaxModel(dim) learning_rate = 1e-1 batch_size = 5 epoch_num = 2 termination_criterion = EpochCounter(epoch_num) cost = DummyCost() algorithm = SGD(learning_rate, cost, batch_size=batch_size, termination_criterion=termination_criterion, update_callbacks=None, init_momentum=None, set_batch_size=False) train = Train(dataset, model, algorithm, save_path=None, save_freq=0, extensions=None) train.main_loop()