def test_random_means_cluster_init(self): """ Test state estimation with random means and weights. 20 cells, 200 genes, 2 clusters """ sim_m, sim_w = simulation.generate_poisson_states(2, 20, 200) sim_data = simulation.generate_state_data(sim_m, sim_w) sim_data = sparse.csc_matrix(sim_data) m, w, ll = state_estimation.poisson_estimate_state( sim_data, 2, max_iters=10, disp=False, initialization='cluster') obj = sparse_objective(sim_data.data, sim_data.indices, sim_data.indptr, 20, 200, m, w) self.assertEqual(ll, obj) dense_obj = objective(sim_data.toarray(), m, w) self.assertTrue(np.abs(obj - dense_obj) < 1e-6) means_good = False weights_good = False for p in itertools.permutations([0, 1]): means_good = means_good or (np.mean(np.abs(sim_m - m[:, p])) < 20.0) weights_good = weights_good or (np.mean(np.abs(sim_w - w[p, :])) < 0.2) self.assertTrue(means_good) self.assertTrue(weights_good)
def _call_sparse_obj(X, M, W): return sparse_objective(X.data, X.indices, X.indptr, X.shape[1], X.shape[0], M, W)