def poisson_estimate_state(data, clusters, init_means=None, init_weights=None, method='<STR_LIT>', max_iters=<NUM_LIT:30>, tol=<NUM_LIT:0>, disp=False, inner_max_iters=<NUM_LIT:100>, normalize=True, initialization='<STR_LIT>', parallel=True, threads=<NUM_LIT:4>, max_assign_weight=<NUM_LIT>, run_w_first=True, constrain_w=False, regularization=<NUM_LIT:0.0>, write_progress_file=None, **kwargs):
genes, cells = data.shape<EOL>means, w_init = initialize_means_weights(data, clusters, init_means, init_weights, initialization, max_assign_weight)<EOL>X = data.astype(float)<EOL>XT = X.T<EOL>is_sparse = False<EOL>if sparse.issparse(X):<EOL><INDENT>is_sparse = True<EOL>update_fn = sparse_nolips_update_w<EOL>X = sparse.csc_matrix(X)<EOL>XT = sparse.csc_matrix(XT)<EOL>if parallel:<EOL><INDENT>update_fn = parallel_sparse_nolips_update_w<EOL><DEDENT>Xsum = np.asarray(X.sum(<NUM_LIT:0>)).flatten()<EOL>Xsum_m = np.asarray(X.sum(<NUM_LIT:1>)).flatten()<EOL>method = '<STR_LIT>'<EOL>objective_fn = _call_sparse_obj<EOL><DEDENT>else:<EOL><INDENT>objective_fn = objective<EOL>update_fn = nolips_update_w<EOL>Xsum = X.sum(<NUM_LIT:0>)<EOL>Xsum_m = X.sum(<NUM_LIT:1>)<EOL>if method == '<STR_LIT>':<EOL><INDENT>is_sparse = True<EOL>X = sparse.csc_matrix(X)<EOL>XT = sparse.csc_matrix(XT)<EOL>update_fn = sparse_nolips_update_w<EOL>if parallel:<EOL><INDENT>update_fn = parallel_sparse_nolips_update_w<EOL><DEDENT>objective_fn = _call_sparse_obj<EOL><DEDENT><DEDENT>w_new = w_init<EOL>for i in range(max_iters):<EOL><INDENT>if disp:<EOL><INDENT>print('<STR_LIT>'.format(i))<EOL><DEDENT>if run_w_first:<EOL><INDENT>w_new = _estimate_w(X, w_new, means, Xsum, update_fn, objective_fn, is_sparse, parallel, threads, method, tol, disp, inner_max_iters, '<STR_LIT>', regularization)<EOL>if constrain_w:<EOL><INDENT>w_new = w_new/w_new.sum(<NUM_LIT:0>)<EOL><DEDENT>if disp:<EOL><INDENT>w_ll = objective_fn(X, means, w_new)<EOL>print('<STR_LIT>'.format(w_ll))<EOL><DEDENT>means = _estimate_w(XT, means.T, w_new.T, Xsum_m, update_fn, objective_fn, is_sparse, parallel, threads, method, tol, disp, inner_max_iters, '<STR_LIT:M>', regularization)<EOL>means = means.T<EOL>if disp:<EOL><INDENT>w_ll = objective_fn(X, means, w_new)<EOL>print('<STR_LIT>'.format(w_ll))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>means = _estimate_w(XT, means.T, w_new.T, Xsum_m, update_fn, objective_fn, is_sparse, parallel, threads, method, tol, disp, inner_max_iters, '<STR_LIT:M>', regularization)<EOL>means = means.T<EOL>if disp:<EOL><INDENT>w_ll = objective_fn(X, means, w_new)<EOL>print('<STR_LIT>'.format(w_ll))<EOL><DEDENT>w_new = _estimate_w(X, w_new, means, Xsum, update_fn, objective_fn, is_sparse, parallel, threads, method, tol, disp, inner_max_iters, '<STR_LIT>', regularization)<EOL>if constrain_w:<EOL><INDENT>w_new = w_new/w_new.sum(<NUM_LIT:0>)<EOL><DEDENT>if disp:<EOL><INDENT>w_ll = objective_fn(X, means, w_new)<EOL>print('<STR_LIT>'.format(w_ll))<EOL><DEDENT><DEDENT>if write_progress_file is not None:<EOL><INDENT>progress = open(write_progress_file, '<STR_LIT:w>')<EOL>progress.write(str(i))<EOL>progress.close()<EOL><DEDENT><DEDENT>if normalize:<EOL><INDENT>w_new = w_new/w_new.sum(<NUM_LIT:0>)<EOL><DEDENT>m_ll = objective_fn(X, means, w_new)<EOL>return means, w_new, m_ll<EOL>
Uses a Poisson Covex Mixture model to estimate cell states and
cell state mixing weights.

To lower computational costs, use a sparse matrix, set disp to False, and set tol to 0.

Args:
    data (array): genes x cells array or sparse matrix.
    clusters (int): number of mixture components
    init_means (array, optional): initial centers - genes x clusters. Default: from Poisson kmeans
    init_weights (array, optional): initial weights - clusters x cells, or assignments as produced by clustering. Default: from Poisson kmeans
    method (str, optional): optimization method. Current options are 'NoLips' and 'L-BFGS-B'. Default: 'NoLips'.
    max_iters (int, optional): maximum number of iterations. Default: 30
    tol (float, optional): if both M and W change by less than tol (RMSE), then the iteration is stopped. Default: 1e-10
    disp (bool, optional): whether or not to display optimization progress. Default: False
    inner_max_iters (int, optional): Number of iterations to run in the optimization subroutine for M and W. Default: 100
    normalize (bool, optional): True if the resulting W should sum to 1 for each cell. Default: True.
    initialization (str, optional): If initial means and weights are not provided, this describes how they are initialized. Options: 'cluster' (poisson cluster for means and weights), 'kmpp' (kmeans++ for means, random weights), 'km' (regular k-means), 'tsvd' (tsvd(50) + k-means). Default: tsvd.
    parallel (bool, optional): Whether to use parallel updates (sparse NoLips only). Default: True
    threads (int, optional): How many threads to use in the parallel computation. Default: 4
    max_assign_weight (float, optional): If using a clustering-based initialization, how much weight to assign to the max weight cluster. Default: 0.75
    run_w_first (bool, optional): Whether or not to optimize W first (if false, M will be optimized first). Default: True
    constrain_w (bool, optional): If True, then W is normalized after every iteration. Default: False
    regularization (float, optional): Regularization coefficient for M and W. Default: 0 (no regularization).
    write_progress_file (str, optional): filename to write progress updates to.

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