code: def link_reweighting(p, link):
      """Returns a weighting that makes mean(weights*link(p)) == link(mean(p)).
  
      This is based on a linearization of the link function. When the link function is monotonic then we
      can find a set of positive weights that adjust for the non-linear influence changes on the
      expected value. Note that there are many possible reweightings that can satisfy the above
      property. This function returns the one that has the lowest L2 norm.
      """
  
      # the linearized link function is a first order Taylor expansion of the link function
      # centered at the expected value
      expected_value = np.mean(p, axis=0)
      epsilon = 0.0001
      link_gradient = (
          link(expected_value + epsilon) - link(expected_value)
      ) / epsilon
      linearized_link = link_gradient * (p - expected_value) + link(
          expected_value
      )
  
      weights = (linearized_link - link(expected_value)) / (
          link(p) - link(expected_value)
      )
      weights *= weights.shape[0] / np.sum(weights, axis=0)
      return weights
  
imports: import copy
  import numpy
  import scipy.sparse
  from numba import njit
  from ..None import links
label_desc: Use image node_id 10 for calling a global function with example usage: link_reweighting(p, link) and returns: weights