diff options
Diffstat (limited to 'dtrain/pairsampling.h')
-rw-r--r-- | dtrain/pairsampling.h | 48 |
1 files changed, 17 insertions, 31 deletions
diff --git a/dtrain/pairsampling.h b/dtrain/pairsampling.h index a8521485..2e4ab155 100644 --- a/dtrain/pairsampling.h +++ b/dtrain/pairsampling.h @@ -8,47 +8,33 @@ namespace dtrain { -struct Pair -{ - SparseVector<double> first, second; - size_t first_rank, second_rank; - double first_score, second_score; -}; - inline void -sample_all_pairs(Samples* kb, vector<Pair> &training) +sample_all_pairs(vector<ScoredHyp>* s, vector<pair<ScoredHyp,ScoredHyp> > &training) { - for (size_t i = 0; i < kb->GetSize()-1; i++) { - for (size_t j = i+1; j < kb->GetSize(); j++) { - Pair p; - p.first = kb->feats[i]; - p.second = kb->feats[j]; - p.first_rank = i; - p.second_rank = j; - p.first_score = kb->scores[i]; - p.second_score = kb->scores[j]; + for (size_t i = 0; i < s->size()-1; i++) { + for (size_t j = i+1; j < s->size(); j++) { + pair<ScoredHyp,ScoredHyp> p; + p.first = (*s)[i]; + p.second = (*s)[j]; training.push_back(p); - } // j - } // i + } + } } inline void -sample_rand_pairs(Samples* kb, vector<Pair> &training, MT19937* prng) +sample_rand_pairs(vector<ScoredHyp>* s, vector<pair<ScoredHyp,ScoredHyp> > &training, + MT19937* prng) { - for (size_t i = 0; i < kb->GetSize()-1; i++) { - for (size_t j = i+1; j < kb->GetSize(); j++) { + for (size_t i = 0; i < s->size()-1; i++) { + for (size_t j = i+1; j < s->size(); j++) { if (prng->next() < .5) { - Pair p; - p.first = kb->feats[i]; - p.second = kb->feats[j]; - p.first_rank = i; - p.second_rank = j; - p.first_score = kb->scores[i]; - p.second_score = kb->scores[j]; + pair<ScoredHyp,ScoredHyp> p; + p.first = (*s)[i]; + p.second = (*s)[j]; training.push_back(p); } - } // j - } // i + } + } } |