필터 지우기
필터 지우기

How to set the encoder transfer function in autoencoder

조회 수: 5 (최근 30일)
huilin zhu
huilin zhu 2018년 11월 1일
편집: Frédéric BERTHOMMIER 2023년 9월 28일
I want to set the encoder transfer function by myself. But I do not how to do it. Can the encoder transfer function be changed by myself

답변 (2개)

SANA
SANA 2018년 11월 16일
First you make an autoencoder and generate its function, the code for generating the function of autoencoder is:
autoenc = trainAutoencoder(Data, 300,...
'MaxEpochs', 100,...
'L2WeightRegularization', 0.001,...
'SparsityRegularization', 4,...
'SparsityProportion', 0.05,...
'ScaleData', true);
generateFunction(autoenc)
The generated function open in MATLAB editor with the name of neural_function, I renamed it my_autoencoder and the transfer function is mentioned there, so you can edit it as you wish, code is below:
function [y1] = my_encoder(x1)
%NEURAL_FUNCTION neural network simulation function.
%
% Generated by Neural Network Toolbox function genFunction, 15-Nov-2018 15:50:26.
%
% [y1] = neural_function(x1) takes these arguments:
% x = 5088xQ matrix, input #1
% and returns:
% y = 5088xQ matrix, output #1
% where Q is the number of samples.
%#ok<*RPMT0>
% ===== NEURAL NETWORK CONSTANTS =====
% Input 1
x1_step1.xoffset = [-10;-11;-11;-12;-1]
x1_step1.gain = [0.090;0.9090;0.9090;0.90909;0.0769]
x1_step1.ymin = 0;
% Layer 1
b1 = [-0.115;0.768;0.7066;0.5009303396;0.1249019302]
IW1_1 = [-0.0947 0.7320 0.3146 0.494636173 -0.0951171]
b2 = [3.5409901027442902688;3.6635759144424437928]
LW2_1 = [-1.1707436273955371675 1.5786236406994880177 -1]
% Output 1
y1_step1.ymin = 0;
y1_step1.gain = [0.0909090909090909;0.07]
y1_step1.xoffset = [-10;-11;-11;-12;-12]
% ===== SIMULATION ========
% Dimensions
Q = size(x1,2); % samples
% Input 1
xp1 = mapminmax_apply(x1,x1_step1);
% Layer 1
a1 = logsig_apply(repmat(b1,1,Q) + IW1_1*xp1);
% Layer 2
a2 = logsig_apply(repmat(b2,1,Q) + LW2_1*a1);
% Output 1
y1 = mapminmax_reverse(a2,y1_step1);
end
% ===== MODULE FUNCTIONS ========
% Map Minimum and Maximum Input Processing Function
function y = mapminmax_apply(x,settings)
y = bsxfun(@minus,x,settings.xoffset);
y = bsxfun(@times,y,settings.gain);
y = bsxfun(@plus,y,settings.ymin);
end
% **********************************************
% ************ Enhance encoder here ************
% Sigmoid Positive Transfer Function
function a = logsig_apply(n,~)
a = 1 ./ (1 + exp(-n));
end
% ************ Enhance encoder here ************
% **********************************************
% Map Minimum and Maximum Output Reverse-Processing Function
function x = mapminmax_reverse(y,settings)
x = bsxfun(@minus,y,settings.ymin);
x = bsxfun(@rdivide,x,settings.gain);
x = bsxfun(@plus,x,settings.xoffset);
end
You can change decoder function as well. Enjoy !!!
  댓글 수: 1
huilin zhu
huilin zhu 2018년 11월 18일
Thanks very much.But do you mean I have to edit a autoencoder before I edit the transfer function, and then I have to train my autoencoder again?

댓글을 달려면 로그인하십시오.


Frédéric BERTHOMMIER
Frédéric BERTHOMMIER 2023년 9월 28일
편집: Frédéric BERTHOMMIER 2023년 9월 28일
I changed the decoder transfer function to recover a PCA equivalent which I checked::
autoenc = trainAutoencoder(Data,4,'MaxEpochs',5000,'DecoderTransferFunction','purelin');
This substitutes to the generation of a .m function as proposed before for obtaining a PCA equivalent. Note that the encoder transfer function cannot be modified.

카테고리

Help CenterFile Exchange에서 Pattern Recognition and Classification에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by