<p align="center">
<img src="http://github-files-qiu.oss-cn-beijing.aliyuncs.com/KPCA-MATLAB/helix.png">
</p>
<h3 align="center">Kernel Principal Component Analysis (KPCA)</h3>
<p align="center">MATLAB code for dimensionality reduction, fault detection, and fault diagnosis using KPCA</p>
<p align="center">Version 2.2, 14-MAY-2021</p>
<p align="center">Email: [email protected]</p>
<div align=center>
[![View Kernel Principal Component Analysis (KPCA) on File Exchange](https://www.mathworks.com/matlabcentral/images/matlab-file-exchange.svg)](https://ww2.mathworks.cn/matlabcentral/fileexchange/69378-kernel-principal-component-analysis-kpca)
<img src="https://img.shields.io/github/v/release/iqiukp/Kernel-Principal-Component-Analysis-KPCA?label=version" />
<img src="https://img.shields.io/github/repo-size/iqiukp/Kernel-Principal-Component-Analysis-KPCA" />
<img src="https://img.shields.io/github/languages/code-size/iqiukp/Kernel-Principal-Component-Analysis-KPCA" />
<img src="https://img.shields.io/github/languages/top/iqiukp/Kernel-Principal-Component-Analysis-KPCA" />
<img src="https://img.shields.io/github/stars/iqiukp/Kernel-Principal-Component-Analysis-KPCA" />
<img src="https://img.shields.io/github/forks/iqiukp/Kernel-Principal-Component-Analysis-KPCA" />
</div>
<hr />
## Main features
- Easy-used API for training and testing KPCA model
- Support for dimensionality reduction, data reconstruction, fault detection, and fault diagnosis
- Multiple kinds of kernel functions (linear, gaussian, polynomial, sigmoid, laplacian)
- Visualization of training and test results
- Component number determination based on given explained level or given number
## Notices
- Only fault diagnosis of Gaussian kernel is supported.
- This code is for reference only.
## How to use
### 01. Kernel funcions
A class named ***Kernel*** is defined to compute kernel function matrix.
```
%{
type -
linear : k(x,y) = x'*y
polynomial : k(x,y) = (γ*x'*y+c)^d
gaussian : k(x,y) = exp(-γ*||x-y||^2)
sigmoid : k(x,y) = tanh(γ*x'*y+c)
laplacian : k(x,y) = exp(-γ*||x-y||)
degree - d
offset - c
gamma - γ
%}
kernel = Kernel('type', 'gaussian', 'gamma', value);
kernel = Kernel('type', 'polynomial', 'degree', value);
kernel = Kernel('type', 'linear');
kernel = Kernel('type', 'sigmoid', 'gamma', value);
kernel = Kernel('type', 'laplacian', 'gamma', value);
```
For example, compute the kernel matrix between **X** and **Y**
```
X = rand(5, 2);
Y = rand(3, 2);
kernel = Kernel('type', 'gaussian', 'gamma', 2);
kernelMatrix = kernel.computeMatrix(X, Y);
>> kernelMatrix
kernelMatrix =
0.5684 0.5607 0.4007
0.4651 0.8383 0.5091
0.8392 0.7116 0.9834
0.4731 0.8816 0.8052
0.5034 0.9807 0.7274
```
### 02. Simple KPCA model for dimensionality reduction
```
clc
clear all
close all
addpath(genpath(pwd))
load('.\data\helix.mat', 'data')
kernel = Kernel('type', 'gaussian', 'gamma', 2);
parameter = struct('numComponents', 2, ...
'kernelFunc', kernel);
% build a KPCA object
kpca = KernelPCA(parameter);
% train KPCA model
kpca.train(data);
% mapping data
mappingData = kpca.score;
% Visualization
kplot = KernelPCAVisualization();
% visulize the mapping data
kplot.score(kpca)
```
The training results (dimensionality reduction):
```
*** KPCA model training finished ***
running time = 0.2798 seconds
kernel function = gaussian
number of samples = 1000
number of features = 3
number of components = 2
number of T2 alarm = 135
number of SPE alarm = 0
accuracy of T2 = 86.5000%
accuracy of SPE = 100.0000%
```
<p align="center">
<img src="http://github-files-qiu.oss-cn-beijing.aliyuncs.com/KPCA-MATLAB/helix.png">
</p>
Another application using banana-shaped data:
<p align="center">
<img src="http://github-files-qiu.oss-cn-beijing.aliyuncs.com/KPCA-MATLAB/banana.png">
</p>
### 03. Simple KPCA model for reconstruction
```
clc
clear all
close all
addpath(genpath(pwd))
load('.\data\circle.mat', 'data')
kernel = Kernel('type', 'gaussian', 'gamma', 0.2);
parameter = struct('numComponents', 2, ...
'kernelFunc', kernel);
% build a KPCA object
kpca = KernelPCA(parameter);
% train KPCA model
kpca.train(data);
% reconstructed data
reconstructedData = kpca.newData;
% Visualization
kplot = KernelPCAVisualization();
kplot.reconstruction(kpca)
```
<p align="center">
<img src="http://github-files-qiu.oss-cn-beijing.aliyuncs.com/KPCA-MATLAB/circle.png">
</p>
### 04. Component number determination
The Component number can be determined based on given explained level or given number.
***Case 1***
The number of components is determined by the given explained level. The given explained level should be 0 < explained level < 1.
For example, when explained level is set to 0.75, the parameter should
be set as:
```
parameter = struct('numComponents', 0.75, ...
'kernelFunc', kernel);
```
The code is
```
clc
clear all
close all
addpath(genpath(pwd))
load('.\data\TE.mat', 'trainData')
kernel = Kernel('type', 'gaussian', 'gamma', 1/128^2);
parameter = struct('numComponents', 0.75, ...
'kernelFunc', kernel);
% build a KPCA object
kpca = KernelPCA(parameter);
% train KPCA model
kpca.train(trainData);
% Visualization
kplot = KernelPCAVisualization();
kplot.cumContribution(kpca)
```
<p align="center">
<img src="http://github-files-qiu.oss-cn-beijing.aliyuncs.com/KPCA-MATLAB/cumContirb.png">
</p>
As shown in the image, when the number of components is 21, the cumulative contribution rate is 75.2656%,which exceeds the given explained level (0.75).
***Case 2***
The number of components is determined by the given number. For example, when the given number is set to 24, the parameter should
be set as:
```
parameter = struct('numComponents', 24, ...
'kernelFunc', kernel);
```
The code is
```
clc
clear all
close all
addpath(genpath(pwd))
load('.\data\TE.mat', 'trainData')
kernel = Kernel('type', 'gaussian', 'gamma', 1/128^2);
parameter = struct('numComponents', 24, ...
'kernelFunc', kernel);
% build a KPCA object
kpca = KernelPCA(parameter);
% train KPCA model
kpca.train(trainData);
% Visualization
kplot = KernelPCAVisualization();
kplot.cumContribution(kpca)
```
<p align="center">
<img src="http://github-files-qiu.oss-cn-beijing.aliyuncs.com/KPCA-MATLAB/components.png">
</p>
As shown in the image, when the number of components is 24, the cumulative contribution rate is 80.2539%.
### 05. Fault detection
Demonstration of fault detection using KPCA (TE process data)
```
clc
clear all
close all
addpath(genpath(pwd))
load('.\data\TE.mat', 'trainData', 'testData')
kernel = Kernel('type', 'gaussian', 'gamma', 1/128^2);
parameter = struct('numComponents', 0.65, ...
'kernelFunc', kernel);
% build a KPCA object
kpca = KernelPCA(parameter);
% train KPCA model
kpca.train(trainData);
% test KPCA model
results = kpca.test(testData);
% Visualization
kplot = KernelPCAVisualization();
kplot.cumContribution(kpca)
kplot.trainResults(kpca)
kplot.testResults(kpca, results)
```
The training results are
```
*** KPCA model training finished ***
running time = 0.0986 seconds
kernel function = gaussian
number of samples = 500
number of features = 52
number of components = 16
number of T2 alarm = 16
number of SPE alarm = 17
accuracy of T2 = 96.8000%
accuracy of SPE = 96.6000%
```
<p align="center">
<img src="http://github-files-qiu.oss-cn-beijing.aliyuncs.com/KPCA-MATLAB/FD_train.png">
</p>
The test results are
```
*** KPCA model test finished ***
running time = 0.0312 seconds
number of test data = 960
number of T2 alarm = 799
number of SPE alarm
没有合适的资源?快使用搜索试试~ 我知道了~
Kernel Principal Component Analysis (KPCA)matlab代码.zip
共19个文件
m:10个
mat:5个
png:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 123 浏览量
2023-04-11
10:58:57
上传
评论
收藏 1.41MB ZIP 举报
温馨提示
1.版本:matlab2014/2019a,内含运行结果,不会运行可私信 2.领域:智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,更多内容可点击博主头像 3.内容:标题所示,对于介绍可点击主页搜索博客 4.适合人群:本科,硕士等教研学习使用 5.博客介绍:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可si信
资源推荐
资源详情
资源评论
收起资源包目录
Kernel Principal Component Analysis (KPCA)matlab代码.zip (19个子文件)
Kernel Principal Component Analysis (KPCA)matlab代码
data
circle.mat 5KB
banana.mat 6KB
helix.mat 23KB
diagnosis.mat 533KB
TE.mat 409KB
说明.txt 367B
仿真咨询.png 350KB
更多代码关注我.png 114KB
demo_DR.m 508B
demo_DR_Reconstruction.m 495B
demo_FD_Diagnosis.m 679B
KernelPCA
Kernel.m 3KB
KernelPCA.m 14KB
KernelPCAVisualization.m 10KB
KernelPCAOption.m 4KB
demo_FD.m 587B
README.md 9KB
demo_kernel_function.m 661B
demo_DR_Contirbution.m 1KB
共 19 条
- 1
资源评论
天天Matlab科研工作室
- 粉丝: 3w+
- 资源: 7259
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 下载安装这个软件.apk
- 【数据集详细解释及案例分析】数据集详细解释及案例分析
- 基于SHT71温湿度传感器、STM32F103C8T6、LCD1602温湿度采集显示系统proteus仿真设计
- 基于TH02温湿度传感器、STM32F103C8T6、LCD1602、FREERTOS的温湿度采集系统proteus仿真设计
- 【TCP-IP协议详细解释及案例分析】TCP-IP协议详细解释及案例分析
- 一文搞懂 LSTM(长短期记忆网络).rar
- 【autosar简介及基本案例解析】autosar简介及基本案例解析
- java模拟斗地主洗牌发牌
- springboot+vue登录系统 vue部分
- 常用常见 SQL语句语法
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功