xref: /petsc/include/petscregressor.h (revision 789736e13dc7600624280f2f1d112db076e5d354)
134b254c5SRichard Tran Mills #pragma once
234b254c5SRichard Tran Mills 
334b254c5SRichard Tran Mills #include <petsctao.h>
434b254c5SRichard Tran Mills 
534b254c5SRichard Tran Mills /* MANSEC = ML */
634b254c5SRichard Tran Mills /* SUBMANSEC = PetscRegressor */
734b254c5SRichard Tran Mills 
834b254c5SRichard Tran Mills /*S
934b254c5SRichard Tran Mills    PetscRegressor - Abstract PETSc object that manages regression and classification problems
1034b254c5SRichard Tran Mills 
1134b254c5SRichard Tran Mills    Level: beginner
1234b254c5SRichard Tran Mills 
13*789736e1SBarry Smith    Notes:
14*789736e1SBarry Smith    For linear problems `PetscRegressor` supports ordinary least squares, lasso, and ridge regression using the `PetscRegressorType` of `PETSCREGRESSORLINEAR`
15*789736e1SBarry Smith    and `PetscRegressorLinearType` of `REGRESSOR_LINEAR_OLS`, `REGRESSOR_LINEAR_LASSO`, and `REGRESSOR_LINEAR_RIDGE`.
16*789736e1SBarry Smith 
1734b254c5SRichard Tran Mills    We have slightly abused the term "regressor" in the naming of this component of PETSc.
1834b254c5SRichard Tran Mills    Statisticians would say that we are doing "regression", and a "regressor", in this context, strictly means an
1934b254c5SRichard Tran Mills    independent (or "predictor") variable in the regression analysis. However, "regressor" has taken on an informal
2034b254c5SRichard Tran Mills    meaning in the machine-learning community of something along the lines of "algorithm or implementation used to fit
2134b254c5SRichard Tran Mills    a regression model". Examples are `MLPRegressor` (multi-layer perceptron regressor) or `RandomForestRegressor`
2234b254c5SRichard Tran Mills    from the scikit-learn toolkit (which is itself not consistent about the use of the term "regressor", since it has a
2334b254c5SRichard Tran Mills    `LinearRegression` component instead of a `LinearRegressor` component).
2434b254c5SRichard Tran Mills 
25*789736e1SBarry Smith .seealso: `PetscRegressorCreate()`, `PetscRegressorLinearType`, `PetscRegressorSetType()`, `PetscRegressorType`, `PetscRegressorDestroy()`,
26*789736e1SBarry Smith           `PETSCREGRESSORLINEAR`, `PetscRegressorLinearType`, `REGRESSOR_LINEAR_OLS`, `REGRESSOR_LINEAR_LASSO`, `REGRESSOR_LINEAR_RIDGE`.
2734b254c5SRichard Tran Mills S*/
2834b254c5SRichard Tran Mills typedef struct _p_PetscRegressor *PetscRegressor;
2934b254c5SRichard Tran Mills 
3034b254c5SRichard Tran Mills /*J
3134b254c5SRichard Tran Mills   PetscRegressorType - String with the name of a PETSc regression method.
3234b254c5SRichard Tran Mills 
3334b254c5SRichard Tran Mills   Level: beginner
3434b254c5SRichard Tran Mills 
35*789736e1SBarry Smith .seealso: [](ch_regressor), `PetscRegressorSetType()`, `PetscRegressor`, `PetscRegressorRegister()`, `PetscRegressorCreate()`, `PetscRegressorSetFromOptions()`,
36*789736e1SBarry Smith           `PETSCREGRESSORLINEAR`
3734b254c5SRichard Tran Mills J*/
3834b254c5SRichard Tran Mills typedef const char *PetscRegressorType;
3934b254c5SRichard Tran Mills #define PETSCREGRESSORLINEAR "linear"
4034b254c5SRichard Tran Mills 
4134b254c5SRichard Tran Mills /*E
4234b254c5SRichard Tran Mills   PetscRegressorLinearType - Type of linear regression
4334b254c5SRichard Tran Mills 
4434b254c5SRichard Tran Mills   Values:
45*789736e1SBarry Smith +  `REGRESSOR_LINEAR_OLS`    - ordinary least squares
4634b254c5SRichard Tran Mills .  `REGRESSOR_LINEAR_LASSO`  - lasso
4734b254c5SRichard Tran Mills -  `REGRESSOR_LINEAR_RIDGE`  - ridge
4834b254c5SRichard Tran Mills 
4934b254c5SRichard Tran Mills   Level: advanced
5034b254c5SRichard Tran Mills 
5134b254c5SRichard Tran Mills .seealso: `PetscRegressor`, `PETSCREGRESSORLINEAR`
5234b254c5SRichard Tran Mills E*/
5334b254c5SRichard Tran Mills 
5434b254c5SRichard Tran Mills typedef enum {
5534b254c5SRichard Tran Mills   REGRESSOR_LINEAR_OLS,
5634b254c5SRichard Tran Mills   REGRESSOR_LINEAR_LASSO,
5734b254c5SRichard Tran Mills   REGRESSOR_LINEAR_RIDGE
5834b254c5SRichard Tran Mills } PetscRegressorLinearType;
5934b254c5SRichard Tran Mills PETSC_EXTERN const char *const PetscRegressorLinearTypes[];
6034b254c5SRichard Tran Mills 
6134b254c5SRichard Tran Mills PETSC_EXTERN PetscFunctionList PetscRegressorList;
6234b254c5SRichard Tran Mills PETSC_EXTERN PetscClassId      PETSCREGRESSOR_CLASSID;
6334b254c5SRichard Tran Mills 
6434b254c5SRichard Tran Mills PETSC_EXTERN PetscErrorCode PetscRegressorInitializePackage(void);
6534b254c5SRichard Tran Mills PETSC_EXTERN PetscErrorCode PetscRegressorFinalizePackage(void);
6634b254c5SRichard Tran Mills PETSC_EXTERN PetscErrorCode PetscRegressorRegister(const char[], PetscErrorCode (*)(PetscRegressor));
6734b254c5SRichard Tran Mills 
6834b254c5SRichard Tran Mills PETSC_EXTERN PetscErrorCode PetscRegressorCreate(MPI_Comm, PetscRegressor *);
6934b254c5SRichard Tran Mills PETSC_EXTERN PetscErrorCode PetscRegressorReset(PetscRegressor);
7034b254c5SRichard Tran Mills PETSC_EXTERN PetscErrorCode PetscRegressorDestroy(PetscRegressor *);
7134b254c5SRichard Tran Mills 
7234b254c5SRichard Tran Mills PETSC_EXTERN PetscErrorCode PetscRegressorSetOptionsPrefix(PetscRegressor, const char[]);
7334b254c5SRichard Tran Mills PETSC_EXTERN PetscErrorCode PetscRegressorAppendOptionsPrefix(PetscRegressor, const char[]);
7434b254c5SRichard Tran Mills PETSC_EXTERN PetscErrorCode PetscRegressorGetOptionsPrefix(PetscRegressor, const char *[]);
7534b254c5SRichard Tran Mills 
7634b254c5SRichard Tran Mills PETSC_EXTERN PetscErrorCode PetscRegressorSetType(PetscRegressor, PetscRegressorType);
7734b254c5SRichard Tran Mills PETSC_EXTERN PetscErrorCode PetscRegressorGetType(PetscRegressor, PetscRegressorType *);
7834b254c5SRichard Tran Mills PETSC_EXTERN PetscErrorCode PetscRegressorSetRegularizerWeight(PetscRegressor, PetscReal);
7934b254c5SRichard Tran Mills PETSC_EXTERN PetscErrorCode PetscRegressorSetUp(PetscRegressor);
8034b254c5SRichard Tran Mills PETSC_EXTERN PetscErrorCode PetscRegressorSetFromOptions(PetscRegressor);
8134b254c5SRichard Tran Mills 
8234b254c5SRichard Tran Mills PETSC_EXTERN PetscErrorCode PetscRegressorView(PetscRegressor, PetscViewer);
8334b254c5SRichard Tran Mills PETSC_EXTERN PetscErrorCode PetscRegressorViewFromOptions(PetscRegressor, PetscObject, const char[]);
8434b254c5SRichard Tran Mills 
8534b254c5SRichard Tran Mills PETSC_EXTERN PetscErrorCode PetscRegressorFit(PetscRegressor, Mat, Vec);
8634b254c5SRichard Tran Mills PETSC_EXTERN PetscErrorCode PetscRegressorPredict(PetscRegressor, Mat, Vec);
8734b254c5SRichard Tran Mills PETSC_EXTERN PetscErrorCode PetscRegressorGetTao(PetscRegressor, Tao *);
8834b254c5SRichard Tran Mills 
8934b254c5SRichard Tran Mills PETSC_EXTERN PetscErrorCode PetscRegressorLinearSetFitIntercept(PetscRegressor, PetscBool);
9034b254c5SRichard Tran Mills PETSC_EXTERN PetscErrorCode PetscRegressorLinearSetUseKSP(PetscRegressor, PetscBool);
9134b254c5SRichard Tran Mills PETSC_EXTERN PetscErrorCode PetscRegressorLinearGetKSP(PetscRegressor, KSP *);
9234b254c5SRichard Tran Mills PETSC_EXTERN PetscErrorCode PetscRegressorLinearGetCoefficients(PetscRegressor, Vec *);
9334b254c5SRichard Tran Mills PETSC_EXTERN PetscErrorCode PetscRegressorLinearGetIntercept(PetscRegressor, PetscScalar *);
9434b254c5SRichard Tran Mills PETSC_EXTERN PetscErrorCode PetscRegressorLinearSetType(PetscRegressor, PetscRegressorLinearType);
9534b254c5SRichard Tran Mills PETSC_EXTERN PetscErrorCode PetscRegressorLinearGetType(PetscRegressor, PetscRegressorLinearType *);
96