def print_graph_connections(infr, label='orig_name_label'): """ label = 'orig_name_label' """ node_to_label = infr.get_node_attrs(label) label_to_nodes = ut.group_items(node_to_label.keys(), node_to_label.values()) logger.info('CC info') for name, cc in label_to_nodes.items(): logger.info('\nname = %r' % (name,)) edges = list(nxu.edges_between(infr.graph, cc)) logger.info(infr.get_edge_df_text(edges)) logger.info('CC pair info') for (n1, cc1), (n2, cc2) in it.combinations(label_to_nodes.items(), 2): if n1 == n2: continue logger.info('\nname_pair = {}-vs-{}'.format(n1, n2)) edges = list(nxu.edges_between(infr.graph, cc1, cc2)) logger.info(infr.get_edge_df_text(edges))
def print_within_connection_info(infr, edge=None, cc=None, aid=None, nid=None): if edge is not None: aid, aid2 = edge if nid is not None: cc = infr.pos_graph._ccs[nid] if aid is not None: cc = infr.pos_graph.connected_to(aid) # subgraph = infr.graph.subgraph(cc) # list(nxu.complement_edges(subgraph)) edges = list(nxu.edges_between(infr.graph, cc)) logger.info(infr.get_edge_df_text(edges))
def pair_connection_info(infr, aid1, aid2): """ Helps debugging when ibs.nids has info that annotmatch/staging do not Examples: >>> # # FIXME failing-test (22-Jul-2020) GZ_Master1 doesn't exist >>> # xdoctest: +SKIP >>> from wbia.algo.graph.mixin_helpers import * # NOQA >>> import wbia >>> ibs = wbia.opendb(defaultdb='GZ_Master1') >>> infr = wbia.AnnotInference(ibs, 'all', autoinit=True) >>> infr.reset_feedback('staging', apply=True) >>> infr.relabel_using_reviews(rectify=False) >>> aid1, aid2 = 1349, 3087 >>> aid1, aid2 = 1535, 2549 >>> infr.pair_connection_info(aid1, aid2) >>> aid1, aid2 = 4055, 4286 >>> aid1, aid2 = 6555, 6882 >>> aid1, aid2 = 712, 803 >>> aid1, aid2 = 3883, 4220 >>> infr.pair_connection_info(aid1, aid2) """ nid1, nid2 = infr.pos_graph.node_labels(aid1, aid2) cc1 = infr.pos_graph.connected_to(aid1) cc2 = infr.pos_graph.connected_to(aid2) ibs = infr.ibs # First check directly relationships def get_aug_df(edges): df = infr.get_edge_dataframe(edges) if len(df): df.index.names = ('aid1', 'aid2') nids = np.array( [infr.pos_graph.node_labels(u, v) for u, v in list(df.index)] ) df = df.assign(nid1=nids.T[0], nid2=nids.T[1]) part = ['nid1', 'nid2', 'evidence_decision', 'tags', 'user_id'] neworder = ut.partial_order(df.columns, part) df = df.reindex(neworder, axis=1) df = df.drop(['review_id', 'timestamp'], axis=1) return df def print_df(df, lbl): df_str = df.to_string() df_str = ut.highlight_regex(df_str, ut.regex_word(str(aid1)), color='blue') df_str = ut.highlight_regex(df_str, ut.regex_word(str(aid2)), color='red') if nid1 not in {aid1, aid2}: df_str = ut.highlight_regex( df_str, ut.regex_word(str(nid1)), color='blue' ) if nid2 not in {aid1, aid2}: df_str = ut.highlight_regex(df_str, ut.regex_word(str(nid2)), color='red') logger.info('\n\n=====') logger.info(lbl) logger.info('=====') logger.info(df_str) logger.info('================') logger.info('Pair Connection Info') logger.info('================') nid1_, nid2_ = ibs.get_annot_nids([aid1, aid2]) logger.info('AIDS aid1, aid2 = %r, %r' % (aid1, aid2)) logger.info('INFR NAMES: nid1, nid2 = %r, %r' % (nid1, nid2)) if nid1 == nid2: logger.info('INFR cc = %r' % (sorted(cc1),)) else: logger.info('INFR cc1 = %r' % (sorted(cc1),)) logger.info('INFR cc2 = %r' % (sorted(cc2),)) if (nid1 == nid2) != (nid1_ == nid2_): ut.cprint('DISAGREEMENT IN GRAPH AND DB', 'red') else: ut.cprint('GRAPH AND DB AGREE', 'green') logger.info('IBS NAMES: nid1, nid2 = %r, %r' % (nid1_, nid2_)) if nid1_ == nid2_: logger.info('IBS CC: %r' % (sorted(ibs.get_name_aids(nid1_)),)) else: logger.info('IBS CC1: %r' % (sorted(ibs.get_name_aids(nid1_)),)) logger.info('IBS CC2: %r' % (sorted(ibs.get_name_aids(nid2_)),)) # Does this exist in annotmatch? in_am = ibs.get_annotmatch_rowid_from_undirected_superkey([aid1], [aid2]) logger.info('in_am = %r' % (in_am,)) # Does this exist in staging? staging_rowids = ibs.get_review_rowids_from_edges([(aid1, aid2)])[0] logger.info('staging_rowids = %r' % (staging_rowids,)) if False: # Make absolutely sure stagedf = ibs.staging.get_table_as_pandas('reviews') aid_cols = ['annot_1_rowid', 'annot_2_rowid'] has_aid1 = (stagedf[aid_cols] == aid1).any(axis=1) from_aid1 = stagedf[has_aid1] conn_aid2 = (from_aid1[aid_cols] == aid2).any(axis=1) logger.info('# connections = %r' % (conn_aid2.sum(),)) # Next check indirect relationships graph = infr.graph if cc1 != cc2: edge_df1 = get_aug_df(nxu.edges_between(graph, cc1)) edge_df2 = get_aug_df(nxu.edges_between(graph, cc2)) print_df(edge_df1, 'Inside1') print_df(edge_df2, 'Inside1') out_df1 = get_aug_df(nxu.edges_outgoing(graph, cc1)) print_df(out_df1, 'Outgoing1') out_df2 = get_aug_df(nxu.edges_outgoing(graph, cc2)) print_df(out_df2, 'Outgoing2') else: subgraph = infr.pos_graph.subgraph(cc1) logger.info('Shortest path between endpoints') logger.info(nx.shortest_path(subgraph, aid1, aid2)) edge_df3 = get_aug_df(nxu.edges_between(graph, cc1, cc2)) print_df(edge_df3, 'Between')
def reset_mtest_graph(): """ Resets the annotmatch and stating table CommandLine: python -m wbia reset_mtest_graph Example: >>> # SCRIPT >>> from wbia.init.sysres import * # NOQA >>> reset_mtest_graph() """ if True: # Delete the graph databases to and set them up for tests import wbia ibs = wbia.opendb('PZ_MTEST') annotmatch = ibs.db['annotmatch'] staging = ibs.staging['reviews'] annotmatch.clear() staging.clear() # Make this CC connected using positive edges from wbia.algo.graph.state import POSTV, NEGTV, INCMP, DIFF, NULL, SAME # NOQA from wbia.algo.graph import nx_utils as nxu import itertools as it # Add some graph properties to MTEST infr = wbia.AnnotInference(ibs, 'all', autoinit=True) # Connect the names with meta decisions infr.ensure_mst(meta_decision=SAME) # big_ccs = [cc for cc in infr.positive_components() if len(cc) > 3] small_ccs = [cc for cc in infr.positive_components() if len(cc) <= 3 and len(cc) > 1] # single_ccs = [cc for cc in infr.positive_components() if len(cc) == 1] cc = infr.pos_graph.connected_to(1) for edge in nxu.edges_between(infr.graph, cc): infr.add_feedback(edge, POSTV, user_id='user:setup1') # Make all small PCCs k-negative-redundant count = 0 for cc1, cc2 in it.combinations(small_ccs, 2): count += 1 for edge in infr.find_neg_augment_edges(cc1, cc2, k=1): if count > 10: # So some with meta infr.add_feedback(edge, meta_decision=DIFF, user_id='user:setup2') else: # So some with evidence infr.add_feedback(edge, NEGTV, user_id='user:setup3') # Make some small PCCs k-positive-redundant from wbia.algo.graph.state import POSTV, NEGTV, INCMP, UNREV, UNKWN # NOQA cand = list(infr.find_pos_redun_candidate_edges()) for edge in cand[0:2]: infr.add_feedback(edge, evidence_decision=POSTV, user_id='user:setup4') assert infr.status()['nInconsistentCCs'] == 0 # Write consistent state to both annotmatch and staging infr.write_wbia_staging_feedback() infr.write_wbia_annotmatch_feedback() # Add an 2 inconsistencies to the staging database ONLY cand = list(infr.find_pos_redun_candidate_edges()) for edge in cand[0:2]: infr.add_feedback(edge, evidence_decision=NEGTV, user_id='user:voldemort') assert infr.status()['nInconsistentCCs'] == 2 infr.write_wbia_staging_feedback() infr.reset_feedback('annotmatch', apply=True) assert infr.status()['nInconsistentCCs'] == 0