Example #1
0
def testdata_raw_internals1(**kwargs):
    from ibeis.algo.hots.smk import smk_debug
    ibs, annots_df, daids, qaids, invindex, qreq_ = smk_debug.testdata_raw_internals0(**kwargs)
    qparams = qreq_.qparams
    print('[smk_debug] testdata_raw_internals1')
    words  = invindex.words
    wordflann = invindex.wordflann
    idx2_vec  = invindex.idx2_dvec
    nAssign = 1  # 1 for database
    massign_sigma = qparams.massign_sigma
    massign_alpha = qparams.massign_alpha
    massign_equal_weights = qparams.massign_equal_weights
    # TODO: Extract args from function via inspect
    _dbargs = (wordflann, words, idx2_vec, nAssign, massign_alpha,
               massign_sigma, massign_equal_weights)
    (wx2_idxs, wx2_dmaws, idx2_wxs) = smk_index.assign_to_words_(*_dbargs)
    invindex.wx2_idxs = wx2_idxs
    invindex.wx2_dmaws = wx2_dmaws
    invindex.idx2_wxs = idx2_wxs
    return ibs, annots_df, daids, qaids, invindex, wx2_idxs, qparams
Example #2
0
def testdata_raw_internals1(**kwargs):
    from ibeis.algo.hots.smk import smk_debug
    ibs, annots_df, daids, qaids, invindex, qreq_ = smk_debug.testdata_raw_internals0(
        **kwargs)
    qparams = qreq_.qparams
    print('[smk_debug] testdata_raw_internals1')
    words = invindex.words
    wordflann = invindex.wordflann
    idx2_vec = invindex.idx2_dvec
    nAssign = 1  # 1 for database
    massign_sigma = qparams.massign_sigma
    massign_alpha = qparams.massign_alpha
    massign_equal_weights = qparams.massign_equal_weights
    # TODO: Extract args from function via inspect
    _dbargs = (wordflann, words, idx2_vec, nAssign, massign_alpha,
               massign_sigma, massign_equal_weights)
    (wx2_idxs, wx2_dmaws, idx2_wxs) = smk_index.assign_to_words_(*_dbargs)
    invindex.wx2_idxs = wx2_idxs
    invindex.wx2_dmaws = wx2_dmaws
    invindex.idx2_wxs = idx2_wxs
    return ibs, annots_df, daids, qaids, invindex, wx2_idxs, qparams
Example #3
0
def testdata_sccw_sum(**kwargs):
    from ibeis.algo.hots.smk import smk_debug
    from ibeis.algo.hots.smk import smk_index

    ibs, annots_df, qaid, invindex, qparams = smk_debug.testdata_query_repr(
        **kwargs)
    aggregate = qparams.aggregate
    smk_alpha = qparams.smk_alpha
    smk_thresh = qparams.smk_thresh

    nAssign = qparams.nAssign
    massign_sigma = qparams.massign_sigma
    massign_alpha = qparams.massign_alpha
    massign_equal_weights = qparams.massign_equal_weights
    nAssign = qparams.nAssign
    wx2_idf = invindex.wx2_idf
    words = invindex.words
    wordflann = invindex.wordflann
    #qfx2_vec  = annots_df['vecs'][qaid].values
    qfx2_vec = annots_df['vecs'][qaid]
    # Assign query to (multiple) words
    _wx2_qfxs, wx2_qmaws, 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_qmaws, wx2_flags = smk_index.compute_residuals_(
        words, _wx2_qfxs, wx2_qmaws, qfx2_vec, qfx2_aid, qfx2_qfx, aggregate)
    # Compute query sccw
    if ut.VERBOSE:
        print('[smk_index] Query TF smk_alpha=%r, smk_thresh=%r' %
              (smk_alpha, smk_thresh))
    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]
    qmaws_list = [wx2_qmaws[wx] for wx in wx_sublist]
    qflags_list = [wx2_flags[wx] for wx in wx_sublist]
    return idf_list, rvecs_list, qflags_list, qmaws_list, smk_alpha, smk_thresh
