Exemplo n.º 1
0
def match_kernel_L2(qindex, invindex, qparams, withinfo=True):
    """
    Example:
        >>> from ibeis.algo.hots.smk.smk_core import *  # NOQA
        >>> from ibeis.algo.hots.smk import smk_debug
        >>> ibs, invindex, qindex, qparams = smk_debug.testdata_match_kernel_L2()
        >>> withinfo = True  # takes an 11s vs 2s
        >>> smk_debug.rrr()
        >>> smk_debug.invindex_dbgstr(invindex)
        >>> daid2_totalscore, daid2_wx2_scoremat = match_kernel_L2(qindex, invindex, qparams, withinfo)
    """
    if DEBUG_SMK:
        from ibeis.algo.hots.smk import smk_debug
        assert smk_debug.check_wx2_rvecs2(invindex), 'bad invindex'
        smk_debug.dbstr_qindex()  # UNSAFE FUNC STACK INSPECTOR
    # Unpack qindex
    # Call match kernel logic
    retL1 = match_kernel_L1(qindex, invindex, qparams)
    # Unpack
    (daid2_totalscore, common_wxs, scores_list, daids_list) = retL1
    if withinfo:
        # Build up cmtup_old if requested TODO: Only build for a shortlist
        daid2_chipmatch = build_daid2_chipmatch3(qindex, invindex, common_wxs,
                                                 scores_list, daids_list)
    else:
        daid2_chipmatch = None

    return daid2_totalscore, daid2_chipmatch
Exemplo n.º 2
0
def match_kernel_L2(qindex, invindex, qparams, withinfo=True):
    """
    Example:
        >>> from ibeis.algo.hots.smk.smk_core import *  # NOQA
        >>> from ibeis.algo.hots.smk import smk_debug
        >>> ibs, invindex, qindex, qparams = smk_debug.testdata_match_kernel_L2()
        >>> withinfo = True  # takes an 11s vs 2s
        >>> smk_debug.rrr()
        >>> smk_debug.invindex_dbgstr(invindex)
        >>> daid2_totalscore, daid2_wx2_scoremat = match_kernel_L2(qindex, invindex, qparams, withinfo)
    """
    if DEBUG_SMK:
        from ibeis.algo.hots.smk import smk_debug
        assert smk_debug.check_wx2_rvecs2(invindex), 'bad invindex'
        smk_debug.dbstr_qindex()  # UNSAFE FUNC STACK INSPECTOR
    # Unpack qindex
    # Call match kernel logic
    retL1 =  match_kernel_L1(qindex, invindex, qparams)
    # Unpack
    (daid2_totalscore, common_wxs, scores_list, daids_list)  = retL1
    if withinfo:
        # Build up cmtup_old if requested TODO: Only build for a shortlist
        daid2_chipmatch = build_daid2_chipmatch3(qindex, invindex, common_wxs, scores_list, daids_list)
    else:
        daid2_chipmatch = None

    return daid2_totalscore, daid2_chipmatch
