def itertrain(self, train, valid=None, **kwargs):
from . import feedforward<EOL>original_layer_names = set(l.name for l in self.network.layers[:-<NUM_LIT:1>])<EOL>layers_ = list(l.to_spec() for l in self.network.layers[:-<NUM_LIT:1>])<EOL>for i, l in enumerate(layers_[::-<NUM_LIT:1>][:-<NUM_LIT:2>]):<EOL><INDENT>layers_.append(dict(<EOL>form='<STR_LIT>', partner=l['<STR_LIT:name>'], activation=l['<STR_LIT>']))<EOL><DEDENT>layers_.append(dict(<EOL>form='<STR_LIT>', partner=layers_[<NUM_LIT:1>]['<STR_LIT:name>'], activation='<STR_LIT>'))<EOL>util.log('<STR_LIT>')<EOL>ae = feedforward.Autoencoder(layers=layers_)<EOL>pre = SupervisedPretrainer(self.algo, ae)<EOL>for monitors in pre.itertrain(train, valid, **kwargs):<EOL><INDENT>yield monitors<EOL><DEDENT>for param in ae.params:<EOL><INDENT>l, p = param.name.split('<STR_LIT:.>')<EOL>if l in original_layer_names:<EOL><INDENT>util.log('<STR_LIT>', param.name)<EOL>self.network.find(l, p).set_value(param.get_value())<EOL><DEDENT><DEDENT>util.log('<STR_LIT>')<EOL>
Train a model using a training and validation set.

        This method yields a series of monitor values to the caller. After every
        iteration, a pair of monitor dictionaries is generated: one evaluated on
        the training dataset, and another evaluated on the validation dataset.
        The validation monitors might not be updated during every training
        iteration; in this case, the most recent validation monitors will be
        yielded along with the training monitors.

        Parameters
        ----------
        train : :class:`Dataset <theanets.dataset.Dataset>`
            A set of training data for computing updates to model parameters.
        valid : :class:`Dataset <theanets.dataset.Dataset>`
            A set of validation data for computing monitor values and
            determining when the loss has stopped improving.

        Yields
        ------
        training : dict
            A dictionary mapping monitor names to values, evaluated on the
            training dataset.
        validation : dict
            A dictionary containing monitor values evaluated on the validation
            dataset.