A bug fix.

git-svn-id: file:///home/svnrepos/software/liblbfgs/trunk@33 ecf4c44f-38d1-4fa4-9757-a0b4dd0349fc
This commit is contained in:
naoaki 2009-02-16 06:47:35 +00:00
parent 768d2cdd79
commit 9df185fd7b

View File

@ -231,9 +231,10 @@ static void owlqn_pseudo_gradient(
lbfgsfloatval_t* pg, lbfgsfloatval_t* pg,
const lbfgsfloatval_t* x, const lbfgsfloatval_t* x,
const lbfgsfloatval_t* g, const lbfgsfloatval_t* g,
const int n,
const lbfgsfloatval_t c, const lbfgsfloatval_t c,
const int start, const int start,
const int n const int end
); );
static lbfgsfloatval_t owlqn_direction_line( static lbfgsfloatval_t owlqn_direction_line(
@ -428,7 +429,7 @@ int lbfgs(
/* Compute the L1 norm of the variable and add it to the object value. */ /* Compute the L1 norm of the variable and add it to the object value. */
xnorm = owlqn_x1norm(x, param.orthantwise_start, param.orthantwise_end); xnorm = owlqn_x1norm(x, param.orthantwise_start, param.orthantwise_end);
fx += xnorm * param.orthantwise_c; fx += xnorm * param.orthantwise_c;
owlqn_pseudo_gradient(pg, x, g, param.orthantwise_c, param.orthantwise_start, param.orthantwise_end); owlqn_pseudo_gradient(pg, x, g, n, param.orthantwise_c, param.orthantwise_start, param.orthantwise_end);
} }
/* Store the initial value of the objective function. */ /* Store the initial value of the objective function. */
@ -478,6 +479,7 @@ int lbfgs(
ls = linesearch(n, x, &fx, g, d, &step, xp, gp, w, &cd, &param); ls = linesearch(n, x, &fx, g, d, &step, xp, gp, w, &cd, &param);
} else { } else {
ls = linesearch(n, x, &fx, g, d, &step, xp, pg, w, &cd, &param); ls = linesearch(n, x, &fx, g, d, &step, xp, pg, w, &cd, &param);
owlqn_pseudo_gradient(pg, x, g, n, param.orthantwise_c, param.orthantwise_start, param.orthantwise_end);
} }
if (ls < 0) { if (ls < 0) {
ret = ls; ret = ls;
@ -1496,9 +1498,10 @@ static void owlqn_pseudo_gradient(
lbfgsfloatval_t* pg, lbfgsfloatval_t* pg,
const lbfgsfloatval_t* x, const lbfgsfloatval_t* x,
const lbfgsfloatval_t* g, const lbfgsfloatval_t* g,
const int n,
const lbfgsfloatval_t c, const lbfgsfloatval_t c,
const int start, const int start,
const int n const int end
) )
{ {
int i; int i;
@ -1508,8 +1511,8 @@ static void owlqn_pseudo_gradient(
pg[i] = g[i]; pg[i] = g[i];
} }
/* Compute the negative of psuedo-gradients. */ /* Compute the psuedo-gradients. */
for (i = start;i < n;++i) { for (i = start;i < end;++i) {
if (x[i] < 0.) { if (x[i] < 0.) {
/* Differentiable. */ /* Differentiable. */
pg[i] = g[i] - c; pg[i] = g[i] - c;
@ -1528,6 +1531,10 @@ static void owlqn_pseudo_gradient(
} }
} }
} }
for (i = end;i < n;++i) {
pg[i] = g[i];
}
} }