def run_state_estimation(data, clusters, dist='<STR_LIT>', reps=<NUM_LIT:1>, **kwargs):
clusters = int(clusters)<EOL>func = poisson_estimate_state<EOL>dist = dist.lower()<EOL>if dist=='<STR_LIT>' or dist=='<STR_LIT>':<EOL><INDENT>pass<EOL><DEDENT>elif dist=='<STR_LIT>':<EOL><INDENT>func = nb_estimate_state<EOL><DEDENT>elif dist=='<STR_LIT>':<EOL><INDENT>func = zip_estimate_state<EOL><DEDENT>elif dist=='<STR_LIT>' or dist=='<STR_LIT>' or dist=='<STR_LIT>':<EOL><INDENT>func = log_norm_nmf<EOL><DEDENT>elif dist=='<STR_LIT>' or dist=='<STR_LIT>' or dist=='<STR_LIT>':<EOL><INDENT>func = norm_nmf<EOL><DEDENT>else:<EOL><INDENT>print('<STR_LIT>')<EOL><DEDENT>if clusters == <NUM_LIT:0>:<EOL><INDENT>from .gap_score import run_gap_k_selection, preproc_data<EOL>data_tsvd = preproc_data(data, gene_subset=False)<EOL>max_k, gap_vals, sk_vals = run_gap_k_selection(data_tsvd,<EOL>k_min=<NUM_LIT:1>, k_max=<NUM_LIT:50>, skip=<NUM_LIT:5>, B=<NUM_LIT:6>)<EOL>clusters = min(max_k, data.shape[<NUM_LIT:0>] - <NUM_LIT:1>, data.shape[<NUM_LIT:1>] - <NUM_LIT:1>)<EOL><DEDENT>best_ll = np.inf<EOL>best_M = None<EOL>best_W = None<EOL>for i in range(reps):<EOL><INDENT>results = func(data, clusters, **kwargs)<EOL>M = results[<NUM_LIT:0>]<EOL>W = results[<NUM_LIT:1>]<EOL>if dist=='<STR_LIT>':<EOL><INDENT>ll = results[<NUM_LIT:3>]<EOL><DEDENT>else:<EOL><INDENT>ll = results[<NUM_LIT:2>]<EOL><DEDENT>if ll < best_ll:<EOL><INDENT>best_ll = ll<EOL>best_M = M<EOL>best_W = W<EOL><DEDENT><DEDENT>return best_M, best_W, best_ll<EOL>
Runs state estimation for multiple initializations, returning the result with the highest log-likelihood. All the arguments are passed to the underlying state estimation functions (poisson_estimate_state, nb_estimate_state, zip_estimate_state).

Args:
    data (array): genes x cells
    clusters (int): number of mixture components. If this is set to 0, this is automatically estimated using gap score.
    dist (str, optional): Distribution used in state estimation. Options: 'Poiss', 'NB', 'ZIP', 'LogNorm', 'Gaussian'. Default: 'Poiss'
    reps (int, optional): number of times to run the state estimation, taking the result with the highest log-likelihood.
    **kwargs: arguments to pass to the underlying state estimation function.

Returns:
    M (array): genes x clusters - state means
    W (array): clusters x cells - state mixing components for each cell
    ll (float): final log-likelihood