Code simplification: reverting to the previous point is done in lbfgs() function.
git-svn-id: file:///home/svnrepos/software/liblbfgs/trunk@41 ecf4c44f-38d1-4fa4-9757-a0b4dd0349fc
This commit is contained in:
parent
4edf33c84e
commit
d1ab96d686
34
lib/lbfgs.c
34
lib/lbfgs.c
@ -482,6 +482,9 @@ int lbfgs(
|
|||||||
owlqn_pseudo_gradient(pg, x, g, n, 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);
|
||||||
}
|
}
|
||||||
if (ls < 0) {
|
if (ls < 0) {
|
||||||
|
/* Revert to the previous point. */
|
||||||
|
veccpy(x, xp, n);
|
||||||
|
veccpy(g, gp, n);
|
||||||
ret = ls;
|
ret = ls;
|
||||||
goto lbfgs_exit;
|
goto lbfgs_exit;
|
||||||
}
|
}
|
||||||
@ -702,8 +705,7 @@ static int line_search_backtracking_owlqn(
|
|||||||
|
|
||||||
if (*stp < param->min_step) {
|
if (*stp < param->min_step) {
|
||||||
/* The step is the minimum value. */
|
/* The step is the minimum value. */
|
||||||
ret = LBFGSERR_MINIMUMSTEP;
|
return LBFGSERR_MINIMUMSTEP;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
if (*stp > param->max_step) {
|
if (*stp > param->max_step) {
|
||||||
/* The step is the maximum value. */
|
/* The step is the maximum value. */
|
||||||
@ -711,17 +713,11 @@ static int line_search_backtracking_owlqn(
|
|||||||
}
|
}
|
||||||
if (param->max_linesearch <= count) {
|
if (param->max_linesearch <= count) {
|
||||||
/* Maximum number of iteration. */
|
/* Maximum number of iteration. */
|
||||||
ret = LBFGSERR_MAXIMUMLINESEARCH;
|
return LBFGSERR_MAXIMUMLINESEARCH;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
(*stp) *= width;
|
(*stp) *= width;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Revert to the previous position. */
|
|
||||||
veccpy(x, xp, n);
|
|
||||||
veccpy(g, gp, n);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -790,8 +786,7 @@ static int line_search_backtracking_loose(
|
|||||||
}
|
}
|
||||||
if (*stp < param->min_step) {
|
if (*stp < param->min_step) {
|
||||||
/* The step is the minimum value. */
|
/* The step is the minimum value. */
|
||||||
ret = LBFGSERR_MINIMUMSTEP;
|
return LBFGSERR_MINIMUMSTEP;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
if (*stp > param->max_step) {
|
if (*stp > param->max_step) {
|
||||||
/* The step is the maximum value. */
|
/* The step is the maximum value. */
|
||||||
@ -799,16 +794,11 @@ static int line_search_backtracking_loose(
|
|||||||
}
|
}
|
||||||
if (param->max_linesearch <= count) {
|
if (param->max_linesearch <= count) {
|
||||||
/* Maximum number of iteration. */
|
/* Maximum number of iteration. */
|
||||||
ret = LBFGSERR_MAXIMUMLINESEARCH;
|
return LBFGSERR_MAXIMUMLINESEARCH;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
(*stp) *= width;
|
(*stp) *= width;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Revert to the previous position. */
|
|
||||||
veccpy(x, xp, n);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -892,8 +882,7 @@ static int line_search_backtracking_strong_wolfe(
|
|||||||
|
|
||||||
if (*stp < param->min_step) {
|
if (*stp < param->min_step) {
|
||||||
/* The step is the minimum value. */
|
/* The step is the minimum value. */
|
||||||
ret = LBFGSERR_MINIMUMSTEP;
|
return LBFGSERR_MINIMUMSTEP;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
if (*stp > param->max_step) {
|
if (*stp > param->max_step) {
|
||||||
/* The step is the maximum value. */
|
/* The step is the maximum value. */
|
||||||
@ -901,16 +890,11 @@ static int line_search_backtracking_strong_wolfe(
|
|||||||
}
|
}
|
||||||
if (param->max_linesearch <= count) {
|
if (param->max_linesearch <= count) {
|
||||||
/* Maximum number of iteration. */
|
/* Maximum number of iteration. */
|
||||||
ret = LBFGSERR_MAXIMUMLINESEARCH;
|
return LBFGSERR_MAXIMUMLINESEARCH;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*stp *= mult;
|
*stp *= mult;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Revert to the previous position. */
|
|
||||||
veccpy(x, xp, n);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user