code: def _optimize_A(self, A):
          
          right_eigenvectors = self.right_eigenvectors_[:, :self.n_macrostates]
          flat_map, square_map = get_maps(A)
          alpha = to_flat(1.0 * A, flat_map)
  
          def obj(x):
              return -1 * self._objective_function(
                      x, self.transmat_, right_eigenvectors, square_map,
                      self.populations_
              )
  
          alpha = scipy.optimize.basinhopping(
                  obj, alpha, niter_success=1000,
          )['x']
  
          alpha = scipy.optimize.fmin(
                  obj, alpha, full_output=True, xtol=1E-4, ftol=1E-4,
                  maxfun=5000, maxiter=100000
          )[0]
  
          if np.isneginf(obj(alpha)):
              raise ValueError(
                      "Error: minimization has not located a feasible point.")
  
          A = to_square(alpha, square_map)
          return A
docs: Find optimal transformation matrix A by minimization.
  
          Parameters
          ----------
          A : ndarray
              The transformation matrix A.
  
          Returns
          -------
          A : ndarray
              The transformation matrix.