def nmf_init(data, clusters, k, init='<STR_LIT>'):
init_w = np.zeros((data.shape[<NUM_LIT:0>], k))<EOL>if sparse.issparse(data):<EOL><INDENT>for i in range(k):<EOL><INDENT>if data[:,clusters==i].shape[<NUM_LIT:1>]==<NUM_LIT:0>:<EOL><INDENT>point = np.random.randint(<NUM_LIT:0>, data.shape[<NUM_LIT:1>])<EOL>init_w[:,i] = data[:,point].toarray().flatten()<EOL><DEDENT>else:<EOL><INDENT>init_w[:,i] = np.array(data[:,clusters==i].mean(<NUM_LIT:1>)).flatten()<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>for i in range(k):<EOL><INDENT>if data[:,clusters==i].shape[<NUM_LIT:1>]==<NUM_LIT:0>:<EOL><INDENT>point = np.random.randint(<NUM_LIT:0>, data.shape[<NUM_LIT:1>])<EOL>init_w[:,i] = data[:,point].flatten()<EOL><DEDENT>else:<EOL><INDENT>init_w[:,i] = data[:,clusters==i].mean(<NUM_LIT:1>)<EOL><DEDENT><DEDENT><DEDENT>init_h = np.zeros((k, data.shape[<NUM_LIT:1>]))<EOL>if init == '<STR_LIT>':<EOL><INDENT>distances = np.zeros((k, data.shape[<NUM_LIT:1>]))<EOL>for i in range(k):<EOL><INDENT>for j in range(data.shape[<NUM_LIT:1>]):<EOL><INDENT>distances[i,j] = np.sqrt(((data[:,j] - init_w[:,i])**<NUM_LIT:2>).sum())<EOL><DEDENT><DEDENT>for i in range(k):<EOL><INDENT>for j in range(data.shape[<NUM_LIT:1>]):<EOL><INDENT>init_h[i,j] = <NUM_LIT:1>/((distances[:,j]/distances[i,j])**(-<NUM_LIT:2>)).sum()<EOL><DEDENT><DEDENT><DEDENT>elif init == '<STR_LIT>':<EOL><INDENT>init_h = initialize_from_assignments(clusters, k)<EOL><DEDENT>elif init == '<STR_LIT>':<EOL><INDENT>init_h_, _, n_iter = non_negative_factorization(data.T, n_components=k, init='<STR_LIT>', update_H=False, H=init_w.T)<EOL>init_h = init_h_.T<EOL><DEDENT>return init_w, init_h<EOL>
runs enhanced NMF initialization from clusterings (Gong 2013)

There are 3 options for init:
    enhanced - uses EIn-NMF from Gong 2013
    basic - uses means for W, assigns H such that the chosen cluster for a given cell has value 0.75 and all others have 0.25/(k-1).
    nmf - uses means for W, and assigns H using the NMF objective while holding W constant.