'Helper function for fit which performs training on a dataset for one epoch.
Arguments:
dataset (NervanaDataIterator): Dataset iterator to perform fit on'

def _epoch_fit(self, dataset, callbacks):

    epoch = self.epoch_index
    self.total_cost[:] = 0
    for (mb_idx, (x, t)) in enumerate(dataset):
        callbacks.on_minibatch_begin(epoch, mb_idx)
        self.be.begin(Block.minibatch, mb_idx)
        x = self.fprop(x)
        self.total_cost[:] = (self.total_cost + self.cost.get_cost(x, t))
        delta = self.cost.get_errors(x, t)
        self.bprop(delta)
        self.optimizer.optimize(self.layers_to_optimize, epoch=epoch)
        self.be.end(Block.minibatch, mb_idx)
        callbacks.on_minibatch_end(epoch, mb_idx)
    self.total_cost[:] = (self.total_cost / dataset.nbatches)
