diff --git a/egs/lre/v1/conf/logistic-regression.conf b/egs/lre/v1/conf/logistic-regression.conf index f0cd5338b..ecef7a601 100644 --- a/egs/lre/v1/conf/logistic-regression.conf +++ b/egs/lre/v1/conf/logistic-regression.conf @@ -1,3 +1,3 @@ ---max-steps=10 +--max-steps=20 --normalizer=0.002 --verbose=2 diff --git a/src/ivector/logistic-regression.cc b/src/ivector/logistic-regression.cc index bd6773c45..f42d9353a 100644 --- a/src/ivector/logistic-regression.cc +++ b/src/ivector/logistic-regression.cc @@ -132,16 +132,17 @@ BaseFloat LogisticRegression::DoStep(const Matrix &xs, return objf; } -BaseFloat LogisticRegression::GetObjfAndGrad(const Matrix &xs, - const std::vector &ys, const Matrix &xw, - Matrix *grad, BaseFloat normalizer) { - BaseFloat objf = 0.0; +BaseFloat LogisticRegression::GetObjfAndGrad( + const Matrix &xs, + const std::vector &ys, const Matrix &xw, + Matrix *grad, BaseFloat normalizer) { + BaseFloat raw_objf = 0.0; // For each training example class for (int32 i = 0; i < ys.size(); i++) { Vector row(xw.NumCols()); row.CopyFromVec(xw.Row(i)); row.ApplySoftMax(); - objf += std::log(std::max(row(ys[i]), 1.0e-20)); + raw_objf += std::log(std::max(row(ys[i]), 1.0e-20)); SubVector x = xs.Row(i); // Iterate over the class labels for (int32 k = 0; k < weights_.NumRows(); k++) { @@ -157,9 +158,11 @@ BaseFloat LogisticRegression::GetObjfAndGrad(const Matrix &xs, // Scale and add regularization term. grad->Scale(1.0/ys.size()); grad->AddMat(-1.0 * normalizer, weights_); - objf /= ys.size(); - objf -= 0.5 * normalizer * TraceMatMat(weights_, weights_, kTrans); - return objf; + raw_objf /= ys.size(); + BaseFloat regularizer = - 0.5 * normalizer * TraceMatMat(weights_, weights_, kTrans); + KALDI_VLOG(2) << "Objf is " << raw_objf << " + " << regularizer + << " = " << (raw_objf + regularizer); + return raw_objf + regularizer; } void LogisticRegression::SetWeights(const Matrix &weights) { diff --git a/src/ivector/logistic-regression.h b/src/ivector/logistic-regression.h index 4b7326818..690f842c2 100644 --- a/src/ivector/logistic-regression.h +++ b/src/ivector/logistic-regression.h @@ -28,7 +28,7 @@ namespace kaldi { struct LogisticRegressionConfig { int32 max_steps; double normalizer; - LogisticRegressionConfig(): max_steps(20), normalizer(0.01) { } + LogisticRegressionConfig(): max_steps(20), normalizer(0.002) { } void Register(OptionsItf *po) { po->Register("max-steps", &max_steps, "Maximum steps in L-BFGS.");