def log_norm_nmf(data, k, normalize_w=True, return_cost=True, init_weights=None, init_means=None, write_progress_file=None, **kwargs):
init = None<EOL>data = log1p(cell_normalize(data))<EOL>if init_weights is not None or init_means is not None:<EOL><INDENT>init = '<STR_LIT>'<EOL>if init_weights is None:<EOL><INDENT>init_weights_, _, n_iter = non_negative_factorization(data.T, n_components=k, init='<STR_LIT>', update_W=False, W=init_means.T)<EOL>init_weights = init_weights_.T<EOL><DEDENT>elif init_means is None:<EOL><INDENT>init_means, _, n_iter = non_negative_factorization(data, n_components=k, init='<STR_LIT>', update_W=False, W=init_weights)<EOL><DEDENT>init_means = init_means.copy(order='<STR_LIT:C>')<EOL>init_weights = init_weights.copy(order='<STR_LIT:C>')<EOL><DEDENT>nmf = NMF(k, init=init, **kwargs)<EOL>if write_progress_file is not None:<EOL><INDENT>progress = open(write_progress_file, '<STR_LIT:w>')<EOL>progress.write(str(<NUM_LIT:0>))<EOL>progress.close()<EOL><DEDENT>M = nmf.fit_transform(data, W=init_means, H=init_weights)<EOL>W = nmf.components_<EOL>if normalize_w:<EOL><INDENT>W = W/W.sum(<NUM_LIT:0>)<EOL><DEDENT>if return_cost:<EOL><INDENT>cost = <NUM_LIT:0><EOL>if sparse.issparse(data):<EOL><INDENT>ws = sparse.csr_matrix(M)<EOL>hs = sparse.csr_matrix(W)<EOL>cost = <NUM_LIT:0.5>*((data - ws.dot(hs)).power(<NUM_LIT:2>)).sum()<EOL><DEDENT>else:<EOL><INDENT>cost = <NUM_LIT:0.5>*((data - M.dot(W))**<NUM_LIT:2>).sum()<EOL><DEDENT>return M, W, cost<EOL><DEDENT>else:<EOL><INDENT>return M, W<EOL><DEDENT>
Args:
    data (array): dense or sparse array with shape (genes, cells)
    k (int): number of cell types
    normalize_w (bool, optional): True if W should be normalized (so that each column sums to 1). Default: True
    return_cost (bool, optional): True if the NMF objective value (squared error) should be returned. Default: True
    init_weights (array, optional): Initial value for W. Default: None
    init_means (array, optional): Initial value for M. Default: None
    **kwargs: misc arguments to NMF

Returns:
    Two matrices M of shape (genes, k) and W of shape (k, cells). They correspond to M and M in Poisson state estimation. If return_cost is True (which it is by default), then the cost will also be returned. This might be prohibitably costly