Exemplo n.º 3
0
def new_qindex(annots_df, qaid, invindex, qparams):
    r"""
    Gets query read for computations

    Args:
        annots_df (DataFrameProxy): pandas-like data interface
        qaid (int): query annotation id
        invindex (InvertedIndex): inverted index object
        qparams (QueryParams): query parameters object

    Returns:
        qindex: named tuple containing query information

    CommandLine:
        python -m ibeis.algo.hots.smk.smk_repr --test-new_qindex

    Example:
        >>> # DISABLE_DOCTEST
        >>> from ibeis.algo.hots.smk.smk_repr import *  # NOQA
        >>> from ibeis.algo.hots.smk import smk_debug
        >>> ibs, annots_df, qaid, invindex, qparams = smk_debug.testdata_query_repr(db='PZ_Mothers', nWords=128000)
        >>> qindex = new_qindex(annots_df, qaid, invindex, qparams)
        >>> assert smk_debug.check_wx2_rvecs(qindex.wx2_qrvecs), 'has nan'
        >>> smk_debug.invindex_dbgstr(invindex)

    Ignore::
        idx2_vec = qfx2_vec
        idx2_aid = qfx2_aid
        idx2_fx  = qfx2_qfx
        wx2_idxs = _wx2_qfxs
        wx2_maws = _wx2_maws
        from ibeis.algo.hots.smk import smk_repr
        import utool as ut
        ut.rrrr()
        print(ut.make_default_docstr(smk_repr.new_qindex))
    """
    # TODO: Precompute and lookup residuals and assignments
    if not ut.QUIET:
        print('[smk_repr] Query Repr qaid=%r' % (qaid,))
    #
    nAssign               = qparams.nAssign
    massign_alpha         = qparams.massign_alpha
    massign_sigma         = qparams.massign_sigma
    massign_equal_weights = qparams.massign_equal_weights
    #
    aggregate             = qparams.aggregate
    smk_alpha             = qparams.smk_alpha
    smk_thresh            = qparams.smk_thresh
    #
    wx2_idf   = invindex.wx2_idf
    words     = invindex.words
    wordflann = invindex.wordflann
    #qfx2_vec  = annots_df['vecs'][qaid]
    # TODO: remove all mention of annot_df and ensure that qparams is passed corectly to config2_
    qfx2_vec  = annots_df.ibs.get_annot_vecs(qaid, config2_=qparams)
    #-------------------
    # Assign query to (multiple) words
    #-------------------
    _wx2_qfxs, _wx2_maws, qfx2_wxs = smk_index.assign_to_words_(
        wordflann, words, qfx2_vec, nAssign, massign_alpha,
        massign_sigma, massign_equal_weights)
    # Hack to make implementing asmk easier, very redundant
    qfx2_aid = np.array([qaid] * len(qfx2_wxs), dtype=hstypes.INTEGER_TYPE)
    qfx2_qfx = np.arange(len(qfx2_vec))
    #-------------------
    # Compute query residuals
    #-------------------
    wx2_qrvecs, wx2_qaids, wx2_qfxs, wx2_maws, wx2_qflags = smk_index.compute_residuals_(
        words, _wx2_qfxs, _wx2_maws, qfx2_vec, qfx2_aid, qfx2_qfx, aggregate)
    # each value in wx2_ dicts is a list with len equal to the number of rvecs
    if ut.VERBOSE:
        print('[smk_repr] Query SCCW smk_alpha=%r, smk_thresh=%r' % (smk_alpha, smk_thresh))
    #-------------------
    # Compute query sccw
    #-------------------
    wx_sublist  = np.array(wx2_qrvecs.keys(), dtype=hstypes.INDEX_TYPE)
    idf_list    = [wx2_idf[wx]    for wx in wx_sublist]
    rvecs_list  = [wx2_qrvecs[wx] for wx in wx_sublist]
    maws_list   = [wx2_maws[wx]   for wx in wx_sublist]
    flags_list  = [wx2_qflags[wx] for wx in wx_sublist]
    query_sccw = smk_scoring.sccw_summation(rvecs_list, flags_list, idf_list, maws_list, smk_alpha, smk_thresh)
    try:
        assert query_sccw > 0, 'query_sccw=%r is not positive!' % (query_sccw,)
    except Exception as ex:
        ut.printex(ex)
        raise
    #-------------------
    # Build query representationm class/tuple
    #-------------------
    if DEBUG_SMK:
        from ibeis.algo.hots.smk import smk_debug
        qfx2_vec = annots_df['vecs'][qaid]
        assert smk_debug.check_wx2_rvecs2(
            invindex, wx2_qrvecs, wx2_qfxs, qfx2_vec), 'bad qindex'

    qindex = QueryIndex(wx2_qrvecs, wx2_qflags, wx2_maws, wx2_qaids, wx2_qfxs, query_sccw)
    return qindex
