def edges(self, nbunch=None, data=False, default=None): # Force edges to always be returned in upper triangular form edges = super(GraphHelperMixin, self).edges(nbunch, data, default) if data: return (e_(u, v) + (d, ) for u, v, d in edges) else: return (e_(u, v) for u, v in edges)
def find_pos_redun_candidate_edges(infr, k=None, verbose=False): r""" Searches for augmenting edges that would make PCCs k-positive redundant Doctest: >>> from ibeis.algo.graph.mixin_matching import * # NOQA >>> from ibeis.algo.graph import demo >>> infr = demo.demodata_infr(ccs=[(1, 2, 3, 4, 5), (7, 8, 9, 10)]) >>> infr.add_feedback((2, 5), 'match') >>> infr.add_feedback((1, 5), 'notcomp') >>> infr.params['redun.pos'] = 2 >>> candidate_edges = list(infr.find_pos_redun_candidate_edges()) >>> result = ('candidate_edges = ' + ut.repr2(candidate_edges)) >>> print(result) candidate_edges = [(1, 3), (7, 10)] """ # Add random edges between exisiting non-redundant PCCs if k is None: k = infr.params['redun.pos'] # infr.find_non_pos_redundant_pccs(k=k, relax=True) pcc_gen = list(infr.positive_components()) prog = ut.ProgIter(pcc_gen, enabled=verbose, freq=1, adjust=False) for pcc in prog: if not infr.is_pos_redundant( pcc, k=k, relax=True, assume_connected=True): for edge in infr.find_pos_augment_edges(pcc, k=k): yield nxu.e_(*edge)
def _get_cm_edge_data(infr, edges, cm_list=None): symmetric = True if cm_list is None: cm_list = infr.cm_list # Find scores for the edges that exist in the graph edge_to_data = ut.ddict(dict) aid_to_cm = {cm.qaid: cm for cm in cm_list} for u, v in edges: if symmetric: u, v = e_(u, v) cm1 = aid_to_cm.get(u, None) cm2 = aid_to_cm.get(v, None) scores = [] ranks = [] for cm in ut.filter_Nones([cm1, cm2]): for aid in [u, v]: idx = cm.daid2_idx.get(aid, None) if idx is None: continue score = cm.annot_score_list[idx] rank = cm.get_annot_ranks([aid])[0] scores.append(score) ranks.append(rank) if len(scores) == 0: score = None rank = None else: # Choose whichever one gave the best score idx = vt.safe_argmax(scores, nans=False) score = scores[idx] rank = ranks[idx] edge_to_data[(u, v)]['score'] = score edge_to_data[(u, v)]['rank'] = rank return edge_to_data
def exec_vsone_subset(infr, edges, prog_hook=None): r""" Args: prog_hook (None): (default = None) CommandLine: python -m ibeis.algo.graph.core exec_vsone_subset Example: >>> # ENABLE_DOCTEST >>> from ibeis.algo.graph.core import * # NOQA >>> infr = testdata_infr('testdb1') >>> infr.ensure_full() >>> edges = [(1, 2), (2, 3)] >>> result = infr.exec_vsone_subset(edges) >>> print(result) """ match_list = infr._make_matches_from(edges, prog_hook) # TODO: is this code necessary anymore? vsone_matches = { e_(u, v): match for (u, v), match in zip(edges, match_list) } infr.vsone_matches.update(vsone_matches) edge_to_score = { e: match.fs.sum() for e, match in vsone_matches.items() } infr.graph.add_edges_from(edge_to_score.keys()) infr.set_edge_attrs('score', edge_to_score) return match_list
def find_neg_redun_candidate_edges(infr, k=None): """ Get pairs of PCCs that are not complete. Finds edges that might complete them. Example: >>> # DISABLE_DOCTEST >>> from ibeis.algo.graph.mixin_matching import * # NOQA >>> from ibeis.algo.graph import demo >>> infr = demo.demodata_infr(ccs=[(1,), (2,), (3,)], ignore_pair=True) >>> edges = list(infr.find_neg_redun_candidate_edges()) >>> assert len(edges) == 3, 'all should be needed here' >>> infr.add_feedback_from(edges, evidence_decision=NEGTV) >>> assert len(list(infr.find_neg_redun_candidate_edges())) == 0 Example: >>> # DISABLE_DOCTEST >>> from ibeis.algo.graph import demo >>> infr = demo.demodata_infr(pcc_sizes=[3] * 20, ignore_pair=True) >>> ccs = list(infr.positive_components()) >>> gen = infr.find_neg_redun_candidate_edges(k=2) >>> for edge in gen: >>> # What happens when we make ccs positive >>> print(infr.node_labels(edge)) >>> infr.add_feedback(edge, evidence_decision=POSTV) >>> import ubelt as ub >>> infr = demo.demodata_infr(pcc_sizes=[1] * 30, ignore_pair=True) >>> ccs = list(infr.positive_components()) >>> gen = infr.find_neg_redun_candidate_edges(k=3) >>> for chunk in ub.chunks(gen, 2): >>> for edge in chunk: >>> # What happens when we make ccs positive >>> print(infr.node_labels(edge)) >>> infr.add_feedback(edge, evidence_decision=POSTV) list(gen) """ if k is None: k = infr.params['redun.neg'] # Loop through all pairs for cc1, cc2 in infr.find_non_neg_redun_pccs(k=k): if len(cc1.intersection(cc2)) > 0: # If there is modification of the underlying graph while we # iterate, then two ccs may not be disjoint. Skip these cases. continue for u, v in infr.find_neg_augment_edges(cc1, cc2, k): edge = e_(u, v) infr.assert_edge(edge) yield edge
def edges(infr, data=False): if data: return ((e_(u, v), d) for u, v, d in infr.graph.edges(data=True)) else: return (e_(u, v) for u, v in infr.graph.edges())
def e_(u, v): return e_(u, v)