def quasi_clique_expansions2(quasi_cliques, cliques, incomp): array_cliques = [np.array(c) for c in cliques.keys()] c_comps = np.array([[valid_combo(array_cliques[i], array_cliques[j], incomp) if j > i else 0 for j in range(len(array_cliques))] for i in range(len(array_cliques))]) #print('ccomps', c_comps.shape) c_comp_graph = graph_from_matrix(c_comps)[0] #print('cgraph', c_comp_graph) max_expansions = dict() for q,r in quasi_cliques.items(): q = np.array(q) qcomps = np.array([valid_combo(q, array_cliques[i], incomp) for i in range(len(array_cliques))]) #print('qcomps', len(qcomps)) if np.any(qcomps): view = GraphView(c_comp_graph, vfilt=qcomps > 0) #get max cliques of compatible patterns combos = list(max_cliques(view)) #add compatible isolated vertices missing in cliques vs = view.get_vertices() isolated = vs[view.get_total_degrees(vs) == 0] combos += [[i] for i in isolated] #build combos and merge into quasi-cliques combos = [[array_cliques[i] for i in c] for c in combos] qcliques = [tuple(list(snp.kway_merge(*([q]+co), duplicates=snp.DROP))) for co in combos] qratings = [r+sum([cliques[tuple(c)] for c in co]) for co in combos] max_expansions.update(zip(qcliques, qratings)) #print('upd') return max_expansions#[np.array(m) for m in max_expansions] if len(max_expansions) > 1 else []
def test_simple_1_not_sorted(self): """ Check that the same array is returned, if only one sorted array is passed to the merger and assume_sorted is False. """ a = np.array([3, 1, 7], dtype=self.get_dtype()) m = snp.kway_merge(a, assume_sorted=False) self.assertEqual(list(m), [1, 3, 7]) self.assertEqual(m.dtype, self.get_dtype())
def test_simple_2_not_sorted(self): """ Check that the correctly merged array is returned when called with two sorted arrays and assume_sorted is False. """ a = np.array([1, 7, 3], dtype=self.get_dtype()) b = np.array([9, 2, 5], dtype=self.get_dtype()) m = snp.kway_merge(a, b, assume_sorted=False) self.assertEqual(list(m), [1, 2, 3, 5, 7, 9]) self.assertEqual(m.dtype, self.get_dtype())
def test_simple_2_sorted(self): """ Check that the correctly merged array is returned when called with two sorted arrays. """ a = np.array([1, 3, 7], dtype=self.get_dtype()) b = np.array([2, 5, 9], dtype=self.get_dtype()) m = snp.kway_merge(a, b) self.assertEqual(list(m), [1, 2, 3, 5, 7, 9]) self.assertEqual(m.dtype, self.get_dtype())
def test_simple_3_callable_1_not_sorted(self): """ Check that the correctly merged array is returned when called with one callable and two arrays and assume_sorted is False. """ a = lambda: np.array([3, 1, 7], dtype=self.get_dtype()) b = np.array([2, 5, 9], dtype=self.get_dtype()) c = np.array([8, 4], dtype=self.get_dtype()) m = snp.kway_merge(a, b, c, assume_sorted=False) self.assertEqual(list(m), [1, 2, 3, 4, 5, 7, 8, 9]) self.assertEqual(m.dtype, self.get_dtype()) m = snp.kway_merge(b, a, c, assume_sorted=False) self.assertEqual(list(m), [1, 2, 3, 4, 5, 7, 8, 9]) self.assertEqual(m.dtype, self.get_dtype()) m = snp.kway_merge(c, b, a, assume_sorted=False) self.assertEqual(list(m), [1, 2, 3, 4, 5, 7, 8, 9]) self.assertEqual(m.dtype, self.get_dtype())
def test_simple_1_callable_1_not_sorted(self): """ Check that the generated array is returned if a single generated is given and assume_sorted is False. """ a = lambda: np.array([3, 7, 5], dtype=self.get_dtype()) m = snp.kway_merge(a, assume_sorted=False) self.assertEqual(list(m), [3, 5, 7]) self.assertEqual(m.dtype, self.get_dtype())
def test_simple_3_callable_1(self): """ Check that the correctly merged array is returned when called with one callable and two arrays. """ a = lambda: np.array([1, 3, 7], dtype=self.get_dtype()) b = np.array([2, 5, 9], dtype=self.get_dtype()) c = np.array([4, 8], dtype=self.get_dtype()) m = snp.kway_merge(a, b, c) self.assertEqual(list(m), [1, 2, 3, 4, 5, 7, 8, 9]) self.assertEqual(m.dtype, self.get_dtype()) m = snp.kway_merge(b, a, c) self.assertEqual(list(m), [1, 2, 3, 4, 5, 7, 8, 9]) self.assertEqual(m.dtype, self.get_dtype()) m = snp.kway_merge(c, b, a) self.assertEqual(list(m), [1, 2, 3, 4, 5, 7, 8, 9]) self.assertEqual(m.dtype, self.get_dtype())
def test_simple_1_callable_1(self): """ Check that the generated array is returned if a single generated is given. """ a = lambda: np.array([3, 5, 7], dtype=self.get_dtype()) m = snp.kway_merge(a) self.assertEqual(list(m), [3, 5, 7]) self.assertEqual(m.dtype, self.get_dtype())
def test_simple_3_callable_3_not_sorted(self): """ Check that the correctly merged array is returned when called with three callable objects and assume_sorted is False. """ a = lambda: np.array([7, 1, 3], dtype=self.get_dtype()) b = lambda: np.array([2, 9, 5], dtype=self.get_dtype()) c = lambda: np.array([8, 4], dtype=self.get_dtype()) m = snp.kway_merge(a, b, c, assume_sorted=False) self.assertEqual(list(m), [1, 2, 3, 4, 5, 7, 8, 9]) self.assertEqual(m.dtype, self.get_dtype())
def test_simple_4_not_sorted(self): """ Check that the correctly merged array is returned when called with four sorted arrays and assume_sorted is False. """ a = np.array([3, 1, 7], dtype=self.get_dtype()) b = np.array([9, 2, 5], dtype=self.get_dtype()) c = np.array([4, 8], dtype=self.get_dtype()) d = np.array([10, 6, 3], dtype=self.get_dtype()) m = snp.kway_merge(a, b, c, d, assume_sorted=False) self.assertEqual(list(m), [1, 2, 3, 3, 4, 5, 6, 7, 8, 9, 10]) self.assertEqual(m.dtype, self.get_dtype())
def test_simple_4_sorted(self): """ Check that the correctly merged array is returned when called with four sorted arrays. """ a = np.array([1, 3, 7], dtype=self.get_dtype()) b = np.array([2, 5, 9], dtype=self.get_dtype()) c = np.array([4, 8], dtype=self.get_dtype()) d = np.array([3, 6, 10], dtype=self.get_dtype()) m = snp.kway_merge(a, b, c, d) self.assertEqual(list(m), [1, 2, 3, 3, 4, 5, 6, 7, 8, 9, 10]) self.assertEqual(m.dtype, self.get_dtype())