code: def costFactory(i):
      """a cost factory for the cost function"""
  
      def cost(rv):
          """compute the diameter as a calculation of cost
  
          Input:
            - rv -- 1-d array of model parameters
  
          Output:
            - diameter -- scale * | F(x) - F(x')|**2
          """
  
          # prepare x and xprime
          params = rv[:-1]  # XXX: assumes Xi' is at rv[-1]
          params_prime = (
              rv[:i] + rv[-1:] + rv[i + 1 : -1]
          )  # XXX: assumes Xi' is at rv[-1]
  
          # get the F(x) response
          Fx = function(params)
  
          # get the F(x') response
          Fxp = function(params_prime)
  
          # compute diameter
          return -scale * (Fx - Fxp) ** 2
  
      return cost
  
label_desc: Use image node_id 2 for calling a global function with example usage: costFactory(i) and returns: cost, unknown