Exemplo n.º 4
0
def new_qindex(annots_df, qaid, invindex, qparams):
    r"""
    Gets query read for computations

    Args:
        annots_df (DataFrameProxy): pandas-like data interface
        qaid (int): query annotation id
        invindex (InvertedIndex): inverted index object
        qparams (QueryParams): query parameters object

    Returns:
        qindex: named tuple containing query information

    CommandLine:
        python -m ibeis.algo.hots.smk.smk_repr --test-new_qindex

    Example:
        >>> # DISABLE_DOCTEST
        >>> from ibeis.algo.hots.smk.smk_repr import *  # NOQA
        >>> from ibeis.algo.hots.smk import smk_debug
        >>> ibs, annots_df, qaid, invindex, qparams = smk_debug.testdata_query_repr(db='PZ_Mothers', nWords=128000)
        >>> qindex = new_qindex(annots_df, qaid, invindex, qparams)
        >>> assert smk_debug.check_wx2_rvecs(qindex.wx2_qrvecs), 'has nan'
        >>> smk_debug.invindex_dbgstr(invindex)

    Ignore::
        idx2_vec = qfx2_vec
        idx2_aid = qfx2_aid
        idx2_fx  = qfx2_qfx
        wx2_idxs = _wx2_qfxs
        wx2_maws = _wx2_maws
        from ibeis.algo.hots.smk import smk_repr
        import utool as ut
        ut.rrrr()
        print(ut.make_default_docstr(smk_repr.new_qindex))
    """
    # TODO: Precompute and lookup residuals and assignments
    if not ut.QUIET:
        print('[smk_repr] Query Repr qaid=%r' % (qaid, ))
    #
    nAssign = qparams.nAssign
    massign_alpha = qparams.massign_alpha
    massign_sigma = qparams.massign_sigma
    massign_equal_weights = qparams.massign_equal_weights
    #
    aggregate = qparams.aggregate
    smk_alpha = qparams.smk_alpha
    smk_thresh = qparams.smk_thresh
    #
    wx2_idf = invindex.wx2_idf
    words = invindex.words
    wordflann = invindex.wordflann
    #qfx2_vec  = annots_df['vecs'][qaid]
    # TODO: remove all mention of annot_df and ensure that qparams is passed corectly to config2_
    qfx2_vec = annots_df.ibs.get_annot_vecs(qaid, config2_=qparams)
    #-------------------
    # Assign query to (multiple) words
    #-------------------
    _wx2_qfxs, _wx2_maws, qfx2_wxs = smk_index.assign_to_words_(
        wordflann, words, qfx2_vec, nAssign, massign_alpha, massign_sigma,
        massign_equal_weights)
    # Hack to make implementing asmk easier, very redundant
    qfx2_aid = np.array([qaid] * len(qfx2_wxs), dtype=hstypes.INTEGER_TYPE)
    qfx2_qfx = np.arange(len(qfx2_vec))
    #-------------------
    # Compute query residuals
    #-------------------
    wx2_qrvecs, wx2_qaids, wx2_qfxs, wx2_maws, wx2_qflags = smk_index.compute_residuals_(
        words, _wx2_qfxs, _wx2_maws, qfx2_vec, qfx2_aid, qfx2_qfx, aggregate)
    # each value in wx2_ dicts is a list with len equal to the number of rvecs
    if ut.VERBOSE:
        print('[smk_repr] Query SCCW smk_alpha=%r, smk_thresh=%r' %
              (smk_alpha, smk_thresh))
    #-------------------
    # Compute query sccw
    #-------------------
    wx_sublist = np.array(wx2_qrvecs.keys(), dtype=hstypes.INDEX_TYPE)
    idf_list = [wx2_idf[wx] for wx in wx_sublist]
    rvecs_list = [wx2_qrvecs[wx] for wx in wx_sublist]
    maws_list = [wx2_maws[wx] for wx in wx_sublist]
    flags_list = [wx2_qflags[wx] for wx in wx_sublist]
    query_sccw = smk_scoring.sccw_summation(rvecs_list, flags_list, idf_list,
                                            maws_list, smk_alpha, smk_thresh)
    try:
        assert query_sccw > 0, 'query_sccw=%r is not positive!' % (
            query_sccw, )
    except Exception as ex:
        ut.printex(ex)
        raise
    #-------------------
    # Build query representationm class/tuple
    #-------------------
    if DEBUG_SMK:
        from ibeis.algo.hots.smk import smk_debug
        qfx2_vec = annots_df['vecs'][qaid]
        assert smk_debug.check_wx2_rvecs2(invindex, wx2_qrvecs, wx2_qfxs,
                                          qfx2_vec), 'bad qindex'

    qindex = QueryIndex(wx2_qrvecs, wx2_qflags, wx2_maws, wx2_qaids, wx2_qfxs,
                        query_sccw)
    return qindex