Lines Matching refs:ls
4 static PetscErrorCode TaoLineSearchDestroy_GPCG(TaoLineSearch ls) in TaoLineSearchDestroy_GPCG() argument
6 TaoLineSearch_GPCG *ctx = (TaoLineSearch_GPCG *)ls->data; in TaoLineSearchDestroy_GPCG()
13 PetscCall(PetscFree(ls->data)); in TaoLineSearchDestroy_GPCG()
17 static PetscErrorCode TaoLineSearchView_GPCG(TaoLineSearch ls, PetscViewer viewer) in TaoLineSearchView_GPCG() argument
27 static PetscErrorCode TaoLineSearchApply_GPCG(TaoLineSearch ls, Vec x, PetscReal *f, Vec g, Vec s) in TaoLineSearchApply_GPCG() argument
29 TaoLineSearch_GPCG *neP = (TaoLineSearch_GPCG *)ls->data; in TaoLineSearchApply_GPCG()
44 PetscCall(TaoLineSearchMonitor(ls, 0, *f, 0.0)); in TaoLineSearchApply_GPCG()
46 ls->reason = TAOLINESEARCH_CONTINUE_ITERATING; in TaoLineSearchApply_GPCG()
47 ls->step = ls->initstep; in TaoLineSearchApply_GPCG()
69 …PetscCall(PetscInfo(ls, "Line search error: search direction is not descent direction. dot(g,s) = … in TaoLineSearchApply_GPCG()
70 ls->reason = TAOLINESEARCH_FAILED_ASCENT; in TaoLineSearchApply_GPCG()
75 if (ls->bounded) { in TaoLineSearchApply_GPCG()
77 PetscCall(VecStepBoundInfo(x, s, ls->lower, ls->upper, &rho, &actred, &d1)); in TaoLineSearchApply_GPCG()
78 ls->step = PetscMin(ls->step, d1); in TaoLineSearchApply_GPCG()
83 if (ls->step < 0) { in TaoLineSearchApply_GPCG()
84 PetscCall(PetscInfo(ls, "Line search error: initial step parameter %g< 0\n", (double)ls->step)); in TaoLineSearchApply_GPCG()
85 ls->reason = TAOLINESEARCH_HALTED_OTHER; in TaoLineSearchApply_GPCG()
91 for (i = 0; i < ls->max_funcs; i++) { in TaoLineSearchApply_GPCG()
93 ls->step = PetscMax(ls->step, ls->stepmin); in TaoLineSearchApply_GPCG()
94 ls->step = PetscMin(ls->step, ls->stepmax); in TaoLineSearchApply_GPCG()
96 PetscCall(VecWAXPY(neP->W2, ls->step, s, x)); in TaoLineSearchApply_GPCG()
97 if (ls->bounded) { in TaoLineSearchApply_GPCG()
99 PetscCall(VecMedian(neP->W2, ls->lower, ls->upper, neP->W2)); in TaoLineSearchApply_GPCG()
106 if (ls->hasobjective) { in TaoLineSearchApply_GPCG()
107 PetscCall(TaoLineSearchComputeObjective(ls, neP->W2, f)); in TaoLineSearchApply_GPCG()
109 } else if (ls->usegts) { in TaoLineSearchApply_GPCG()
110 PetscCall(TaoLineSearchComputeObjectiveAndGTS(ls, neP->W2, f, &gdx)); in TaoLineSearchApply_GPCG()
113 PetscCall(TaoLineSearchComputeObjectiveAndGradient(ls, neP->W2, f, g)); in TaoLineSearchApply_GPCG()
118 PetscCall(TaoLineSearchMonitor(ls, i + 1, *f, ls->step)); in TaoLineSearchApply_GPCG()
120 if (0 == i) ls->f_fullstep = *f; in TaoLineSearchApply_GPCG()
135 PetscCall(PetscInfo(ls, "Step resulted in ascent, rejecting.\n")); in TaoLineSearchApply_GPCG()
136 ls->step = (ls->step) / 2; in TaoLineSearchApply_GPCG()
137 } else if (rho > ls->ftol) { in TaoLineSearchApply_GPCG()
140 ls->step = (ls->step) / 2; in TaoLineSearchApply_GPCG()
145 if (ls->step <= ls->stepmin || ls->step >= ls->stepmax) { in TaoLineSearchApply_GPCG()
146 ls->reason = TAOLINESEARCH_HALTED_OTHER; in TaoLineSearchApply_GPCG()
147 …PetscCall(PetscInfo(ls, "Rounding errors may prevent further progress. May not be a step satisfyi… in TaoLineSearchApply_GPCG()
148 …PetscCall(PetscInfo(ls, "sufficient decrease and curvature conditions. Tolerances may be too small… in TaoLineSearchApply_GPCG()
151 if (ls->step == ls->stepmax) { in TaoLineSearchApply_GPCG()
152 PetscCall(PetscInfo(ls, "Step is at the upper bound, stepmax (%g)\n", (double)ls->stepmax)); in TaoLineSearchApply_GPCG()
153 ls->reason = TAOLINESEARCH_HALTED_UPPERBOUND; in TaoLineSearchApply_GPCG()
156 if (ls->step == ls->stepmin) { in TaoLineSearchApply_GPCG()
157 PetscCall(PetscInfo(ls, "Step is at the lower bound, stepmin (%g)\n", (double)ls->stepmin)); in TaoLineSearchApply_GPCG()
158 ls->reason = TAOLINESEARCH_HALTED_LOWERBOUND; in TaoLineSearchApply_GPCG()
161 if ((ls->nfeval + ls->nfgeval) >= ls->max_funcs) { in TaoLineSearchApply_GPCG()
162 …all(PetscInfo(ls, "Number of line search function evals (%" PetscInt_FMT ") > maximum (%" PetscInt… in TaoLineSearchApply_GPCG()
163 ls->reason = TAOLINESEARCH_HALTED_MAXFCN; in TaoLineSearchApply_GPCG()
166 if (neP->bracket && (ls->stepmax - ls->stepmin <= ls->rtol * ls->stepmax)) { in TaoLineSearchApply_GPCG()
167 …PetscCall(PetscInfo(ls, "Relative width of interval of uncertainty is at most rtol (%g)\n", (doubl… in TaoLineSearchApply_GPCG()
168 ls->reason = TAOLINESEARCH_HALTED_RTOL; in TaoLineSearchApply_GPCG()
172 …PetscCall(PetscInfo(ls, "%" PetscInt_FMT " function evals in line search, step = %g\n", ls->nfeval… in TaoLineSearchApply_GPCG()
175 if (ls->reason == TAOLINESEARCH_CONTINUE_ITERATING) ls->reason = TAOLINESEARCH_SUCCESS; in TaoLineSearchApply_GPCG()
176 if (!g_computed) PetscCall(TaoLineSearchComputeGradient(ls, x, g)); in TaoLineSearchApply_GPCG()
188 PETSC_EXTERN PetscErrorCode TaoLineSearchCreate_GPCG(TaoLineSearch ls) in TaoLineSearchCreate_GPCG() argument
193 ls->ftol = 0.05; in TaoLineSearchCreate_GPCG()
194 ls->rtol = 0.0; in TaoLineSearchCreate_GPCG()
195 ls->gtol = 0.0; in TaoLineSearchCreate_GPCG()
196 ls->stepmin = 1.0e-20; in TaoLineSearchCreate_GPCG()
197 ls->stepmax = 1.0e+20; in TaoLineSearchCreate_GPCG()
198 ls->nfeval = 0; in TaoLineSearchCreate_GPCG()
199 ls->max_funcs = 30; in TaoLineSearchCreate_GPCG()
200 ls->step = 1.0; in TaoLineSearchCreate_GPCG()
205 ls->data = (void *)neP; in TaoLineSearchCreate_GPCG()
207 ls->ops->setup = NULL; in TaoLineSearchCreate_GPCG()
208 ls->ops->reset = NULL; in TaoLineSearchCreate_GPCG()
209 ls->ops->apply = TaoLineSearchApply_GPCG; in TaoLineSearchCreate_GPCG()
210 ls->ops->view = TaoLineSearchView_GPCG; in TaoLineSearchCreate_GPCG()
211 ls->ops->destroy = TaoLineSearchDestroy_GPCG; in TaoLineSearchCreate_GPCG()
212 ls->ops->setfromoptions = NULL; in TaoLineSearchCreate_GPCG()
213 ls->ops->monitor = NULL; in TaoLineSearchCreate_GPCG()