'Called when minibatch is about to end
Arguments:
callback_data (HDF5 dataset): shared data between callbacks
model (Model): model object
epoch (int): index of current epoch
minibatch (int): index of minibatch that is ending'

def on_minibatch_end(self, callback_data, model, epoch, minibatch):

    self.cost_history.append(model.cost.cost)
    mean_cost = (sum(self.cost_history) / len(self.cost_history))
    mbstart = (callback_data['time_markers/minibatch'][(epoch - 1)] if (epoch > 0) else 0)
    callback_data['cost/train'][(mbstart + minibatch)] = mean_cost
