def test_bpmf(self): Y = scipy.sparse.rand(10, 20, 0.2) Y, Ytest = macau.make_train_test(Y, 0.5) results = macau.bpmf(Y, Ytest = Ytest, num_latent = 4, verbose = False, burnin = 50, nsamples = 50, univariate = False) self.assertEqual(Ytest.nnz, results.prediction.shape[0]) self.assertTrue( (results.prediction.columns[0:2] == ["row", "col"]).all() )
def test_macau_univariate(self): Y = scipy.sparse.rand(10, 20, 0.2) Y, Ytest = macau.make_train_test(Y, 0.5) side1 = scipy.sparse.coo_matrix( np.random.rand(10, 2) ) side2 = scipy.sparse.coo_matrix( np.random.rand(20, 3) ) results = macau.bpmf(Y, Ytest = Ytest, side = [side1, side2], num_latent = 4, verbose = False, burnin = 50, nsamples = 50, univariate = True) self.assertEqual(Ytest.nnz, results.prediction.shape[0])
def test_make_train_test(self): X = scipy.sparse.rand(15, 10, 0.2) Xtr, Xte = macau.make_train_test(X, 0.5) self.assertEqual(X.nnz, Xtr.nnz + Xte.nnz) diff = np.linalg.norm( (X - Xtr - Xte).todense() ) self.assertEqual(diff, 0.0)
#print(Y) grid = np.indices((drug_num, assay_num)) rows_idx = grid[0].flatten() col_idx = grid[1].flatten() import random idx_sel = random.sample(range(len(rows_idx)), (nums_0)) row_sel = rows_idx[idx_sel] col_sel = col_idx[idx_sel] # Set some samples to 0 Y[row_sel[0:nums_0], col_sel[0:nums_0]] = 0 #Training D = scipy.sparse.coo_matrix(Y) #Test D, Dtest = macau.make_train_test(D, test_per) #Censor below censoring threshold: a = D.data cens = [1] * sum(D.data < cens_threshold) C_mat = scipy.sparse.coo_matrix( (cens, (D.row[D.data < cens_threshold], D.col[D.data < cens_threshold])), shape=D.shape) D.data[a < cens_threshold] = cens_threshold cens_numbers[idx_i, loop] = len(C_mat.data) / len(D.data) result = macau.macau(Y=D, Ytest=Dtest, side=[None, None], num_latent=latents,