Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bug in OWLQN: use raw gradient to calculate y vectors #90

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/edu/stanford/nlp/optimization/QNMinimizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ public double[] minimize(DiffFunction dFunction, double functionTolerance,
noHistory = false;
}

double[] x, newX, grad, newGrad, dir;
double[] x, newX, rawGrad, grad, newGrad, dir;
double value;
its = 0;
fevals = 0;
Expand All @@ -924,19 +924,20 @@ public double[] minimize(DiffFunction dFunction, double functionTolerance,
x = initial;

// initialize gradient
grad = new double[x.length];
rawGrad = new double[x.length];
newGrad = new double[x.length];
newX = new double[x.length];
dir = new double[x.length];

// initialize function value and gradient (gradient is stored in grad inside
// evaluateFunction)
value = evaluateFunction(dFunction, x, grad);
value = evaluateFunction(dFunction, x, rawGrad);
if (useOWLQN) {
double norm = l1NormOWL(x, dFunction);
value += norm * lambdaOWL;
grad = pseudoGradientOWL(x, grad, dFunction); // step (1) in Galen & Gao except we are not computing v yet
}
// step (1) in Galen & Gao except we are not computing v yet
grad = pseudoGradientOWL(x, rawGrad, dFunction);
} else grad = rawGrad;

PrintWriter outFile = null;
PrintWriter infoFile = null;
Expand All @@ -958,7 +959,7 @@ public double[] minimize(DiffFunction dFunction, double functionTolerance,

Record rec = new Record(quiet, monitor, functionTolerance, outFile);
// sets the original gradient and x. Also stores the monitor.
rec.start(value, grad, x);
rec.start(value, rawGrad, x);

// Check if max Evaluations and Iterations have been provided.
maxFevals = (maxFunctionEvaluations > 0) ? maxFunctionEvaluations
Expand Down Expand Up @@ -1049,9 +1050,10 @@ public double[] minimize(DiffFunction dFunction, double functionTolerance,
System.arraycopy(dFunction.derivativeAt(newX), 0, newGrad, 0, newGrad.length);

// This is where all the s, y updates are applied.
qn.update(newX, x, newGrad, grad, newPoint[a]); // step (4) in Galen & Gao 2007
qn.update(newX, x, newGrad, rawGrad, newPoint[a]); // step (4) in Galen & Gao 2007

if (useOWLQN) {
System.arraycopy(newGrad, 0, rawGrad, 0, newGrad.length);
// pseudo gradient
newGrad = pseudoGradientOWL(newX, newGrad, dFunction);
}
Expand Down