Lines Matching refs:ls

10 static PetscErrorCode Tao_mcstep(TaoLineSearch ls, PetscReal *stx, PetscReal *fx, PetscReal *dx, Pe…
12 static PetscErrorCode TaoLineSearchDestroy_MT(TaoLineSearch ls) in TaoLineSearchDestroy_MT() argument
14 TaoLineSearch_MT *mt = (TaoLineSearch_MT *)ls->data; in TaoLineSearchDestroy_MT()
19 PetscCall(PetscFree(ls->data)); in TaoLineSearchDestroy_MT()
23 static PetscErrorCode TaoLineSearchMonitor_MT(TaoLineSearch ls) in TaoLineSearchMonitor_MT() argument
25 TaoLineSearch_MT *mt = (TaoLineSearch_MT *)ls->data; in TaoLineSearchMonitor_MT()
28 …PetscCall(PetscViewerASCIIPrintf(ls->viewer, "stx: %g, fx: %g, dgx: %g\n", (double)mt->stx, (doubl… in TaoLineSearchMonitor_MT()
29 …PetscCall(PetscViewerASCIIPrintf(ls->viewer, "sty: %g, fy: %g, dgy: %g\n", (double)mt->sty, (doubl… in TaoLineSearchMonitor_MT()
33 static PetscErrorCode TaoLineSearchApply_MT(TaoLineSearch ls, Vec x, PetscReal *f, Vec g, Vec s) in TaoLineSearchApply_MT() argument
35 TaoLineSearch_MT *mt = (TaoLineSearch_MT *)ls->data; in TaoLineSearchApply_MT()
45 ls->reason = TAOLINESEARCH_CONTINUE_ITERATING; in TaoLineSearchApply_MT()
46 PetscCall(TaoLineSearchMonitor(ls, 0, *f, 0.0)); in TaoLineSearchApply_MT()
60 ostepmax = ls->stepmax; in TaoLineSearchApply_MT()
61 ostepmin = ls->stepmin; in TaoLineSearchApply_MT()
63 if (ls->bounded) { in TaoLineSearchApply_MT()
67 PetscCall(VecGetLocalSize(ls->upper, &n1)); in TaoLineSearchApply_MT()
69 PetscCall(VecGetSize(ls->upper, &nn1)); in TaoLineSearchApply_MT()
73 PetscCall(VecBoundGradientProjection(s, x, ls->lower, ls->upper, s)); in TaoLineSearchApply_MT()
75 PetscCall(VecStepBoundInfo(x, s, ls->lower, ls->upper, &bstepmin1, &bstepmin2, &bstepmax)); in TaoLineSearchApply_MT()
76 ls->stepmax = PetscMin(bstepmax, ls->stepmax); in TaoLineSearchApply_MT()
81 …PetscCall(PetscInfo(ls, "Initial Line Search step * g is infinity or NaN (%g)\n", (double)dginit)); in TaoLineSearchApply_MT()
82 ls->reason = TAOLINESEARCH_FAILED_INFORNAN; in TaoLineSearchApply_MT()
86 …PetscCall(PetscInfo(ls, "Initial Line Search step * g is not descent direction (%g)\n", (double)dg… in TaoLineSearchApply_MT()
87 ls->reason = TAOLINESEARCH_FAILED_ASCENT; in TaoLineSearchApply_MT()
95 dgtest = ls->ftol * dginit; in TaoLineSearchApply_MT()
96 width = ls->stepmax - ls->stepmin; in TaoLineSearchApply_MT()
112 ls->step = ls->initstep; in TaoLineSearchApply_MT()
113 for (i = 0; i < ls->max_funcs; i++) { in TaoLineSearchApply_MT()
116 ls->stepmin = PetscMin(stx, sty); in TaoLineSearchApply_MT()
117 ls->stepmax = PetscMax(stx, sty); in TaoLineSearchApply_MT()
119 ls->stepmin = stx; in TaoLineSearchApply_MT()
120 ls->stepmax = ls->step + xtrapf * (ls->step - stx); in TaoLineSearchApply_MT()
124 ls->step = PetscMax(ls->step, ls->stepmin); in TaoLineSearchApply_MT()
125 ls->step = PetscMin(ls->step, ls->stepmax); in TaoLineSearchApply_MT()
129ls->step <= ls->stepmin || ls->step >= ls->stepmax)) || (mt->bracket && (ls->stepmax - ls->stepmin… in TaoLineSearchApply_MT()
130 ls->step = stx; in TaoLineSearchApply_MT()
132 PetscCall(VecWAXPY(mt->work, ls->step, s, x)); /* W = X + step*S */ in TaoLineSearchApply_MT()
134 if (ls->step == 0.0) { in TaoLineSearchApply_MT()
135 PetscCall(PetscInfo(ls, "Step size is zero.\n")); in TaoLineSearchApply_MT()
136 ls->reason = TAOLINESEARCH_HALTED_LOWERBOUND; in TaoLineSearchApply_MT()
140 if (ls->bounded) PetscCall(VecMedian(ls->lower, mt->work, ls->upper, mt->work)); in TaoLineSearchApply_MT()
143 if (ls->usegts) { in TaoLineSearchApply_MT()
144 PetscCall(TaoLineSearchComputeObjectiveAndGTS(ls, mt->work, f, &dg)); in TaoLineSearchApply_MT()
147 PetscCall(TaoLineSearchComputeObjectiveAndGradient(ls, mt->work, f, g)); in TaoLineSearchApply_MT()
149 if (ls->bounded) { in TaoLineSearchApply_MT()
152 dg = (dg2 - dg) / ls->step; in TaoLineSearchApply_MT()
166 PetscCall(TaoLineSearchMonitor(ls, i + 1, *f, ls->step)); in TaoLineSearchApply_MT()
168 if (i == 0) ls->f_fullstep = *f; in TaoLineSearchApply_MT()
178 ftest1 = finit + ls->step * dgtest; in TaoLineSearchApply_MT()
179 if (ls->bounded) ftest2 = finit + ls->step * dgtest * ls->ftol; in TaoLineSearchApply_MT()
182 …if ((*f - ftest1 <= PETSC_SMALL * PetscAbsReal(finit)) && (PetscAbsReal(dg) + ls->gtol * dginit <=… in TaoLineSearchApply_MT()
183 …PetscCall(PetscInfo(ls, "Line search success: Sufficient decrease and directional deriv conditions… in TaoLineSearchApply_MT()
184 ls->reason = TAOLINESEARCH_SUCCESS; in TaoLineSearchApply_MT()
189 if (ls->bounded && *f <= ftest2 && ls->step >= bstepmin2) { in TaoLineSearchApply_MT()
190 PetscCall(PetscInfo(ls, "Line search success: Sufficient decrease.\n")); in TaoLineSearchApply_MT()
191 ls->reason = TAOLINESEARCH_SUCCESS; in TaoLineSearchApply_MT()
196 if ((mt->bracket && (ls->step <= ls->stepmin || ls->step >= ls->stepmax)) || !mt->infoc) { in TaoLineSearchApply_MT()
197 …PetscCall(PetscInfo(ls, "Rounding errors may prevent further progress. May not be a step satisfyin… in TaoLineSearchApply_MT()
198 ls->reason = TAOLINESEARCH_HALTED_OTHER; in TaoLineSearchApply_MT()
201 if (ls->step == ls->stepmax && *f <= ftest1 && dg <= dgtest) { in TaoLineSearchApply_MT()
202 PetscCall(PetscInfo(ls, "Step is at the upper bound, stepmax (%g)\n", (double)ls->stepmax)); in TaoLineSearchApply_MT()
203 ls->reason = TAOLINESEARCH_HALTED_UPPERBOUND; in TaoLineSearchApply_MT()
206 if (ls->step == ls->stepmin && *f >= ftest1 && dg >= dgtest) { in TaoLineSearchApply_MT()
207 PetscCall(PetscInfo(ls, "Step is at the lower bound, stepmin (%g)\n", (double)ls->stepmin)); in TaoLineSearchApply_MT()
208 ls->reason = TAOLINESEARCH_HALTED_LOWERBOUND; in TaoLineSearchApply_MT()
211 if (mt->bracket && (ls->stepmax - ls->stepmin <= ls->rtol * ls->stepmax)) { in TaoLineSearchApply_MT()
212 …PetscCall(PetscInfo(ls, "Relative width of interval of uncertainty is at most rtol (%g)\n", (doubl… in TaoLineSearchApply_MT()
213 ls->reason = TAOLINESEARCH_HALTED_RTOL; in TaoLineSearchApply_MT()
219 if (stage1 && *f <= ftest1 && dg >= dginit * PetscMin(ls->ftol, ls->gtol)) stage1 = 0; in TaoLineSearchApply_MT()
228 fm = *f - ls->step * dgtest; /* Define modified function */ in TaoLineSearchApply_MT()
237 PetscCall(Tao_mcstep(ls, &stx, &fxm, &dgxm, &sty, &fym, &dgym, &ls->step, &fm, &dgm)); in TaoLineSearchApply_MT()
245 PetscCall(Tao_mcstep(ls, &stx, &fx, &dgx, &sty, &fy, &dgy, &ls->step, f, &dg)); in TaoLineSearchApply_MT()
250 if (PetscAbsReal(sty - stx) >= 0.66 * width1) ls->step = stx + 0.5 * (sty - stx); in TaoLineSearchApply_MT()
255 if (ls->nfeval + ls->nfgeval > ls->max_funcs) { in TaoLineSearchApply_MT()
256 …all(PetscInfo(ls, "Number of line search function evals (%" PetscInt_FMT ") > maximum (%" PetscInt… in TaoLineSearchApply_MT()
257 ls->reason = TAOLINESEARCH_HALTED_MAXFCN; in TaoLineSearchApply_MT()
259 ls->stepmax = ostepmax; in TaoLineSearchApply_MT()
260 ls->stepmin = ostepmin; in TaoLineSearchApply_MT()
263 …PetscCall(PetscInfo(ls, "%" PetscInt_FMT " function evals in line search, step = %g\n", ls->nfeval… in TaoLineSearchApply_MT()
267 if (!g_computed) PetscCall(TaoLineSearchComputeGradient(ls, x, g)); in TaoLineSearchApply_MT()
282 PETSC_EXTERN PetscErrorCode TaoLineSearchCreate_MT(TaoLineSearch ls) in TaoLineSearchCreate_MT() argument
287 PetscValidHeaderSpecific(ls, TAOLINESEARCH_CLASSID, 1); in TaoLineSearchCreate_MT()
291 ls->data = (void *)ctx; in TaoLineSearchCreate_MT()
292 ls->initstep = 1.0; in TaoLineSearchCreate_MT()
293 ls->ops->setup = NULL; in TaoLineSearchCreate_MT()
294 ls->ops->reset = NULL; in TaoLineSearchCreate_MT()
295 ls->ops->apply = TaoLineSearchApply_MT; in TaoLineSearchCreate_MT()
296 ls->ops->destroy = TaoLineSearchDestroy_MT; in TaoLineSearchCreate_MT()
297 ls->ops->monitor = TaoLineSearchMonitor_MT; in TaoLineSearchCreate_MT()
363 static PetscErrorCode Tao_mcstep(TaoLineSearch ls, PetscReal *stx, PetscReal *fx, PetscReal *dx, Pe… in Tao_mcstep() argument
365 TaoLineSearch_MT *mtP = (TaoLineSearch_MT *)ls->data; in Tao_mcstep()
374 …PetscCheck(ls->stepmax >= ls->stepmin, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "stepmax > stepm… in Tao_mcstep()
448 else if (*stp > *stx) stpc = ls->stepmax; in Tao_mcstep()
449 else stpc = ls->stepmin; in Tao_mcstep()
479 stpf = ls->stepmax; in Tao_mcstep()
481 stpf = ls->stepmin; in Tao_mcstep()
504 stpf = PetscMin(ls->stepmax, stpf); in Tao_mcstep()
505 stpf = PetscMax(ls->stepmin, stpf); in Tao_mcstep()