Example #4
0
def testdata_sccw_sum(**kwargs):
    from ibeis.algo.hots.smk import smk_debug
    from ibeis.algo.hots.smk import smk_index

    ibs, annots_df, qaid, invindex, qparams = smk_debug.testdata_query_repr(**kwargs)
    aggregate  = qparams.aggregate
    smk_alpha  = qparams.smk_alpha
    smk_thresh = qparams.smk_thresh

    nAssign =  qparams.nAssign
    massign_sigma = qparams.massign_sigma
    massign_alpha = qparams.massign_alpha
    massign_equal_weights = qparams.massign_equal_weights
    nAssign   = qparams.nAssign
    wx2_idf   = invindex.wx2_idf
    words     = invindex.words
    wordflann = invindex.wordflann
    #qfx2_vec  = annots_df['vecs'][qaid].values
    qfx2_vec  = annots_df['vecs'][qaid]
    # Assign query to (multiple) words
    _wx2_qfxs, wx2_qmaws, 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_qmaws, wx2_flags = smk_index.compute_residuals_(
        words, _wx2_qfxs, wx2_qmaws, qfx2_vec, qfx2_aid, qfx2_qfx, aggregate)
    # Compute query sccw
    if ut.VERBOSE:
        print('[smk_index] Query TF smk_alpha=%r, smk_thresh=%r' % (smk_alpha, smk_thresh))
    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]
    qmaws_list  = [wx2_qmaws[wx]  for wx in wx_sublist]
    qflags_list = [wx2_flags[wx]  for wx in wx_sublist]
    return idf_list, rvecs_list, qflags_list, qmaws_list, smk_alpha, smk_thresh
Example #5
0
def compute_data_internals_(invindex, qparams, memtrack=None,
                            delete_rawvecs=True):
    """
    Builds each of the inverted index internals.

        invindex (InvertedIndex): object for fast vocab lookup
        qparams (QueryParams): hyper-parameters
        memtrack (None):
        delete_rawvecs (bool):

    Returns:
        None

    Example:
        >>> from ibeis.algo.hots.smk.smk_repr import *  # NOQA
        >>> from ibeis.algo.hots.smk import smk_debug
        >>> ibs, annots_df, daids, qaids, invindex, qreq_ = smk_debug.testdata_raw_internals0()
        >>> compute_data_internals_(invindex, qreq_.qparams)

    Ignore:
        idx2_vec = idx2_dvec
        wx2_maws = _wx2_maws  # NOQA
    """
    # Get information
    #if memtrack is None:
    #    memtrack = ut.MemoryTracker('[DATA INTERNALS ENTRY]')

    #memtrack.report('[DATA INTERNALS1]')

    #
    aggregate             = qparams.aggregate
    smk_alpha             = qparams.smk_alpha
    smk_thresh            = qparams.smk_thresh
    #
    massign_alpha         = qparams.massign_alpha
    massign_sigma         = qparams.massign_sigma
    massign_equal_weights = qparams.massign_equal_weights
    #
    vocab_weighting       = qparams.vocab_weighting
    #
    nAssign = 1  # single assignment for database side

    idx2_vec  = invindex.idx2_dvec
    idx2_dfx  = invindex.idx2_dfx
    idx2_daid = invindex.idx2_daid
    daids     = invindex.daids
    wordflann = invindex.wordflann
    words     = invindex.words
    daid2_label = invindex.daid2_label
    wx_series = np.arange(len(words))
    #memtrack.track_obj(idx2_vec, 'idx2_vec')
    if not ut.QUIET:
        print('[smk_repr] compute_data_internals_')
    if ut.VERBOSE:
        print('[smk_repr] * len(daids) = %r' % (len(daids),))
        print('[smk_repr] * len(words) = %r' % (len(words),))
        print('[smk_repr] * len(idx2_vec) = %r' % (len(idx2_vec),))
        print('[smk_repr] * aggregate = %r' % (aggregate,))
        print('[smk_repr] * smk_alpha = %r' % (smk_alpha,))
        print('[smk_repr] * smk_thresh = %r' % (smk_thresh,))

    # Try to use the cache
    #cfgstr = ut.hashstr_arr(words, 'words') + qparams.feat_cfgstr
    #cachekw = dict(
        #cfgstr=cfgstr,
        #appname='smk_test'
    #)
    #invindex_cache = ut.Cacher('inverted_index', **cachekw)
    #try:
    #    raise IOError('cache is off')
    #    #cachetup = invindex_cache.load()
    #    #(idx2_wxs, wx2_idxs, wx2_idf, wx2_drvecs, wx2_aids, wx2_fxs, wx2_maws, daid2_sccw) = cachetup
    #    invindex.idx2_dvec = None
    #except IOError as ex:
    # Database word assignments (perform single assignment on database side)
    wx2_idxs, _wx2_maws, idx2_wxs = smk_index.assign_to_words_(
        wordflann, words, idx2_vec, nAssign, massign_alpha, massign_sigma,
        massign_equal_weights)
    if ut.DEBUG2:
        assert len(idx2_wxs) == len(idx2_vec)
        assert len(wx2_idxs.keys()) == len(_wx2_maws.keys())
        assert len(wx2_idxs.keys()) <= len(words)
        try:
            assert len(wx2_idxs.keys()) == len(words)
        except AssertionError as ex:
            ut.printex(ex, iswarning=True)
    # Database word inverse-document-frequency (idf weights)
    wx2_idf = smk_index.compute_word_idf_(
        wx_series, wx2_idxs, idx2_daid, daids, daid2_label, vocab_weighting,
        verbose=True)
    if ut.DEBUG2:
        assert len(wx2_idf) == len(wx2_idf.keys())
    # Compute (normalized) residual vectors and inverse mappings
    wx2_drvecs, wx2_aids, wx2_fxs, wx2_dmaws, wx2_dflags = smk_index.compute_residuals_(
        words, wx2_idxs, _wx2_maws, idx2_vec, idx2_daid, idx2_dfx,
        aggregate, verbose=True)
    if not ut.QUIET:
        print('[smk_repr] unloading idx2_vec')
    if delete_rawvecs:
        # Try to save some memory
        del _wx2_maws
        invindex.idx2_dvec = None
        del idx2_vec
    # Compute annotation normalization factor
    daid2_sccw = smk_index.compute_data_sccw_(
        idx2_daid, wx2_drvecs, wx2_dflags, wx2_aids, wx2_idf, wx2_dmaws, smk_alpha,
        smk_thresh, verbose=True)
    # Cache save
    #cachetup = (idx2_wxs, wx2_idxs, wx2_idf, wx2_drvecs, wx2_aids, wx2_fxs, wx2_dmaws, daid2_sccw)
    #invindex_cache.save(cachetup)

    # Store information
    invindex.idx2_wxs    = idx2_wxs   # stacked index -> word indexes (might not be needed)
    invindex.wx2_idxs    = wx2_idxs
    invindex.wx2_idf     = wx2_idf
    invindex.wx2_drvecs  = wx2_drvecs
    invindex.wx2_dflags  = wx2_dflags  # flag nan rvecs
    invindex.wx2_aids    = wx2_aids    # needed for asmk
    invindex.wx2_fxs     = wx2_fxs     # needed for asmk
    invindex.wx2_dmaws   = wx2_dmaws   # needed for awx2_mawssmk
    invindex.daid2_sccw  = daid2_sccw
    #memtrack.report('[DATA INTERNALS3]')

    if ut.DEBUG2:
        from ibeis.algo.hots.smk import smk_debug
        smk_debug.check_invindex_wx2(invindex)
