This is a note of Linear Discriminant Analysis (LDA) and an original Regularized Matrix Discriminant Analysis (R-MDA) method proposed by Jie Su et al, 2018. Both methods are suitable for efficient multiclass classification, while the latter is a state-of-the-art version of the classical LDA method s.t. data in matrix forms can be classified without destroying the original structure.

# A Sketch of LDA

The plain idea behind Discriminant Analysis is to find the optimal partition (or projection, for higher-dimensional problems) s.t. entities within the same class are distributed as compactly as possible and entities between classes are distributed as sparsely as possible. To derive closed-form solutions we have various conditions on the covariance matrices of the input data. When we assume covariances $\boldsymbol{\Sigma}\_k$ are equal for all classes $k\in\{1,2,\ldots,K\}$, we're following the framework of Linear Discriminant Analysis (LDA).

As shown above, when we consider a 2-dimensional binary classification problem, the LDA is equivalently finding the optimal direction vector $\boldsymbol{w}$ s.t. the ratio of $\boldsymbol{w}^T\boldsymbol{S}\_b\boldsymbol{w}$ (sum of between-class covariances of the projections) and $\boldsymbol{w}^T\boldsymbol{S}\_w\boldsymbol{w}$ (sum of within-class covariances of the projections) is maximized. Specifically, we define

$\boldsymbol{S}_b = (\boldsymbol{\mu}_0 - \boldsymbol{\mu}_1)^T(\boldsymbol{\mu}_0 - \boldsymbol{\mu}_1)$

and

$\boldsymbol{S}_w = \sum_{\boldsymbol{x}\in X_0}(\boldsymbol{x} - \boldsymbol{\mu}_0)^T(\boldsymbol{x} - \boldsymbol{\mu}_0) + \sum_{\boldsymbol{x}\in X_1}(\boldsymbol{x} - \boldsymbol{\mu}_1)^T(\boldsymbol{x} - \boldsymbol{\mu}_1).$

Therefore, the objective of this maximization problem is

$J = \frac{\boldsymbol{w}^T\boldsymbol{S}_b\boldsymbol{w}}{\boldsymbol{w}^T\boldsymbol{S}_w\boldsymbol{w}}$

which is also called the generalized Rayleigh quotiet.

The homogenous objective can be equivalently written into

\begin{align} \min_{\boldsymbol{w}}\quad &-\boldsymbol{w}^T\boldsymbol{S}_b\boldsymbol{w}\\\\ \text{s.t.}\quad &\boldsymbol{w}^T\boldsymbol{S}_w\boldsymbol{w} = 1 \end{align}

which, by using the method of Langrange multipliers, gives solution

$\boldsymbol{w} = \boldsymbol{S}_w^{-1}(\boldsymbol{\mu}_0 - \boldsymbol{\mu}_1)$

and the final prediction for new data $\boldsymbol{x}$ is based on the scale of $\boldsymbol{w}^T\boldsymbol{x}$.

For multiclass classification, the solution is similar. Here we propose the score function below without derivation:

$\delta_k = \boldsymbol{x}^T\boldsymbol{\Sigma}^{-1}\boldsymbol{\mu}_k - \frac{1}{2}\boldsymbol{\mu}_k^T\boldsymbol{\Sigma}^{-1}\boldsymbol{\mu}_k + \log\pi_k$

where $\boldsymbol{\mu}\_k$ is the sample mean of all data within class $k$, and $\pi_k$ is the percentage of all data that is of this class. By comparing these $k$ scores we determine the best prediction with the highest value.

# Codes of LDA

Now we define a new class called LDA with a predict (in fact also predict_prob) method.

Then we define three classes of 2D input $\boldsymbol{X}$ and pass it to the classifier. Original as well as the predicted distributions are plotted with accuracy printed below.

Training accuracy: 95.67%

# A Sketch of R-MDA

For data with inherent matrix forms like electroencephalogram (EEG) data introduced in Jie Su (2018), the classical LDA is not the most appropriate solution since it forcibly requires vector input. To use LDA for classification on such datasets we have to vectorize the matrices and potentially losing some critical structural information. Authors of this paper invented this new method called Regularized Matrix Discriminant Analysis (R-MDA) that naturally takes matric input in analysis. Furthermore, noticing that inversing large matrix $\boldsymbol{S}_w$ in high dimensions can be computationally burdonsome, they adopted the Alternating Direction Method of Multipliers (ADMM) to iteratively optimize the objective instead of the widely-used Singular Valur Decomposition (SVD). A graphical representation of the R-MDA compared with LDA is as follows.

The algorithm is implemented below. Notice here I skipped the Gradient Descent (GD) approach in the minimization during iterations and opt for the minimize function in scipy.optimize. I did so to make the structure simpler without hurting the understanding of the whole algorithm. For more detailed illustration please resort to the original paper.

# Codes of R-MDA

Again we first define the class RMDA. The predict method now takes a matrix.

Then we train the model and print the final accuracy.

Optimization converged successfully.
Training accuracy: 87.00%

Further analysis and debugging should be expected. Any correction in comments is also welcomed. 😇

# References

• Su, Jie, Linbo Qing, Xiaohai He, Hang Zhang, Jing Zhou, and Yonghong Peng. "A New Regularized Matrix Discriminant Analysis (R-MDA) Enabled Human-Centered EEG Monitoring Systems." IEEE Access 6 (2018): 13911-13920.
• Friedman, Jerome, Trevor Hastie, and Robert Tibshirani. The elements of statistical learning. Vol. 1. New York: Springer series in statistics, 2001.