matchbin_selectors.hpp

Selector structs that can be plugged into MatchBin.

struct CacheStateBase
#include <matchbin_selectors.hpp>

Subclassed by RankedCacheState, RouletteCacheState, SieveCacheState

Public Functions

CacheStateBase() = default
inline virtual ~CacheStateBase()
virtual optional<vector<size_t>> operator()(size_t n) = 0
struct RouletteCacheState : public CacheStateBase
#include <matchbin_selectors.hpp>

Public Functions

RouletteCacheState() = default
inline RouletteCacheState(IndexMap &im, vector<size_t> ids, Random &r, const size_t default_n_)
inline virtual optional<vector<size_t>> operator()(size_t n) override

Public Members

IndexMap indexMap
vector<size_t> uids
Random *rand
size_t default_n
struct SieveCacheState : public CacheStateBase
#include <matchbin_selectors.hpp>

Public Functions

SieveCacheState() = default
inline SieveCacheState(vector<size_t> uids_, const vector<double> &probs_, Random &r, const size_t default_n_)
inline virtual optional<vector<size_t>> operator()(size_t n) override

Public Members

vector<size_t> uids
vector<double> probs
Random *rand
size_t default_n
struct RankedCacheState : public CacheStateBase
#include <matchbin_selectors.hpp>

Public Functions

RankedCacheState() = default
inline RankedCacheState(vector<size_t> uids_, size_t n, size_t default_n_)
inline virtual optional<vector<size_t>> operator()(size_t n) override

Public Members

vector<size_t> uids
size_t requestSize
size_t default_n
template<typename CacheType>
struct SelectorBase
#include <matchbin_selectors.hpp>

Abstract base class for selectors.

Public Functions

inline virtual ~SelectorBase()
virtual CacheType operator()(vector<std::pair<size_t, double>> scores, size_t n) = 0
virtual std::string name() const = 0
template<typename ThreshRatio = std::ratio<-1, 1>, size_t DefaultN = 1>
struct RankedSelector : public SelectorBase<RankedCacheState>
#include <matchbin_selectors.hpp>

Returns matches within the threshold ThreshRatio sorted by match quality.

Public Types

using cache_state_t = RankedCacheState

Public Functions

RankedSelector() = default
inline RankedSelector(Random&)
inline std::string name() const override
inline virtual RankedCacheState operator()(vector<std::pair<size_t, double>> scores, size_t n) override
template<typename ThreshRatio = std::ratio<-1, 1>, typename SkewRatio = std::ratio<1, 10>, typename MaxBaselineRatio = std::ratio<1, 1>, size_t DefaultN = 1>
struct RouletteSelector : public SelectorBase<RouletteCacheState>
#include <matchbin_selectors.hpp>

Selector chooses probabilistically based on match quality with replacement. ThreshRatio: what is the raw maximum score to even be considered to match SkewRatio: how much more heavily should the best matches be weighted in terms of match probability; must be greater than 0 (close to zero: very heavily, large: mostly even weighting) MaxBaselineRatio: maximum score that all scores will be normalized to baseline = min(min_score, MaxBaselineRatio) normalized_score = score - baseline … overall, p_match ~ 1 / (skew + score - baseline)

Public Types

using cache_state_t = RouletteCacheState

Public Functions

inline RouletteSelector(Random &rand_)
inline std::string name() const override
inline virtual RouletteCacheState operator()(vector<std::pair<size_t, double>> scores, size_t n) override

Public Members

Random &rand
template<typename ThreshRatio = std::ratio<13, 10>, typename BRatio = std::ratio<1, 100>, typename CRatio = std::ratio<4, 1>, typename ZRatio = std::ratio<4, 1>, typename MaxBaselineRatio = std::ratio<5, 4>, size_t DefaultN = 1>
struct ExpRouletteSelector : public SelectorBase<RouletteCacheState>
#include <matchbin_selectors.hpp>

Selector chooses probabilistically based on match quality with replacement using exponentially. ThreshRatio: what is the minimum probability of matching to even be considered for a match BRatio, CRatio, ZRatio: p_match ~ b ^ (c * normalized_score) ^ z MaxBaselineRatio: maximum score that all scores will be normalized to baseline = min(min_score, MaxBaselineRatio) normalized_score = score - baseline

Public Types

using cache_state_t = RouletteCacheState

Public Functions

inline ExpRouletteSelector(Random &rand_)
inline std::string name() const override
inline virtual RouletteCacheState operator()(vector<std::pair<size_t, double>> scores, size_t n) override

Public Members

Random &rand
template<typename StochasticRatio = std::ratio<1, 10>, typename LockInRatio = std::ratio<-1, 1>, size_t DefaultN = std::numeric_limits<size_t>::max()>
struct SieveSelector : public SelectorBase<SieveCacheState>
#include <matchbin_selectors.hpp>

Selector treats each element of the MatchBin independently. As match distance increases, each element passes through a regime where selection is guaranteed, a regime where selection is stochastic, and then a regime where non-selection is guaranteed.

Public Types

using cache_state_t = SieveCacheState

Public Functions

inline SieveSelector(Random &rand_)
inline std::string name() const override
inline virtual SieveCacheState operator()(vector<std::pair<size_t, double>> scores, size_t n) override

Public Members

Random &rand