diff options
author | Paul Mineiro <paul-github@mineiro.com> | 2013-12-21 23:39:24 +0400 |
---|---|---|
committer | Paul Mineiro <paul-github@mineiro.com> | 2013-12-21 23:39:24 +0400 |
commit | 899a5560f5fd6e4e6a42f3df89e1fdae20a4db72 (patch) | |
tree | b04cff4b73656e3105792b3a550cb42cbf00e7e0 /vowpalwabbit/lrq.cc | |
parent | ca02bb2330ca933a61b96167542e700dc4312546 (diff) |
alternating least squares mf
Diffstat (limited to 'vowpalwabbit/lrq.cc')
-rw-r--r-- | vowpalwabbit/lrq.cc | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/vowpalwabbit/lrq.cc b/vowpalwabbit/lrq.cc index 82f6ec2a..01402cd6 100644 --- a/vowpalwabbit/lrq.cc +++ b/vowpalwabbit/lrq.cc @@ -1,6 +1,7 @@ #include "gd.h" #include "vw.h" #include "lrq.h" +#include <float.h> namespace { bool @@ -13,6 +14,20 @@ namespace { return (*s != '\0' && *endptr == '\0'); } + + inline float + cheesyrand (uint32_t x) + { + uint32_t v = 1664525 * x + 1013904223; + + return ((float) v) / 2147483648; + } + + inline bool + example_is_test (example* ec) + { + return ec->test_only || (((label_data*) ec->ld)->label == FLT_MAX); + } } namespace LRQ { @@ -66,7 +81,11 @@ namespace LRQ { { uint32_t lwindex = lindex + n * all.reg.stride; - float lw = all.reg.weight_vector[lwindex & all.reg.weight_mask]; + float* lw = &all.reg.weight_vector[lwindex & all.reg.weight_mask]; + + // perturb away from saddle point at (0, 0) + if (all.training && ! example_is_test (ec) && *lw == 0) + *lw = cheesyrand (lwindex); for (unsigned int rfn = 0; rfn < lrq->orig_size[right]; @@ -79,7 +98,7 @@ namespace LRQ { uint32_t rwindex = rindex + n * all.reg.stride; feature lrq; - lrq.x = lw; + lrq.x = *lw; lrq.weight_index = rwindex; ec->atomics[right].push_back (lrq); |