Fixed the termination condition for OW-LQN.
git-svn-id: file:///home/svnrepos/software/liblbfgs/trunk@17 ecf4c44f-38d1-4fa4-9757-a0b4dd0349fc
This commit is contained in:
parent
7efbd5aca1
commit
83b5fd9801
50
lib/lbfgs.c
50
lib/lbfgs.c
@ -169,6 +169,15 @@ static int update_trial_interval(
|
|||||||
int *brackt
|
int *brackt
|
||||||
);
|
);
|
||||||
|
|
||||||
|
static lbfgsfloatval_t orthantwise_gnorm(
|
||||||
|
const lbfgsfloatval_t* x,
|
||||||
|
const lbfgsfloatval_t* g,
|
||||||
|
const lbfgsfloatval_t c,
|
||||||
|
const int start,
|
||||||
|
const int n
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
#if defined(USE_SSE) && (defined(__SSE__) || defined(__SSE2__))
|
#if defined(USE_SSE) && (defined(__SSE__) || defined(__SSE2__))
|
||||||
static int round_out_variables(int n)
|
static int round_out_variables(int n)
|
||||||
{
|
{
|
||||||
@ -357,8 +366,12 @@ int lbfgs(
|
|||||||
/*
|
/*
|
||||||
Make sure that the initial variables are not a minimizer.
|
Make sure that the initial variables are not a minimizer.
|
||||||
*/
|
*/
|
||||||
vecnorm(&gnorm, g, n);
|
|
||||||
vecnorm(&xnorm, x, n);
|
vecnorm(&xnorm, x, n);
|
||||||
|
if (param->orthantwise_c != 0.) {
|
||||||
|
gnorm = orthantwise_gnorm(x, g, param->orthantwise_c, param->orthantwise_start, n);
|
||||||
|
} else {
|
||||||
|
vecnorm(&gnorm, g, n);
|
||||||
|
}
|
||||||
if (xnorm < 1.0) xnorm = 1.0;
|
if (xnorm < 1.0) xnorm = 1.0;
|
||||||
if (gnorm / xnorm <= param->epsilon) {
|
if (gnorm / xnorm <= param->epsilon) {
|
||||||
ret = LBFGS_ALREADY_MINIMIZED;
|
ret = LBFGS_ALREADY_MINIMIZED;
|
||||||
@ -385,8 +398,12 @@ int lbfgs(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Compute x and g norms. */
|
/* Compute x and g norms. */
|
||||||
vecnorm(&gnorm, g, n);
|
|
||||||
vecnorm(&xnorm, x, n);
|
vecnorm(&xnorm, x, n);
|
||||||
|
if (param->orthantwise_c != 0.) {
|
||||||
|
gnorm = orthantwise_gnorm(x, g, param->orthantwise_c, param->orthantwise_start, n);
|
||||||
|
} else {
|
||||||
|
vecnorm(&gnorm, g, n);
|
||||||
|
}
|
||||||
|
|
||||||
/* Report the progress. */
|
/* Report the progress. */
|
||||||
if (cd.proc_progress) {
|
if (cd.proc_progress) {
|
||||||
@ -1217,3 +1234,32 @@ static int update_trial_interval(
|
|||||||
*t = newt;
|
*t = newt;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static lbfgsfloatval_t orthantwise_gnorm(
|
||||||
|
const lbfgsfloatval_t* x,
|
||||||
|
const lbfgsfloatval_t* g,
|
||||||
|
const lbfgsfloatval_t c,
|
||||||
|
const int start,
|
||||||
|
const int n
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
lbfgsfloatval_t d = 0.;
|
||||||
|
lbfgsfloatval_t norm = 0.;
|
||||||
|
|
||||||
|
for (i = 0;i < start;++i) {
|
||||||
|
norm += g[i] * g[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = start;i < n;++i) {
|
||||||
|
d = g[i];
|
||||||
|
if (x[i] < 0.) {
|
||||||
|
d -= c;
|
||||||
|
} else if (0. < x[i]) {
|
||||||
|
d += c;
|
||||||
|
}
|
||||||
|
norm += d * d;
|
||||||
|
}
|
||||||
|
|
||||||
|
return sqrt(norm);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user