summaryrefslogtreecommitdiff
path: root/dtrain/sample.h
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2011-09-09 00:41:17 +0200
committerPatrick Simianer <p@simianer.de>2011-09-23 19:13:58 +0200
commit14637f89c899179f54a5bc327857db8ea1e1d427 (patch)
tree66cdbfd8039107075509faa4a4d1dc5dc33698cc /dtrain/sample.h
parent0269777fc54bc554c12107bdd5498f743df2a1ce (diff)
added svm, ksampler
Diffstat (limited to 'dtrain/sample.h')
-rw-r--r--dtrain/sample.h64
1 files changed, 38 insertions, 26 deletions
diff --git a/dtrain/sample.h b/dtrain/sample.h
index b9bc4461..b6aa9abd 100644
--- a/dtrain/sample.h
+++ b/dtrain/sample.h
@@ -1,3 +1,7 @@
+#ifndef _DTRAIN_SAMPLE_H_
+#define _DTRAIN_SAMPLE_H_
+
+
#include "kbestget.h"
@@ -7,9 +11,9 @@ namespace dtrain
struct TPair
{
- double type;
- SparseVector<double> first;
- SparseVector<double> second;
+ SparseVector<double> first, second;
+ size_t first_rank, second_rank;
+ double first_score, second_score;
};
typedef vector<TPair> TrainingInstances;
@@ -18,35 +22,43 @@ typedef vector<TPair> TrainingInstances;
void
sample_all( KBestList* kb, TrainingInstances &training )
{
- double type;
for ( size_t i = 0; i < kb->GetSize()-1; i++ ) {
- for ( size_t j = i+1; j < kb->GetSize(); j++ ) {
- if ( kb->scores[i] - kb->scores[j] < 0 ) {
- type = -1;
- } else {
- type = 1;
- }
- TPair p;
- p.type = type;
- p.first = kb->feats[i];
- p.second = kb->feats[j];
- training.push_back( p );
- }
- }
-}
-
-/*void
-sample_all_only_neg(, vector<pair<SparSparseVector<double> > pairs)
-{
-
+ for ( size_t j = i+1; j < kb->GetSize(); j++ ) {
+ TPair 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];
+ training.push_back( p );
+ }
+ }
}
void
-sample_random_pos()
+sample_all_rand( KBestList* kb, TrainingInstances &training )
{
- if ( rand() % 2 ) { // sample it?
-}*/
+ srand( time(NULL) );
+ for ( size_t i = 0; i < kb->GetSize()-1; i++ ) {
+ for ( size_t j = i+1; j < kb->GetSize(); j++ ) {
+ if ( rand() % 2 ) {
+ TPair 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];
+ training.push_back( p );
+ }
+ }
+ }
+}
} // namespace
+
+#endif
+