def NMijF_jp(tt_matrix, tw_matrix, k_topic, alpha): print "Entering NMijF_jp process..." tt_shape = tt_matrix.shape tw_shape = tw_matrix.shape W = np.random.rand(tt_shape[0], k_topic) Y = np.random.rand(k_topic, tt_shape[1]) H = np.random.rand(k_topic, tw_shape[1]) observation = 0 for i in range(30): print "Fatoring..." + str(float(i) / 30.0) + "%" W = NMF.update_a(W, Y, tt_matrix) Y = NMF.update_x(W, Y, tt_matrix) H = NMF.update_x(W, H, tw_matrix) di = NMF.divergence_function(tt_matrix, np.dot(W, Y)) dj = NMF.divergence_function(tw_matrix, np.dot(W, H)) if (object_function(di, dj, alpha) - observation) < 0.001: break observation = object_function(di, dj, alpha) # print "tweet - topic matrix \n" + str(W) # print "topic - tweet matrix \n" + str(Y) # print "topic - word matrix \n" + str(H) print "Done!" return [W, H]