-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
221 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,229 @@ | ||
Kernel Principal Component Analysis(KPCA) | ||
=== | ||
--------------------------------------------------------- | ||
Updates on 18 Apr 2019 | ||
1. Fixed some errors | ||
2. Added Dynamic KPCA(DKPCA) | ||
--------------------------------------------------------- | ||
|
||
four demos are provided: | ||
demo1: dimensionality reduction or feature extraction | ||
demo2: fault detection for a numerical example | ||
demo3: fault detection and fault diagnosis for TE process using KPCA | ||
demo4: fault detection and fault diagnosis for TE process using Dynamic KPCA(DKPCA) | ||
|
||
demo1: dimensionality reduction, feature extraction | ||
= | ||
load circledata | ||
X = circledata; | ||
figure | ||
for i = 1:4 | ||
scatter(X(1+250*(i-1):250*i,1),X(1+250*(i-1):250*i,2)) | ||
hold on | ||
end | ||
|
||
% Train KPCA model | ||
model = kpca_train(X,'type',0,'sigma',5,'dims',2); | ||
|
||
% Visualize the result of dimensionality reduction | ||
figure | ||
for i = 1:4 | ||
scatter(model.mappedX(1+250*(i-1):250*i,1), ... | ||
model.mappedX(1+250*(i-1):250*i,2)) | ||
hold on | ||
end | ||
![](img/demo1_1.png)![](img/demo1_2.png) | ||
# Kernel Principal Component Analysis(KPCA) | ||
|
||
--------------------------------------------------------------- | ||
Updated on 16 Nov 2019 | ||
1. Used OOP to rewrite some modules. | ||
2. Added support for multiple kernel function. | ||
3. Fixed some bugs. | ||
4. Accelerated the running speed of the fault diagnosis module | ||
--------------------------------------------------------------- | ||
|
||
Notice | ||
1. For a brief introduction to this code, please read 'contents.m' file. | ||
2. Fault diagnosis module only supports gaussian kernel function at this version. | ||
3. The fault diagnosis module calls the precompiled file '.mexw64' to accelerate the running speed. | ||
4. Class is defined using 'Classdef...End', so this code can only be applied to MATLAB after the R2008a release. | ||
5. The original version (v1.0) is also provided. | ||
|
||
### Demo for dimensionality reduction (helix data) | ||
|
||
``` | ||
clc | ||
clear all | ||
close all | ||
addpath(genpath(pwd)) | ||
% load the training data | ||
load('.\data\helix.mat') | ||
traindata = helix; | ||
% create a parameter structure for the KPCA application | ||
application = struct('type','dimensionalityreduction',... | ||
'dimensionality', 2); | ||
% create an object for kernel function | ||
kernel = Kernel('type', 'gauss', 'width', 24); | ||
% create an object for kpca model | ||
kpca = KpcaModel('application', application,... | ||
'kernel', kernel); | ||
% train KPCA model | ||
model = kpca.train(traindata); | ||
% get the mapping data | ||
mappingdata = model.mappingdata; | ||
% plot the mapping data (only support for 2D or 3D data) | ||
plotMappingData(traindata, mappingdata); | ||
``` | ||
![](img/fig-helix.png) | ||
|
||
demo2: fault detection (Improve the performance of fault detection by adjusting parameters) | ||
= | ||
% Training data and Test data | ||
X = rand(200,10); | ||
Y = rand(100,10); | ||
Y(20:40,:) = rand(21,10)+3; | ||
Y(60:80,:) = rand(21,10)*3; | ||
|
||
% Train KPCA model | ||
model = kpca_train(X,'type',1,'sigma',60); | ||
|
||
% Test a new sample Y (vector of matrix) | ||
model = kpca_test(model,Y); | ||
|
||
% Plot the result | ||
plotResult(model.SPE_limit,model.SPE_test); | ||
plotResult(model.T2_limit,model.T2_test); | ||
![](img/demo2_SPE.png)![](img/demo2_T2.png) | ||
### Demo for dimensionality reduction (circle data) | ||
|
||
``` | ||
clc | ||
clear all | ||
close all | ||
addpath(genpath(pwd)) | ||
% load the training data | ||
load('.\data\circledata.mat') | ||
traindata = circledata; | ||
% create a parameter structure for the KPCA application | ||
application = struct('type','dimensionalityreduction',... | ||
'dimensionality', 2); | ||
% create an object for kernel function | ||
kernel = Kernel('type', 'gauss', 'width', 6); | ||
% create an object for kpca model | ||
kpca = KpcaModel('application', application,... | ||
'kernel', kernel); | ||
% train KPCA model | ||
model = kpca.train(traindata); | ||
% get the mapping data | ||
mappingdata = model.mappingdata; | ||
% plot the mapping data (only support for 2D or 3D data) | ||
plotMappingData(traindata, mappingdata, label); | ||
``` | ||
![](img/fig-circle.png) | ||
|
||
### Demo for dimensionality reduction (banana data) | ||
![](img/fig-banana.png) | ||
|
||
### Demo for Fault Dection (using TE process data) | ||
|
||
``` | ||
clc | ||
clear all | ||
close all | ||
addpath(genpath(pwd)) | ||
% load the original process data of the TE process | ||
load('.\data\teprocess.mat') | ||
% normalization (in general, this step is important for fault detection) | ||
[traindata, testdata] = normalize(traindata, testdata); | ||
% create a parameter structure for the KPCA application | ||
application = struct('type','faultdetection',... | ||
'cumulativepercentage', 0.75,... | ||
'significancelevel', 0.95); | ||
% create an object for kernel function | ||
kernel = Kernel('type', 'gauss', 'width', 800); | ||
% create an object for kpca model | ||
kpca = KpcaModel('application', application,... | ||
'kernel', kernel); | ||
% train kpca model | ||
model = kpca.train(traindata); | ||
% test KPCA model | ||
testresult = kpca.test(model, testdata); | ||
% visualize the testing results | ||
plotTestResult(model.spelimit, testresult.spe, 'SPE'); | ||
plotTestResult(model.t2limit, testresult.t2, 'T2'); | ||
``` | ||
``` | ||
*** Detection finished *** | ||
Testing samples number: 960 | ||
T2 alarm number : 799 | ||
SPE alarm number : 859 | ||
``` | ||
![](img/fig-kpca-spe.png)![](img/fig-kpca-t2.png) | ||
|
||
demo3: fault detection and fault diagnosis for TE process | ||
= | ||
% load TE process data | ||
load train | ||
load test | ||
|
||
% Normalization | ||
[X, Y] = normalize(train,test); | ||
### Demo for Fault Diagnosis (using TE process data) | ||
|
||
``` | ||
clc | ||
clear all | ||
close all | ||
addpath(genpath(pwd)) | ||
% load the original process data of the TE process | ||
load('.\data\teprocess.mat') | ||
% normalization (in general, this step is important for fault detection) | ||
[traindata, testdata] = normalize(traindata, testdata); | ||
% create a parameter structure for the KPCA application | ||
application = struct('type','faultdetection',... | ||
'cumulativepercentage', 0.75,... | ||
'significancelevel', 0.95,... | ||
'faultdiagnosis','on',... | ||
'diagnosisparameter', 0.7); | ||
% create an object for kernel function | ||
kernel = Kernel('type', 'gauss', 'width', 800); | ||
% create an object for kpca model | ||
kpca = KpcaModel('application', application,... | ||
'kernel', kernel); | ||
% train kpca model | ||
model = kpca.train(traindata); | ||
% test KPCA model | ||
testresult = kpca.test(model, testdata); | ||
% visualize the testing results | ||
plotTestResult(model.spelimit, testresult.spe, 'SPE'); | ||
plotTestResult(model.t2limit, testresult.t2, 'T2'); | ||
% create a parameter structure for the fault diagnosis | ||
contribution = diagnoseFault(testresult, ... | ||
'startingtime', 301,... | ||
'endingtime', 500,... | ||
'theta', 0.7); | ||
% | ||
% % visualize the results of fault diagnosis | ||
plotContribution(contribution, 'SPE') | ||
plotContribution(contribution, 'T2') | ||
``` | ||
![](img/fig-diagnosis-spe.png)![](img/fig-diagnosis-t2.png) | ||
|
||
### Demo for Dynamic KPCA (DKPCA) (using TE process data) | ||
|
||
``` | ||
clc | ||
clear all | ||
close all | ||
addpath(genpath(pwd)) | ||
% load the original process data of the TE process | ||
load('.\data\teprocess.mat') | ||
% normalization (in general, this step is important for fault detection) | ||
[traindata, testdata] = normalize(traindata, testdata); | ||
% create a parameter structure for the KPCA application | ||
application = struct('type','faultdetection',... | ||
'cumulativepercentage', 0.75,... | ||
'significancelevel', 0.95,... | ||
'timelag', 60); | ||
% create an object for kernel function | ||
kernel = Kernel('type', 'gauss', 'width', 800); | ||
% Train KPCA model | ||
model = kpca_train(X,'type',1,'sigma',800,'fd',1); | ||
% create an object for kpca model | ||
kpca = KpcaModel('application', application,... | ||
'kernel', kernel); | ||
% train kpca model | ||
model = kpca.train(traindata); | ||
% Test a new sample Y (vector of matrix) | ||
model = kpca_test(model,Y); | ||
% test KPCA model | ||
testresult = kpca.test(model, testdata); | ||
% Plot the result | ||
plotResult(model.SPE_limit,model.SPE_test); | ||
plotResult(model.T2_limit,model.T2_test); | ||
% visualize the testing results | ||
plotTestResult(model.spelimit, testresult.spe, 'SPE'); | ||
plotTestResult(model.t2limit, testresult.t2, 'T2'); | ||
``` | ||
|
||
% Fault diagnosis | ||
[CPs_T2_test_s, CPs_SPE_test_s] = CPsKPCA(X,Y,model, ... | ||
'start_time',300,'end_time',500,'theta',0.7); | ||
``` | ||
*** Detection finished *** | ||
Testing samples number: 960 | ||
T2 alarm number : 768 | ||
SPE alarm number : 777 | ||
``` | ||
![](img/fig-dkpca-spe.png)![](img/fig-dkpca-t2.png) | ||
|
||
% Plot Contribution Plots | ||
plotCPs(CPs_SPE_test_s) | ||
plotCPs(CPs_T2_test_s) | ||
![](img/demo3_SPE.png)![](img/demo3_T2.png)![](img/demo3_SPE_fd.png)![](img/demo3_T2_fd.png) |