def make_perturbation_getter(should_regularize, collector, perturbation):
  """Creates custom getter to replace variables in scope by their perturbations.

  Args:
    should_regularize: Function, takes a variable name as String and returns
      Boolean that decides whether the variable should be regularized.
    collector: `VariableCollector` object that provides the dictionary to use
      for subsequent use of the same `Variable` object for the same name.
    perturbation: Float, perturbation value added on top of 1 to use for
      variable replacement value.

  Returns:
    A custom getter function that can be used with `VariableScope`.
  """

  def plus_getter(getter, name, *args, **kwargs):
    var = collector.collector_getter(getter, name, *args, **kwargs)

    if should_regularize(name) and kwargs.get("trainable"):
      var = (1. + perturbation) * var

    return var

  return plus_getter