Skip to main content
`Ctrl`+`K`

# PetscRegressorLinearSetUseKSP

Set a flag to indicate that a `KSP` object, instead of a `Tao` one, should be used to fit the linear regressor

## Synopsis

    #include "petscregressor.h"
    PetscErrorCode PetscRegressorLinearSetUseKSP(PetscRegressor regressor, PetscBool flg)

Logically Collective

## Input Parameters

- regressor - the `PetscRegressor` context

- flg - `PETSC_TRUE` to use a `KSP`, `PETSC_FALSE` to use a `Tao` object (default is false)

## Options Database Key

- regressor_linear_use_ksp <true,false> - use `KSP`

## Notes

`KSPLSQR` with no preconditioner is used to solve the normal equations by default.

For sequential `MATSEQAIJ` sparse matrices QR factorization a `PCType` of `PCQR` can be used to solve the least-squares system with a `MatSolverType` of `MATSOLVERSPQR`, using, for example,

      -ksp_type none -pc_type qr -pc_factor_mat_solver_type sp

if centering, `PetscRegressorLinearSetFitIntercept()`, is not used.

## Developer Notes

It should be possible to use Cholesky (and any other preconditioners) to solve the normal equations.

It should be possible to use QR if centering is used. See ml/regressor/ex1.c and ex2.c

It should be possible to use dense SVD `PCSVD` and dense qr directly on the rectangular matrix to solve the least squares problem.

Adding the above support seems to require a refactorization of how least squares problems are solved with PETSc in `KSPLSQR`

## See Also

`PetscRegressor`, `PetscRegressorLinearGetKSP()`, `KSPLSQR`, `PCQR`, `MATSOLVERSPQR`, `MatSolverType`, `MATSEQDENSE`, `PCSVD`

## Level

intermediate

## Location

src/ml/regressor/impls/linear/linear.c

## Implementations

PetscRegressorLinearSetUseKSP_Linear() in src/ml/regressor/impls/linear/linear.c

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