From 14637f89c899179f54a5bc327857db8ea1e1d427 Mon Sep 17 00:00:00 2001
From: Patrick Simianer
Date: Fri, 9 Sep 2011 00:41:17 +0200
Subject: added svm, ksampler
---
dtrain/sample.h | 64 ++++++++++++++++++++++++++++++++++-----------------------
1 file changed, 38 insertions(+), 26 deletions(-)
(limited to 'dtrain/sample.h')
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 first;
- SparseVector second;
+ SparseVector first, second;
+ size_t first_rank, second_rank;
+ double first_score, second_score;
};
typedef vector TrainingInstances;
@@ -18,35 +22,43 @@ typedef vector 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 > 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
+
--
cgit v1.2.3