Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/vowpal_wabbit.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Langford <jl@hunch.net>2011-06-25 19:55:09 +0400
committerJohn Langford <jl@hunch.net>2011-06-25 19:55:09 +0400
commit1b77637e310807de16619c22bfad478f2c02c18c (patch)
tree9ad44f3a049d8293b2acbfe32ccee2fda201bec1 /simple_label.cc
parentcda12a14ba94b79863f4e2eed6736ef76ebd84a0 (diff)
changed label to include an initial offset, allowing residual prediction
Diffstat (limited to 'simple_label.cc')
-rw-r--r--simple_label.cc28
1 files changed, 22 insertions, 6 deletions
diff --git a/simple_label.cc b/simple_label.cc
index edf12321..67a2b831 100644
--- a/simple_label.cc
+++ b/simple_label.cc
@@ -5,11 +5,13 @@
char* bufread_simple_label(label_data* ld, char* c)
{
- ld->label = *(double *)c;
+ ld->label = *(float *)c;
c += sizeof(ld->label);
set_minmax(ld->label);
ld->weight = *(float *)c;
c += sizeof(ld->weight);
+ ld->initial = *(float *)c;
+ c += sizeof(ld->initial);
return c;
}
@@ -17,7 +19,7 @@ size_t read_cached_simple_label(void* v, io_buf& cache)
{
label_data* ld = (label_data*) v;
char *c;
- size_t total = sizeof(ld->label)+sizeof(ld->weight);
+ size_t total = sizeof(ld->label)+sizeof(ld->weight)+sizeof(ld->initial);
if (buf_read(cache, c, total) < total)
return 0;
c = bufread_simple_label(ld,c);
@@ -31,12 +33,20 @@ float get_weight(void* v)
return ld->weight;
}
+float get_initial(void* v)
+{
+ label_data* ld = (label_data*) v;
+ return ld->initial;
+}
+
char* bufcache_simple_label(label_data* ld, char* c)
{
- *(double *)c = ld->label;
+ *(float *)c = ld->label;
c += sizeof(ld->label);
*(float *)c = ld->weight;
c += sizeof(ld->weight);
+ *(float *)c = ld->initial;
+ c += sizeof(ld->initial);
return c;
}
@@ -44,7 +54,7 @@ void cache_simple_label(void* v, io_buf& cache)
{
char *c;
label_data* ld = (label_data*) v;
- buf_write(cache, c, sizeof(ld->label)+sizeof(ld->weight));
+ buf_write(cache, c, sizeof(ld->label)+sizeof(ld->weight)+sizeof(ld->initial));
c = bufcache_simple_label(ld,c);
}
@@ -53,6 +63,7 @@ void default_simple_label(void* v)
label_data* ld = (label_data*) v;
ld->label = FLT_MAX;
ld->weight = 1.;
+ ld->initial = 0.;
}
void delete_simple_label(void* v)
@@ -67,11 +78,16 @@ void parse_simple_label(void* v, v_array<substring>& words)
case 0:
break;
case 1:
- ld->label = double_of_substring(words[0]);
+ ld->label = float_of_substring(words[0]);
break;
case 2:
- ld->label = double_of_substring(words[0]);
+ ld->label = float_of_substring(words[0]);
+ ld->weight = float_of_substring(words[1]);
+ break;
+ case 3:
+ ld->label = float_of_substring(words[0]);
ld->weight = float_of_substring(words[1]);
+ ld->initial = float_of_substring(words[2]);
break;
default:
cerr << "malformed example!\n";