code: def alignment(layer, decay_ratio=2):
    
    def inner(T):
      batch_n = T(layer).get_shape().as_list()[0]
      arr = T(layer)
      accum = 0
      for d in [1, 2, 3, 4]:
        for i in range(batch_n - d):
          a, b = i, i+d
          arr1, arr2 = arr[a], arr[b]
          accum += tf.reduce_mean((arr1-arr2)**2) / decay_ratio**float(d)
      return -accum
    return inner
docs: Encourage neighboring images to be similar.
  
    When visualizing the interpolation between two objectives, it's often
    desireable to encourage analagous boejcts to be drawn in the same position,
    to make them more comparable.
  
    This term penalizes L2 distance between neighboring images, as evaluated at
    layer.
  
    In general, we find this most effective if used with a paramaterization that
    shares across the batch. (In fact, that works quite well by iteself, so this
    function may just be obselete.)
  
    Args:
      layer: layer to penalize at.
      decay_ratio: how much to decay penalty as images move apart in batch.
  
    Returns:
      Objective.