INNER CODE UNIT · Python
MultiNMF
ShixiangWang/sigminer · inst/py/nmf.py:34
def MultiNMF(V, rank, nrun, cores, return_best = True):
'''Run NMF for a target matrix multiple times'''
available_cores = multiprocess.cpu_count()
if available_cores < cores:
print("Only %d cores available but %d cores requested, reset it to available number." %(available_cores, cores))
cores = available_cores
xs = range(1, nrun + 1)
with multiprocess.Pool(processes=cores) as p:
v = p.starmap(NMF2, zip(xs, repeat(V), repeat(rank)))
if return_best:
print("Compare KLD and return the best.")
l = len(v)
kld = v[0]["KLD"]
idx = 0
for i in range(1, l):
k = v[i]["KLD"]
print("KLD to compare: %f, KLD to be compared: %f" %(k, kld))