INNER CODE UNIT · Python
NMF2
ShixiangWang/sigminer · inst/py/nmf.py:30
def NMF2(i, V, rank):
print("Starting NMF run: %d." %i)
return NMF(V, rank)
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"]