Example #6
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
Example #7
0
def compute_data_internals_(invindex,
                            qparams,
                            memtrack=None,
                            delete_rawvecs=True):
    """
    Builds each of the inverted index internals.

        invindex (InvertedIndex): object for fast vocab lookup
        qparams (QueryParams): hyper-parameters
        memtrack (None):
        delete_rawvecs (bool):

    Returns:
        None

    Example:
        >>> from ibeis.algo.hots.smk.smk_repr import *  # NOQA
        >>> from ibeis.algo.hots.smk import smk_debug
        >>> ibs, annots_df, daids, qaids, invindex, qreq_ = smk_debug.testdata_raw_internals0()
        >>> compute_data_internals_(invindex, qreq_.qparams)

    Ignore:
        idx2_vec = idx2_dvec
        wx2_maws = _wx2_maws  # NOQA
    """
    # Get information
    #if memtrack is None:
    #    memtrack = ut.MemoryTracker('[DATA INTERNALS ENTRY]')

    #memtrack.report('[DATA INTERNALS1]')

    #
    aggregate = qparams.aggregate
    smk_alpha = qparams.smk_alpha
    smk_thresh = qparams.smk_thresh
    #
    massign_alpha = qparams.massign_alpha
    massign_sigma = qparams.massign_sigma
    massign_equal_weights = qparams.massign_equal_weights
    #
    vocab_weighting = qparams.vocab_weighting
    #
    nAssign = 1  # single assignment for database side

    idx2_vec = invindex.idx2_dvec
    idx2_dfx = invindex.idx2_dfx
    idx2_daid = invindex.idx2_daid
    daids = invindex.daids
    wordflann = invindex.wordflann
    words = invindex.words
    daid2_label = invindex.daid2_label
    wx_series = np.arange(len(words))
    #memtrack.track_obj(idx2_vec, 'idx2_vec')
    if not ut.QUIET:
        print('[smk_repr] compute_data_internals_')
    if ut.VERBOSE:
        print('[smk_repr] * len(daids) = %r' % (len(daids), ))
        print('[smk_repr] * len(words) = %r' % (len(words), ))
        print('[smk_repr] * len(idx2_vec) = %r' % (len(idx2_vec), ))
        print('[smk_repr] * aggregate = %r' % (aggregate, ))
        print('[smk_repr] * smk_alpha = %r' % (smk_alpha, ))
        print('[smk_repr] * smk_thresh = %r' % (smk_thresh, ))

    # Try to use the cache
    #cfgstr = ut.hashstr_arr(words, 'words') + qparams.feat_cfgstr
    #cachekw = dict(
    #cfgstr=cfgstr,
    #appname='smk_test'
    #)
    #invindex_cache = ut.Cacher('inverted_index', **cachekw)
    #try:
    #    raise IOError('cache is off')
    #    #cachetup = invindex_cache.load()
    #    #(idx2_wxs, wx2_idxs, wx2_idf, wx2_drvecs, wx2_aids, wx2_fxs, wx2_maws, daid2_sccw) = cachetup
    #    invindex.idx2_dvec = None
    #except IOError as ex:
    # Database word assignments (perform single assignment on database side)
    wx2_idxs, _wx2_maws, idx2_wxs = smk_index.assign_to_words_(
        wordflann, words, idx2_vec, nAssign, massign_alpha, massign_sigma,
        massign_equal_weights)
    if ut.DEBUG2:
        assert len(idx2_wxs) == len(idx2_vec)
        assert len(wx2_idxs.keys()) == len(_wx2_maws.keys())
        assert len(wx2_idxs.keys()) <= len(words)
        try:
            assert len(wx2_idxs.keys()) == len(words)
        except AssertionError as ex:
            ut.printex(ex, iswarning=True)
    # Database word inverse-document-frequency (idf weights)
    wx2_idf = smk_index.compute_word_idf_(wx_series,
                                          wx2_idxs,
                                          idx2_daid,
                                          daids,
                                          daid2_label,
                                          vocab_weighting,
                                          verbose=True)
    if ut.DEBUG2:
        assert len(wx2_idf) == len(wx2_idf.keys())
    # Compute (normalized) residual vectors and inverse mappings
    wx2_drvecs, wx2_aids, wx2_fxs, wx2_dmaws, wx2_dflags = smk_index.compute_residuals_(
        words,
        wx2_idxs,
        _wx2_maws,
        idx2_vec,
        idx2_daid,
        idx2_dfx,
        aggregate,
        verbose=True)
    if not ut.QUIET:
        print('[smk_repr] unloading idx2_vec')
    if delete_rawvecs:
        # Try to save some memory
        del _wx2_maws
        invindex.idx2_dvec = None
        del idx2_vec
    # Compute annotation normalization factor
    daid2_sccw = smk_index.compute_data_sccw_(idx2_daid,
                                              wx2_drvecs,
                                              wx2_dflags,
                                              wx2_aids,
                                              wx2_idf,
                                              wx2_dmaws,
                                              smk_alpha,
                                              smk_thresh,
                                              verbose=True)
    # Cache save
    #cachetup = (idx2_wxs, wx2_idxs, wx2_idf, wx2_drvecs, wx2_aids, wx2_fxs, wx2_dmaws, daid2_sccw)
    #invindex_cache.save(cachetup)

    # Store information
    invindex.idx2_wxs = idx2_wxs  # stacked index -> word indexes (might not be needed)
    invindex.wx2_idxs = wx2_idxs
    invindex.wx2_idf = wx2_idf
    invindex.wx2_drvecs = wx2_drvecs
    invindex.wx2_dflags = wx2_dflags  # flag nan rvecs
    invindex.wx2_aids = wx2_aids  # needed for asmk
    invindex.wx2_fxs = wx2_fxs  # needed for asmk
    invindex.wx2_dmaws = wx2_dmaws  # needed for awx2_mawssmk
    invindex.daid2_sccw = daid2_sccw
    #memtrack.report('[DATA INTERNALS3]')

    if ut.DEBUG2:
        from ibeis.algo.hots.smk import smk_debug
        smk_debug.check_invindex_wx2(invindex)
Example #8
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