Skip to content
Snippets Groups Projects
Commit 5b338be2 authored by yager2's avatar yager2
Browse files

Replace cSNMF.py. Contains modification to allow W initialization and option to turn of update_W

parent 237334c5
No related branches found
No related tags found
No related merge requests found
...@@ -90,6 +90,7 @@ def sort_WH(W, H): ...@@ -90,6 +90,7 @@ def sort_WH(W, H):
def factorize(data_array, def factorize(data_array,
init_W = None,
rank = config.RANK, rank = config.RANK,
beta = None, beta = None,
threshold = 0.5, threshold = 0.5,
...@@ -98,7 +99,8 @@ def factorize(data_array, ...@@ -98,7 +99,8 @@ def factorize(data_array,
seed_H = None, seed_H = None,
log = logger, log = logger,
debug = False, debug = False,
axing = True): axing = True,
update_W = True):
log.info('Rank= %s, Threshold= %s', rank, threshold) log.info('Rank= %s, Threshold= %s', rank, threshold)
...@@ -136,8 +138,12 @@ def factorize(data_array, ...@@ -136,8 +138,12 @@ def factorize(data_array,
W_shape = (D.shape[0], rank) W_shape = (D.shape[0], rank)
H_shape = (rank, D.shape[1]) H_shape = (rank, D.shape[1])
np.random.seed(seed_W) if init_W is None:
W = np.random.uniform(low = 0.01, high = 1., size = W_shape) np.random.seed(seed_W)
W = np.random.uniform(low = 0.01, high = 1., size = W_shape)
else:
W = init_W
np.random.seed(seed_H) np.random.seed(seed_H)
H = np.random.uniform(low = 0.01, high = 1., size = H_shape) H = np.random.uniform(low = 0.01, high = 1., size = H_shape)
log.info('W, H chosen') log.info('W, H chosen')
...@@ -158,7 +164,10 @@ def factorize(data_array, ...@@ -158,7 +164,10 @@ def factorize(data_array,
if iterations > max_iter: if iterations > max_iter:
break break
W_new = update_W(W, H) if update_W:
W_new = update_W(W, H)
else:
W_new = W
H_new = update_H(W_new, H) H_new = update_H(W_new, H)
# Check for nonnegativity # Check for nonnegativity
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment