xref: /petsc/src/ml/regressor/impls/linear/linearimpl.h (revision c12c126234ed623246a63bfa78c9f75a3aa00323)
1 #pragma once
2 #include <petsc/private/regressorimpl.h>
3 #include <petscksp.h>
4 #include <petsctao.h>
5 
6 /* We define this header, since it serves as a "base" for all linear models. */
7 #define REGRESSOR_LINEAR_HEADER \
8   PetscRegressorLinearType type; \
9   /* Parameters of the fitted regression model */ \
10   Vec         coefficients; \
11   PetscScalar intercept; \
12 \
13   Mat X;        /* Operator of the linear model; often the training data matrix, but might be a MATCOMPOSITE */ \
14   Mat C;        /* Centering matrix */ \
15   Vec rhs;      /* Right-hand side of the linear model; often the target vector, but may be the mean-centered version */ \
16   Vec residual; /* Residual for our model, or the loss vector */ \
17   /* Various options */ \
18   PetscBool fit_intercept; /* Calculate intercept ("bias" or "offset") if true. Assume centered data if false. */ \
19   PetscBool use_ksp        /* Use KSP for the model-fitting problem; otherwise we will use TAO. */
20 
21 typedef struct {
22   REGRESSOR_LINEAR_HEADER;
23 
24   PetscInt ksp_its, ksp_tot_its;
25   KSP      ksp;
26   Mat      XtX; /* Normal matrix formed from X */
27 } PetscRegressor_Linear;
28