Lines Matching defs:tao

9 + tao - the `Tao` context
16 PetscErrorCode TaoSetSolution(Tao tao, Vec x0)
19 PetscValidHeaderSpecific(tao, TAO_CLASSID, 1);
22 PetscCall(VecDestroy(&tao->solution));
23 tao->solution = x0;
27 PetscErrorCode TaoTestGradient(Tao tao, Vec x, Vec g1)
40 PetscObjectOptionsBegin((PetscObject)tao);
49 PetscCall(PetscObjectGetComm((PetscObject)tao, &comm));
52 PetscCall(PetscViewerASCIISetTab(viewer, ((PetscObject)tao)->tablevel));
69 PetscCall(TaoDefaultComputeGradient(tao, x, g2, NULL));
109 + tao - the `Tao` context
127 PetscErrorCode TaoComputeGradient(Tao tao, Vec X, Vec G)
132 PetscValidHeaderSpecific(tao, TAO_CLASSID, 1);
135 PetscCheckSameComm(tao, 1, X, 2);
136 PetscCheckSameComm(tao, 1, G, 3);
138 if (tao->ops->computegradient) {
139 PetscCall(PetscLogEventBegin(TAO_GradientEval, tao, X, G, NULL));
140 PetscCallBack("Tao callback gradient", (*tao->ops->computegradient)(tao, X, G, tao->user_gradP));
141 PetscCall(PetscLogEventEnd(TAO_GradientEval, tao, X, G, NULL));
142 tao->ngrads++;
143 } else if (tao->ops->computeobjectiveandgradient) {
144 PetscCall(PetscLogEventBegin(TAO_ObjGradEval, tao, X, G, NULL));
145 PetscCallBack("Tao callback objective/gradient", (*tao->ops->computeobjectiveandgradient)(tao, X, &dummy, G, tao->user_objgradP));
146 PetscCall(PetscLogEventEnd(TAO_ObjGradEval, tao, X, G, NULL));
147 tao->nfuncgrads++;
148 } else SETERRQ(PetscObjectComm((PetscObject)tao), PETSC_ERR_ARG_WRONGSTATE, "TaoSetGradient() has not been called");
151 PetscCall(TaoTestGradient(tao, X, G));
161 + tao - the `Tao` context
175 PetscErrorCode TaoComputeObjective(Tao tao, Vec X, PetscReal *f)
180 PetscValidHeaderSpecific(tao, TAO_CLASSID, 1);
182 PetscCheckSameComm(tao, 1, X, 2);
184 if (tao->ops->computeobjective) {
185 PetscCall(PetscLogEventBegin(TAO_ObjectiveEval, tao, X, NULL, NULL));
186 PetscCallBack("Tao callback objective", (*tao->ops->computeobjective)(tao, X, f, tao->user_objP));
187 PetscCall(PetscLogEventEnd(TAO_ObjectiveEval, tao, X, NULL, NULL));
188 tao->nfuncs++;
189 } else if (tao->ops->computeobjectiveandgradient) {
190 PetscCall(PetscInfo(tao, "Duplicating variable vector in order to call func/grad routine\n"));
192 PetscCall(PetscLogEventBegin(TAO_ObjGradEval, tao, X, NULL, NULL));
193 PetscCallBack("Tao callback objective/gradient", (*tao->ops->computeobjectiveandgradient)(tao, X, f, temp, tao->user_objgradP));
194 PetscCall(PetscLogEventEnd(TAO_ObjGradEval, tao, X, NULL, NULL));
196 tao->nfuncgrads++;
197 } else SETERRQ(PetscObjectComm((PetscObject)tao), PETSC_ERR_ARG_WRONGSTATE, "TaoSetObjective() has not been called");
198 PetscCall(PetscInfo(tao, "TAO Function evaluation: %20.19e\n", (double)(*f)));
209 + tao - the `Tao` context
224 PetscErrorCode TaoComputeObjectiveAndGradient(Tao tao, Vec X, PetscReal *f, Vec G)
227 PetscValidHeaderSpecific(tao, TAO_CLASSID, 1);
230 PetscCheckSameComm(tao, 1, X, 2);
231 PetscCheckSameComm(tao, 1, G, 4);
233 if (tao->ops->computeobjectiveandgradient) {
234 PetscCall(PetscLogEventBegin(TAO_ObjGradEval, tao, X, G, NULL));
235 if (tao->ops->computegradient == TaoDefaultComputeGradient) {
236 PetscCall(TaoComputeObjective(tao, X, f));
237 PetscCall(TaoDefaultComputeGradient(tao, X, G, NULL));
238 } else PetscCallBack("Tao callback objective/gradient", (*tao->ops->computeobjectiveandgradient)(tao, X, f, G, tao->user_objgradP));
239 PetscCall(PetscLogEventEnd(TAO_ObjGradEval, tao, X, G, NULL));
240 tao->nfuncgrads++;
241 } else if (tao->ops->computeobjective && tao->ops->computegradient) {
242 PetscCall(PetscLogEventBegin(TAO_ObjectiveEval, tao, X, NULL, NULL));
243 PetscCallBack("Tao callback objective", (*tao->ops->computeobjective)(tao, X, f, tao->user_objP));
244 PetscCall(PetscLogEventEnd(TAO_ObjectiveEval, tao, X, NULL, NULL));
245 tao->nfuncs++;
246 PetscCall(PetscLogEventBegin(TAO_GradientEval, tao, X, G, NULL));
247 PetscCallBack("Tao callback gradient", (*tao->ops->computegradient)(tao, X, G, tao->user_gradP));
248 PetscCall(PetscLogEventEnd(TAO_GradientEval, tao, X, G, NULL));
249 tao->ngrads++;
250 } else SETERRQ(PetscObjectComm((PetscObject)tao), PETSC_ERR_ARG_WRONGSTATE, "TaoSetObjective() or TaoSetGradient() not set");
251 PetscCall(PetscInfo(tao, "TAO Function evaluation: %20.19e\n", (double)(*f)));
254 PetscCall(TaoTestGradient(tao, X, G));
264 + tao - the `Tao` context
270 + tao - the optimizer
279 PetscErrorCode TaoSetObjective(Tao tao, PetscErrorCode (*func)(Tao tao, Vec x, PetscReal *f, PetscCtx ctx), PetscCtx ctx)
282 PetscValidHeaderSpecific(tao, TAO_CLASSID, 1);
283 if (ctx) tao->user_objP = ctx;
284 if (func) tao->ops->computeobjective = func;
294 . tao - the `Tao` context
301 + tao - the optimizer
310 PetscErrorCode TaoGetObjective(Tao tao, PetscErrorCode (**func)(Tao tao, Vec x, PetscReal *f, PetscCtx ctx), PetscCtxRt ctx)
313 PetscValidHeaderSpecific(tao, TAO_CLASSID, 1);
314 if (func) *func = tao->ops->computeobjective;
315 if (ctx) *(void **)ctx = tao->user_objP;
325 + tao - the `Tao` context
332 + tao - the optimizer
341 PetscErrorCode TaoSetResidualRoutine(Tao tao, Vec res, PetscErrorCode (*func)(Tao tao, Vec x, Vec res, PetscCtx ctx), PetscCtx ctx)
344 PetscValidHeaderSpecific(tao, TAO_CLASSID, 1);
347 if (tao->ls_res) PetscCall(VecDestroy(&tao->ls_res));
348 tao->ls_res = res;
349 tao->user_lsresP = ctx;
350 tao->ops->computeresidual = func;
360 + tao - the `Tao` context
377 PetscErrorCode TaoSetResidualWeights(Tao tao, Vec sigma_v, PetscInt n, PetscInt *rows, PetscInt *cols, PetscReal *vals)
382 PetscValidHeaderSpecific(tao, TAO_CLASSID, 1);
385 PetscCall(VecDestroy(&tao->res_weights_v));
386 tao->res_weights_v = sigma_v;
388 PetscCall(PetscFree(tao->res_weights_rows));
389 PetscCall(PetscFree(tao->res_weights_cols));
390 PetscCall(PetscFree(tao->res_weights_w));
391 PetscCall(PetscMalloc1(n, &tao->res_weights_rows));
392 PetscCall(PetscMalloc1(n, &tao->res_weights_cols));
393 PetscCall(PetscMalloc1(n, &tao->res_weights_w));
394 tao->res_weights_n = n;
396 tao->res_weights_rows[i] = rows[i];
397 tao->res_weights_cols[i] = cols[i];
398 tao->res_weights_w[i] = vals[i];
401 tao->res_weights_n = 0;
402 tao->res_weights_rows = NULL;
403 tao->res_weights_cols = NULL;
414 + tao - the `Tao` context
428 PetscErrorCode TaoComputeResidual(Tao tao, Vec X, Vec F)
431 PetscValidHeaderSpecific(tao, TAO_CLASSID, 1);
434 PetscCheckSameComm(tao, 1, X, 2);
435 PetscCheckSameComm(tao, 1, F, 3);
436 PetscCheck(tao->ops->computeresidual, PetscObjectComm((PetscObject)tao), PETSC_ERR_ARG_WRONGSTATE, "TaoSetResidualRoutine() has not been called");
437 PetscCall(PetscLogEventBegin(TAO_ObjectiveEval, tao, X, NULL, NULL));
438 PetscCallBack("Tao callback least-squares residual", (*tao->ops->computeresidual)(tao, X, F, tao->user_lsresP));
439 PetscCall(PetscLogEventEnd(TAO_ObjectiveEval, tao, X, NULL, NULL));
440 tao->nfuncs++;
441 PetscCall(PetscInfo(tao, "TAO least-squares residual evaluation.\n"));
451 + tao - the `Tao` context
458 + tao - the optimization solver
467 PetscErrorCode TaoSetGradient(Tao tao, Vec g, PetscErrorCode (*func)(Tao tao, Vec x, Vec g, PetscCtx ctx), PetscCtx ctx)
470 PetscValidHeaderSpecific(tao, TAO_CLASSID, 1);
473 PetscCheckSameComm(tao, 1, g, 2);
475 PetscCall(VecDestroy(&tao->gradient));
476 tao->gradient = g;
478 if (func) tao->ops->computegradient = func;
479 if (ctx) tao->user_gradP = ctx;
489 . tao - the `Tao` context
497 + tao - the optimizer
506 PetscErrorCode TaoGetGradient(Tao tao, Vec *g, PetscErrorCode (**func)(Tao tao, Vec x, Vec g, PetscCtx ctx), PetscCtxRt ctx)
509 PetscValidHeaderSpecific(tao, TAO_CLASSID, 1);
510 if (g) *g = tao->gradient;
511 if (func) *func = tao->ops->computegradient;
512 if (ctx) *(void **)ctx = tao->user_gradP;
522 + tao - the `Tao` context
529 + tao - the optimization object
542 PetscErrorCode TaoSetObjectiveAndGradient(Tao tao, Vec g, PetscErrorCode (*func)(Tao tao, Vec x, PetscReal *f, Vec g, PetscCtx ctx), PetscCtx ctx)
545 PetscValidHeaderSpecific(tao, TAO_CLASSID, 1);
548 PetscCheckSameComm(tao, 1, g, 2);
550 PetscCall(VecDestroy(&tao->gradient));
551 tao->gradient = g;
553 if (ctx) tao->user_objgradP = ctx;
554 if (func) tao->ops->computeobjectiveandgradient = func;
564 . tao - the `Tao` context
572 + tao - the optimizer
582 PetscErrorCode TaoGetObjectiveAndGradient(Tao tao, Vec *g, PetscErrorCode (**func)(Tao tao, Vec x, PetscReal *f, Vec g, PetscCtx ctx), PetscCtxRt ctx)
585 PetscValidHeaderSpecific(tao, TAO_CLASSID, 1);
586 if (g) *g = tao->gradient;
587 if (func) *func = tao->ops->computeobjectiveandgradient;
588 if (ctx) *(void **)ctx = tao->user_objgradP;
601 . tao - the `Tao` context
610 PetscErrorCode TaoIsObjectiveDefined(Tao tao, PetscBool *flg)
613 PetscValidHeaderSpecific(tao, TAO_CLASSID, 1);
614 if (tao->ops->computeobjective == NULL) *flg = PETSC_FALSE;
628 . tao - the `Tao` context
637 PetscErrorCode TaoIsGradientDefined(Tao tao, PetscBool *flg)
640 PetscValidHeaderSpecific(tao, TAO_CLASSID, 1);
641 if (tao->ops->computegradient == NULL) *flg = PETSC_FALSE;
655 . tao - the `Tao` context
664 PetscErrorCode TaoIsObjectiveAndGradientDefined(Tao tao, PetscBool *flg)
667 PetscValidHeaderSpecific(tao, TAO_CLASSID, 1);
668 if (tao->ops->computeobjectiveandgradient == NULL) *flg = PETSC_FALSE;