'Runs one epoch of SGD training on the specified dataset.
Parameters
dataset : Dataset'

def train(self, dataset):

    if (not hasattr(self, 'd_func')):
        raise Exception('train    called    without    first    calling    setup')
    for param in self.params:
        value = param.get_value(borrow=True)
        if (np.any(np.isnan(value)) or np.any(np.isinf(value))):
            raise Exception(('NaN    in    ' + param.name))
    self.first = False
    rng = self.rng
    if (not is_stochastic(self.train_iteration_mode)):
        rng = None
    data_specs = self.cost.get_data_specs(self.model)
    mapping = DataSpecsMapping(data_specs)
    space_tuple = mapping.flatten(data_specs[0], return_tuple=True)
    source_tuple = mapping.flatten(data_specs[1], return_tuple=True)
    if (len(space_tuple) == 0):
        raise NotImplementedError(('Unable    to    train    with    SGD,    because    the    cost    does    not    actually    use    data    from    the    data    set.    data_specs:    %s' % str(data_specs)))
    flat_data_specs = (CompositeSpace(space_tuple), source_tuple)
    iterator = dataset.iterator(mode=self.train_iteration_mode, batch_size=self.batch_size, data_specs=flat_data_specs, return_tuple=True, rng=rng, num_batches=self.batches_per_iter)
    on_load_batch = self.on_load_batch
    i = 0
    for batch in iterator:
        for callback in on_load_batch:
            callback(*batch)
        if (self.train_generator and (i == self.discriminator_steps)):
            self.g_func(*batch)
            i = 0
        else:
            self.d_func(*batch)
            i += 1
        actual_batch_size = flat_data_specs[0].np_batch_size(batch)
        self.monitor.report_batch(actual_batch_size)
        for callback in self.update_callbacks:
            callback(self)
    for param in self.params:
        value = param.get_value(borrow=True)
        if (np.any(np.isnan(value)) or np.any(np.isinf(value))):
            raise Exception(('NaN    in    ' + param.name))
    self.train_generator = (not self.train_generator)
