Module for linear algebra procedures. Uses LAPACK routines (through stdlib).
Impure wrapper function for f_lin_mahalanobis_core.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=wp), | intent(in) | :: | x(:) |
input vector 1 |
||
| real(kind=wp), | intent(in) | :: | y(:) |
input vector 2 |
||
| real(kind=wp), | intent(in), | optional | :: | cov(:,:) |
covariance matrix |
Mahalanobis distance
Compute Mahalanobis distance between vectors x and y using covariance matrix cov if provided; otherwise estimate covariance from the two-sample dataset formed by x and y. NOTE: check if cov matrix is positive definite.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=wp), | intent(in) | :: | x(:) |
input vector 1 (features) |
||
| real(kind=wp), | intent(in) | :: | y(:) |
input vector 2 (features) |
||
| real(kind=wp), | intent(in), | optional | :: | cov(:,:) |
covariance matrix (m,m) |
Mahalanobis distance
Empirical Orthogonal Function (EOF) analysis
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=wp), | intent(in) | :: | x(nd,nv) |
input data |
||
| integer(kind=i4), | intent(in) | :: | nd |
number of rows |
||
| integer(kind=i4), | intent(in) | :: | nv |
number of columns |
||
| real(kind=wp), | intent(out) | :: | pc(nd,nv) |
principal components |
||
| real(kind=wp), | intent(out) | :: | eof(nv,nv) |
EOFs/eigenvectors (unweighted) |
||
| real(kind=wp), | intent(out) | :: | ew(nv) |
eigenvalues |
||
| integer(kind=i4), | intent(in), | optional | :: | opt |
0 = covariance, 1 = correlation |
|
| real(kind=wp), | intent(in), | optional | :: | wt(nv) |
optional weights (default = 1.0/n) |
|
| real(kind=wp), | intent(out), | optional | :: | r2(nv) |
explained variance (fraction) |
|
| real(kind=wp), | intent(out), | optional | :: | eof_scaled(nv,nv) |
EOFs/eigenvectors scaled for plotting |
2-class multivariate Linear Discriminant Analysis (LDA)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=wp), | intent(in) | :: | x(nd,nv,nc) |
input data (nd samples × nv variables × nc classes) |
||
| integer(kind=i4), | intent(in) | :: | nd |
number of datapoints per class |
||
| integer(kind=i4), | intent(in) | :: | nv |
number of variables |
||
| integer(kind=i4), | intent(in) | :: | nc |
number of classes (must be 2) |
||
| real(kind=wp), | intent(out) | :: | sa(nv) |
standardised discriminant coefficients |
||
| real(kind=wp), | intent(out) | :: | g |
discriminant criterion |
||
| real(kind=wp), | intent(out) | :: | score |
classification score |
||
| real(kind=wp), | intent(out), | optional | :: | mh |
Mahalanobis distance |
Multiple Linear Ordinary Least Squares (OLS) Regression with intercept. NOTE: OLS could be wrapper for ridge (with lambda = 0 or presence checks if mande an optional argument). However, it would increase computation slightly and make code less readable. OLS is often used in teaching and therefore, an easily readable standalone is kept.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=wp), | intent(in) | :: | x(nd,nv) |
predictor data matrix (no intercept column) |
||
| real(kind=wp), | intent(in) | :: | y(nd) |
response vector |
||
| integer(kind=i4), | intent(in) | :: | nd |
number of datapoints |
||
| integer(kind=i4), | intent(in) | :: | nv |
number of predictors (excluding intercept) |
||
| real(kind=wp), | intent(out) | :: | b0 |
intercept coefficient |
||
| real(kind=wp), | intent(out) | :: | b(nv) |
predictor coefficients |
||
| real(kind=wp), | intent(out) | :: | r2 |
coefficient of determination R² |
||
| real(kind=wp), | intent(out), | optional | :: | y_hat(nd) |
predicted y values |
|
| real(kind=wp), | intent(out), | optional | :: | se(nv) |
standard errors of predictor coefficients |
|
| real(kind=wp), | intent(out), | optional | :: | cov_b(nv,nv) |
covariance matrix of predictor coefficients |
Principal Component Analysis (PCA).
It is a special (simplified) case of EOF analysis offered as a separate
procedure for clarity/familiarity. It calls s_lin_eof with equal weights.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=wp), | intent(in) | :: | x(nd,nv) |
input data |
||
| integer(kind=i4), | intent(in) | :: | nd |
number of rows |
||
| integer(kind=i4), | intent(in) | :: | nv |
number of columns |
||
| real(kind=wp), | intent(out) | :: | pc(nd,nv) |
principal components |
||
| real(kind=wp), | intent(out) | :: | ev(nv,nv) |
eigenvectors (unweighted) |
||
| real(kind=wp), | intent(out) | :: | ew(nv) |
eigenvalues |
||
| real(kind=wp), | intent(out), | optional | :: | r2(nv) |
explained variance (fraction) |
Multiple Linear Ridge Regression (λ >= 0) with intercept.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=wp), | intent(in) | :: | x(nd,nv) |
predictor data matrix (no intercept column) |
||
| real(kind=wp), | intent(in) | :: | y(nd) |
response vector |
||
| integer(kind=i4), | intent(in) | :: | nd |
number of datapoints |
||
| integer(kind=i4), | intent(in) | :: | nv |
number of predictors (excluding intercept) |
||
| real(kind=wp), | intent(in) | :: | lambda |
ridge penalty parameter (≥ 0, non-optional) |
||
| real(kind=wp), | intent(out) | :: | b0 |
intercept coefficient |
||
| real(kind=wp), | intent(out) | :: | b(nv) |
predictor coefficients |
||
| real(kind=wp), | intent(out) | :: | r2 |
coefficient of determination R² |
||
| real(kind=wp), | intent(out), | optional | :: | y_hat(nd) |
predicted y values |
|
| real(kind=wp), | intent(out), | optional | :: | se(nv) |
standard errors of predictor coefficients |
|
| real(kind=wp), | intent(out), | optional | :: | cov_b(nv,nv) |
covariance matrix of predictor coefficients |