Skip to content

Commit 9a71a91

Browse files
committed
Written MATLAB code
1 parent 798b936 commit 9a71a91

File tree

6 files changed

+89
-8
lines changed

6 files changed

+89
-8
lines changed

Presentation/Presentation.pdf

41.4 KB
Binary file not shown.

Presentation/Presentation.tex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
\usecolortheme{beaver}
44
\usepackage{amsmath}
55
\usepackage{ragged2e}
6+
\usepackage{listings}
7+
\usepackage{fancyvrb}
8+
\usepackage{adjustbox}
69
\justifying
710

811
\title[Implementation of the PLS algorithm]{Implementation in MATLAB of the Partial Least Squares algorithm for classification}

Presentation/Presentation.vrb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
\begin{Verbatim}[tabsize=4, commandchars=\\\{\}, frame=bottomline]
2+
\textcolor{green}{% calculation of W, P, T and B2}
3+
W(:, j) = w;
4+
P(:, j) = p;
5+
T(:, j) = t;
6+
B2 = W*(P'*W)^-1*(T'*T)^-1*T'*Y;
7+
\textcolor{blue}{end}
8+
Y_hat = X*B2; \textcolor{green}{% computation of predictions}
9+
\end{Verbatim}
10+
For each row of \verb|Y_hat| the fault class is chosen by assigning $1$ to the column whose value si greater than that of the others, $0$ otherwise. Moreover, to increase the performances of PLS it is necessary \textbf{normalize} both $X$ and $Y$ before running the algorithm.
11+

Presentation/Sections/Case study.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
\section{Fault detection and diagnosis on steel plates}
1+
\section{Fault detection and isolation on steel plates}
22

33
\begin{frame}
44
TO DO

Presentation/Sections/Introduction.tex

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,18 @@ \section{Introduction}
1414
\begin{frame}
1515
\frametitle{Popular application of PLS}
1616
This technique is often used in \textbf{fault detection} and \textbf{isolation}. With PLS is possible to treat both regression and classification problems. The matrix $X$ always contains the process variables (e.g. diameter and thickness of a gasket), while the matrix $Y$ only (quantitative) quality variables (e.g. its mechanical seal) in the regression case, whereas in pattern classification the predicted variables are dummy variables ($1$ or $0$) such as:
17-
\begin{equation}
17+
\begin{equation*}
1818
Y =
19+
\begin{bmatrix}
20+
\boldsymbol{y}_1 & \boldsymbol{y}_2 & \boldsymbol{y}_3\\
21+
\end{bmatrix}
22+
=
1923
\begin{bmatrix}
2024
1 & \dots & 1 & 0 & \dots & 0 & 0 & \dots & 0\\
2125
0 & \dots & 0 & 1 & \dots & 1 & 0 & \dots & 0\\
2226
0 & \dots & 0 & 0 & \dots & 0 & 1 & \dots & 1\\
23-
\end{bmatrix}^\top
24-
\end{equation}
25-
where each column of $Y$ corresponds to a fault class. The first $n_j$ elements of column $j$ are filled with a $1$, which indicates that the first $n_j$ rows of $X$ are data from fault $j$. In this case PLS is called \textbf{discriminant}.
27+
\end{bmatrix}^\top
28+
p = 3
29+
\end{equation*}
30+
where each column of $Y$ corresponds to a \textit{fault class}. The first $n_j$ elements of column $j$ are filled with a $1$, which indicates that the first $n_j$ rows of $X$ are data from fault $j$. In classification case PLS is named \textbf{discriminant}.
2631
\end{frame}
Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,67 @@
11
\section{Description of the PLS algorithm}
22

3-
\begin{frame}
4-
TO DO
5-
\end{frame}
3+
\begin{frame}[fragile]
4+
\frametitle{NIPALS algorithm}
5+
The most popular algorithm used in PLS to compute the model parameters is known as \textbf{non-iterative partial least squares} (\textbf{NIPALS}). There are two versions of this technique:
6+
\begin{itemize}
7+
\item \textbf{PLS1}: each of the \textit{p} predicted variables in modeled separately, resulting in one model for each class;
8+
\item \textbf{PLS2}: all predicted variables are modeled simultaneously.
9+
\end{itemize}
10+
The first algorithm is more accurate than the other, however it requires more computational time than PLS2 to find the $\alpha$ eigenvectors into which project the \textit{m} covariates.
11+
\end{frame}
12+
13+
\begin{frame}[fragile]
14+
\frametitle{MATLAB code}
15+
The following MATLAB code implements the PLS2 algorithm:
16+
\begin{Verbatim}[tabsize=4, commandchars=\\\{\}, frame=topline]
17+
E = X; \textcolor{green}{% residual matrix for X}
18+
F = Y; \textcolor{green}{% residual matrix for Y}
19+
[~, idx] = max(sum(Y.*Y));
20+
\textcolor{green}{% search of the j-th eigenvector}
21+
\textcolor{blue}{for} j = 1:alpha
22+
u = F(:, idx);
23+
tOld = 0;
24+
\textcolor{blue}{for} i = 1:maxIter
25+
w = (E'*u)/norm(E'*u); \textcolor{green}{% support vector}
26+
t = E*w; \textcolor{green}{% j-th column of the score matrix for X}
27+
q = (F'*t)/norm(F'*t); \textcolor{green}{% j-th column of the...}
28+
\textcolor{green}{% loading matrix for Y}
29+
u = F*q; \textcolor{green}{% j-th column of the score matrix for Y}
30+
\end{Verbatim}
31+
\end{frame}
32+
33+
\begin{frame}[fragile]
34+
\begin{Verbatim}[tabsize=4, commandchars=\\\{\}]
35+
\textcolor{blue}{if} abs(tOld - t) < exitTol
36+
\textcolor{blue}{break};
37+
\textcolor{blue}{else}
38+
tOld = t;
39+
\textcolor{blue}{end}
40+
\textcolor{blue}{end}
41+
p = (E'*t)/(t'*t); \textcolor{green}{% j-th column of the...}
42+
\textcolor{green}{% loading matrix of X}
43+
\textcolor{green}{% scaling}
44+
t = t*norm(p);
45+
w = w*norm(p);
46+
p = p/norm(p);
47+
\textcolor{green}{% calculation of b and the error matrices}
48+
b = (u'*t)/(t'*t); \textcolor{green}{% j-th column of the...}
49+
\textcolor{green}{% coefficient regression matrix}
50+
E = E - t*p';
51+
F = F - b*t*q';
52+
\end{Verbatim}
53+
\end{frame}
54+
55+
\begin{frame}[fragile]
56+
\begin{Verbatim}[tabsize=4, commandchars=\\\{\}, frame=bottomline]
57+
\textcolor{green}{% calculation of W, P, T and B2}
58+
W(:, j) = w;
59+
P(:, j) = p;
60+
T(:, j) = t;
61+
B2 = W*(P'*W)^-1*(T'*T)^-1*T'*Y;
62+
\textcolor{blue}{end}
63+
Y_hat = X*B2; \textcolor{green}{% computation of predictions}
64+
\end{Verbatim}
65+
For each row of \verb|Y_hat| the fault class is chosen by assigning $1$ to the column whose value si greater than that of the others, $0$ otherwise. Moreover, to increase the performances of PLS it is necessary \textbf{normalize} both $X$ and $Y$ before running the algorithm.
66+
67+
\end{frame}

0 commit comments

Comments
 (0)