def _transform_activation(phi, params):
  """Transform an activation function phi using the given parameters."""

  params = params.copy()

  input_scale = params.pop("input_scale", None)
  input_shift = params.pop("input_shift", None)
  output_shift = params.pop("output_shift", None)
  output_scale = params.pop("output_scale", None)

  def activation(x):

    # Note: DO NOT use += and *= below! Bad things will happen.
    if input_scale is not None:
      x = x * input_scale
    if input_shift is not None:
      x = x + input_shift

    x = phi(x, **params)

    if output_shift is not None:
      x = x + output_shift
    if output_scale is not None:
      x = x * output_scale

    return x

  return activation