From 5a8c49572325e9065a15af50e4231339609a2993 Mon Sep 17 00:00:00 2001 From: pavithraks Date: Wed, 20 Mar 2019 14:36:14 -0400 Subject: [PATCH] Fix to bug 1729: no bias regularization for BFGS not working (#1794) * fix to bug 1729 * fix to bug 1729 --- vowpalwabbit/bfgs.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/vowpalwabbit/bfgs.cc b/vowpalwabbit/bfgs.cc index daa179a47a7..1eb2d8bd232 100644 --- a/vowpalwabbit/bfgs.cc +++ b/vowpalwabbit/bfgs.cc @@ -457,18 +457,19 @@ double add_regularization(vw& all, bfgs& b, float regularization, T& weights) } // if we're not regularizing the intercept term, then subtract it off from the result above + // when accessing weights[constant], always use weights.strided_index(constant) if (all.no_bias) { if (b.regularizers == nullptr) { - (&weights[constant])[W_GT] -= regularization * weights[constant]; - ret -= 0.5 * regularization * (weights[constant]) * (weights[constant]); + (&weights.strided_index(constant))[W_GT] -= regularization * (weights.strided_index(constant)); + ret -= 0.5 * regularization * (weights.strided_index(constant)) * (weights.strided_index(constant)); } else { uint64_t i = constant >> weights.stride_shift(); - weight delta_weight = weights[constant] - b.regularizers[2 * i + 1]; - (&weights[constant])[W_GT] -= b.regularizers[2 * i] * delta_weight; + weight delta_weight = (weights.strided_index(constant)) - b.regularizers[2 * i + 1]; + (&weights.strided_index(constant))[W_GT] -= b.regularizers[2 * i] * delta_weight; ret -= 0.5 * b.regularizers[2 * i] * delta_weight * delta_weight; } }