diff options
author | Jacob Hofman <hofman@research-mm5.corp.sp1.yahoo.com> | 2011-07-16 20:19:03 +0400 |
---|---|---|
committer | Jacob Hofman <hofman@research-mm5.corp.sp1.yahoo.com> | 2011-07-16 20:19:03 +0400 |
commit | eb808c44647d59c2cb7b94f0024ab74a242829c4 (patch) | |
tree | fe114e5558f576685e996ac64c9eb1e9f26b0dc7 /sparse_dense.cc | |
parent | 2af3c472e43030d9bd74921924ca7e8ba7eea749 (diff) | |
parent | 6cb47949f15cfad879976775ae20c733909e9518 (diff) |
integrated basic matrix factorization
Merge branch 'master' of git://github.com/JohnLangford/vowpal_wabbit
Conflicts:
Makefile
parse_regressor.cc
sparse_dense.cc
vw.cc
Diffstat (limited to 'sparse_dense.cc')
-rw-r--r-- | sparse_dense.cc | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/sparse_dense.cc b/sparse_dense.cc index 91f6e493..f99c5a09 100644 --- a/sparse_dense.cc +++ b/sparse_dense.cc @@ -16,6 +16,18 @@ float sd_add(weight* weights, size_t mask, feature* begin, feature* end) return ret; } +float sd_truncadd(weight* weights, size_t mask, feature* begin, feature* end, float gravity) +{ + float ret = 0.; + for (feature* f = begin; f!= end; f++) + { + float w = weights[f->weight_index & mask]; + float wprime = real_weight(w,gravity); + ret += wprime*f->x; + } + return ret; +} + float sd_offset_add(weight* weights, size_t mask, feature* begin, feature* end, size_t offset) { float ret = 0.; @@ -24,6 +36,18 @@ float sd_offset_add(weight* weights, size_t mask, feature* begin, feature* end, return ret; } +float sd_offset_truncadd(weight* weights, size_t mask, feature* begin, feature* end, size_t offset, float gravity) +{ + float ret = 0.; + for (feature* f = begin; f!= end; f++) + { + float w = weights[(f->weight_index+offset) & mask]; + float wprime = real_weight(w,gravity); + ret += wprime*f->x; + } + return ret; +} + void sd_offset_update(weight* weights, size_t mask, feature* begin, feature* end, size_t offset, float update, float regularization) { for (feature* f = begin; f!= end; f++) @@ -64,6 +88,14 @@ float one_pf_quad_predict(weight* weights, feature& f, v_array<feature> &cross_f sd_offset_add(weights, mask, cross_features.begin, cross_features.end, halfhash); } +float one_pf_quad_predict_trunc(weight* weights, feature& f, v_array<feature> &cross_features, size_t mask, float gravity) +{ + size_t halfhash = quadratic_constant * f.weight_index; + + return f.x * + sd_offset_truncadd(weights, mask, cross_features.begin, cross_features.end, halfhash, gravity); +} + float offset_quad_predict(weight* weights, feature& page_feature, v_array<feature> &offer_features, size_t mask, size_t offset) { float prediction = 0.0; |