code: def inv_link(scores, link, link_param=np.nan):
      """Applies the inverse link function to scores to generate predictions.
  
      Args:
          scores: Numpy array of scores for samples.
          link: string containing the type of link function to use
          link_param: Optional. numeric parameter that is specified by the link function.
  
      Returns:
          Predictions converted by the link function.
      """
  
      scores = np.array(scores, np.float64, copy=False)
      if link == "monoclassification":
          bools = np.isnan(scores)
          preds = np.ones(scores.shape + (1,), np.float64)
          preds[np.expand_dims(bools, axis=-1)] = np.nan
  
          bools |= scores == -np.inf
          if not bools.all():
              msg = "monoclassification must have all -infs or NaN"
              _log.error(msg)
              raise ValueError(msg)
  
          return preds
      elif link == "logit":
          with np.errstate(over="ignore"):
              # scores == 999 gives warning otherwise from overflow
              val = np.expand_dims(np.exp(scores), axis=-1)
          inf_bool = np.isposinf(val)
          tmp = val + 1.0
          with np.errstate(invalid="ignore"):
              # val == +inf gives warning otherwise during inf/inf
              val /= tmp
          val[inf_bool] = 1.0
          np.subtract(1.0, val, out=tmp)
          return np.c_[tmp, val]
      elif link == "vlogit":
          with np.errstate(over="ignore"):
              # scores == 999 gives warning otherwise
              val = np.exp(scores)
          inf_bool = np.isposinf(val)
          with np.errstate(invalid="ignore"):
              # val == +inf gives warning otherwise
              val /= val + 1.0
          val[inf_bool] = 1.0
          return val
      elif link == "mlogit":
          # accept multinominal with 2 classes, even though it's weird
          if scores.shape[-1] <= 1:
              msg = f"scores must have 2 or more elements in the last dimensions, but has {scores.shape[-1]}."
              _log.error(msg)
              raise ValueError(msg)
  
          reduced_float = scores.max(
              axis=-1, keepdims=True
          )  # max() preserves NaN
          inf_bool = np.isposinf(scores)
          reduced_bool = np.isneginf(reduced_float)
          inf_bool |= reduced_bool
          np.isnan(reduced_float, out=reduced_bool)
          np.logical_not(reduced_bool, out=reduced_bool)
          inf_bool &= reduced_bool
          with np.errstate(invalid="ignore"):
              # reduced_float == +inf or all -inf gives warning otherwise
              val = scores - reduced_float
          np.exp(val, out=val)
          np.any(inf_bool, axis=-1, keepdims=True, out=reduced_bool)
          val[reduced_bool.squeeze(-1)] = 0.0
          val[inf_bool] = 1.0
          np.sum(val, axis=-1, keepdims=True, out=reduced_float)
          val /= reduced_float
          return val
      elif link == "identity":
          return scores.copy()
      elif link == "log":
          with np.errstate(over="ignore"):
              # scores == 999 gives warning otherwise
              return np.exp(scores)
      else:
          raise ValueError(f"Unsupported link function: {link}")
  
imports: import numpy
  import logging
label_desc: Use image node_id 3 for calling a global function with example usage: inv_link(scores, link, link_param) and returns: preds, np, val, val, scores, np