3 Star 0 Fork 0

LP/BCI_MI_CSP_DNN

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
DNN.m 2.04 KB
一键复制 编辑 原始数据 按行查看 历史
养乐多 提交于 2019-03-24 16:32 . Bandpass_filter.m
%% Construct Deep Network Using Autoencoders
% Load the sample data.
% Copyright 2015 The MathWorks, Inc.
% CSP-DNN
clc;
clear;
load('CSP_feature.mat')
load('label.mat')
CSP_DNN_Train_data = CSP_Train_feature';
CSP_DNN_Test_data = CSP_Test_feature';
%[X,T] = wine_dataset;
X = CSP_DNN_Train_data;
T = Train_label;
%%
% Train an autoencoder with a hidden layer of size 10 and a linear transfer
% function for the decoder. Set the L2 weight regularizer to 0.001,
% sparsity regularizer to 4 and sparsity proportion to 0.05.
hiddenSize = 15;
autoenc1 = trainAutoencoder(X,hiddenSize,...
'L2WeightRegularization',0.001,...
'SparsityRegularization',4,...
'SparsityProportion',0.05,...
'DecoderTransferFunction','purelin',...
'MaxEpochs', 1000);
view(autoenc1);
plotWeights(autoenc1);
%%
% Extract the features in the hidden layer.
features1 = encode(autoenc1,X);
%%
% Train a second autoencoder using the features from the first autoencoder. Do not scale the data.
hiddenSize = 3;
autoenc2 = trainAutoencoder(features1,hiddenSize,...
'L2WeightRegularization',0.0005,...
'SparsityRegularization',4,...
'SparsityProportion',0.05,...
'DecoderTransferFunction','purelin',...
'ScaleData',false,...
'MaxEpochs', 1000);
view(autoenc2)
%%
% Extract the features in the hidden layer.
features2 = encode(autoenc2,features1);
%%
% Train a softmax layer for classification using the features, |features2|,
% from the second autoencoder, |autoenc2|.
softnet = trainSoftmaxLayer(features2,T,'LossFunction','crossentropy');
%%
% Stack the encoders and the softmax layer to form a deep network.
deepnet = stack(autoenc1,autoenc2,softnet);
%%
% Train the deep network on the wine data.
epoches = 1;
for i = 1:epoches
deepnet = train(deepnet,X,T);
end
% save('deepnet');
%%
% Estimate the wine types using the deep network, |deepnet|.
image_type = deepnet(X);
image_test_type = deepnet(CSP_DNN_Test_data);
%%
% Plot the confusion matrix.
figure(1),plotconfusion(Train_label,image_type,'Train ');
figure(2),plotconfusion(Test_label,image_test_type,'Test ');
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Matlab
1
https://gitee.com/lipeng_66/BCI_MI_CSP_DNN.git
git@gitee.com:lipeng_66/BCI_MI_CSP_DNN.git
lipeng_66
BCI_MI_CSP_DNN
BCI_MI_CSP_DNN
master

搜索帮助