TaoTermCreateHalfL2Squared — PETSc 3.25.0 documentation

Skip to main content
`Ctrl`+`K`

# TaoTermCreateHalfL2Squared

Create a `TaoTerm` for the objective term \(\tfrac{1}{2}\|x - p\|_2^2\), for solution \(x\) and parameters \(p\).

## Synopsis

    #include "petsctao.h"
    PetscErrorCode TaoTermCreateHalfL2Squared(MPI_Comm comm, PetscInt n, PetscInt N, TaoTerm *term)

Collective

## Input Parameters

- comm - the MPI communicator where the `TaoTerm` will be computed

- n - the local size of the \(x\) and \(p\) vectors (or `PETSC_DECIDE`)

- N - the global size of the \(x\) and \(p\) vectors (or `PETSC_DECIDE`)

## Output Parameter

- term - the `TaoTerm`

## Note

If you would like to add a Tikhonov regularization term \(\alpha \tfrac{1}{2}\|x\|_2^2\) to the objective function of a `Tao`, do the following:

      VecGetSizes(x, &n, &N);
      TaoTermCreateHalfL2Squared(PetscObjectComm((PetscObject)x), n, N, &term);
      TaoAddTerm(tao, "reg_", alpha, term, NULL, NULL);
      TaoTermDestroy(&term);

If you would like to add a biased regularization term \(\alpha \tfrac{1}{2}\|x - p \|_2^2\), do the same but pass `p` as the parameters of the term:

      TaoAddTerm(tao, "reg_", alpha, term, p, NULL);

## See Also

TaoTerm: composable objective function terms, `TaoTerm`, `TAOTERMHALFL2SQUARED`, `TaoTermCreateL1()`, `TaoTermCreateQuadratic()`

## Level

beginner

## Location

src/tao/term/impls/halfl2squared/taotermhalfl2squared.c

## Examples

src/tao/unconstrained/tutorials/elastic_net_regularization.c

Index of all TaoTerm routines
Table of Contents for all manual pages
Index of all manual pages