import theanets

import util


class TestTrainer(util.MNIST):
    def setUp(self):
        super(TestTrainer, self).setUp()
        self.exp = theanets.Experiment(
            theanets.Autoencoder,
            layers=(self.DIGIT_SIZE, 10, self.DIGIT_SIZE))

    def assert_progress(self, algo, **kwargs):
        trainer = self.exp.itertrain(self.images, optimize=algo, **kwargs)
        costs0 = next(trainer)
        costs1 = next(trainer)
        costs2 = next(trainer)
        assert costs2['loss'] < costs0['loss']

    def test_sgd(self):
        self.assert_progress('sgd', learning_rate=1e-4)

    def test_nag(self):
        self.assert_progress('nag', learning_rate=1e-4)

    def test_rprop(self):
        self.assert_progress('rprop', learning_rate=1e-4)

    def test_rmsprop(self):
        self.assert_progress('rmsprop', learning_rate=1e-4)

    def test_adadelta(self):
        self.assert_progress('adadelta', learning_rate=1e-4)

    def test_cg(self):
        self.assert_progress('cg')

    def test_layerwise(self):
        self.exp = theanets.Experiment(
            theanets.Autoencoder,
            layers=(self.DIGIT_SIZE, 10, 10, self.DIGIT_SIZE))
        self.assert_progress('layerwise')

@@ -381,21 +381,21 @@
         
-costs
+t0, v
 0 = next
@@ -412,21 +412,21 @@
         
-costs
+t1, v
 1 = next
@@ -443,21 +443,21 @@
         
-costs
+t2, v
 2 = next
@@ -481,21 +481,17 @@
  assert 
-costs
+t
 2%5B'loss'
@@ -498,13 +498,9 @@
 %5D %3C 
-costs
+t
 0%5B'l

Update test to work with new monitors.