code: def create_calc_dh_d_alpha(estimator):
      
      if estimator.intercept_ref_pos is not None:
          needed_idxs = range(estimator.rows_to_alts.shape[1])
          needed_idxs.remove(estimator.intercept_ref_pos)
          dh_d_alpha = (estimator.rows_to_alts
                                 .copy()
                                 .transpose()[needed_idxs, :]
                                 .transpose())
      else:
          dh_d_alpha = None
      # Create a function that will take in the pre-formed matrix, replace its
      # data in-place with the new data, and return the correct dh_dalpha on each
      # iteration of the minimizer
      calc_dh_d_alpha = partial(_cloglog_transform_deriv_alpha,
                                output_array=dh_d_alpha)
  
      return calc_dh_d_alpha
docs: Return the function that can be used in the various gradient and hessian
      calculations to calculate the derivative of the transformation with respect
      to the outside intercept parameters.
  
      Parameters
      ----------
      estimator : an instance of the estimation.LogitTypeEstimator class.
          Should contain a `rows_to_alts` attribute that is a 2D scipy sparse
          matrix that maps the rows of the `design` matrix to the alternatives
          available in this dataset. Should also contain an `intercept_ref_pos`
          attribute that is either None or an int. This attribute should denote
          which intercept is not being estimated (in the case of outside
          intercept parameters) for identification purposes.
  
      Returns
      -------
      Callable.
          Will accept a 1D array of systematic utility values, a 1D array of
          alternative IDs, (shape parameters if there are any) and miscellaneous
          args and kwargs. Should return a 2D array whose elements contain the
          derivative of the tranformed utility vector with respect to the vector
          of outside intercepts. The dimensions of the returned vector should
          be `(design.shape[0], num_alternatives - 1)`.