'Make sure Polyak-averaged model gets monitored.
Save the model if necessary.
Parameters
model : a Model instance
dataset : Dataset
algorithm : WRITEME'

def on_monitor(self, model, dataset, algorithm):

    if (self._count == self.start):
        self._worker = _PolyakWorker(model)
        algorithm.update_callbacks.append(self._worker)
        try:
            model.add_polyak_channels(self._worker.param_to_mean, algorithm.monitoring_dataset)
        except AttributeError:
            pass
    elif ((self.save_path is not None) and (self._count > self.start) and ((self._count % self.save_freq) == 0)):
        saved_params = OrderedDict()
        for param in model.get_params():
            saved_params[param] = param.get_value()
            param.set_value(self._worker.param_to_mean[param].get_value())
        serial.save(self.save_path, model)
        for param in model.get_params():
            param.set_value(saved_params[param])
    self._count += 1
