具有不同激活函数的 Matlab 中的感知器

Perceptron in Matlab with different activation functions

我即将了解神经网络的工作原理。让我明确一点:我不想使用任何内置函数。据我了解,我想从一开始就构建一个自己的感知器。例如,我根据这个原理图构建了一个感知器:

除神经元 6 和 7 外,所有神经元都具有恒等函数。这两个神经元应具有逻辑函数 1/(1+e^(-x))。神经元 1 直接连接到 6,神经元 2 直接连接到输出神经元 8。

我现在的问题是如何实现这种特殊情况。当所有神经元都是同一性时,我在 C 中得到正确的值。但是一旦我想在 6 和 7 上实现逻辑函数,我就会得到错误的值。

是否可以找到一种通用算法来涵盖这些特殊情况? (不同的激活函数、层层跳跃、反馈)。

我喜欢它尽可能具有一般性和数学性。应避免变通办法!

代码:

clear;
% Input Layer
o1 = 1;
o2 = 1;
o3 = 1;

% Hidden Layer
o4 = 0;
o5 = 0;
o6 = 0;
o7 = 0;

% Output Layer
o8 = 0;

% Init the Inputvektor:
O = [o1,o2,o3,o4,o5,o6,o7,o8];
C = 0;

% Weight Matrix:

     % 1 2 3 4 5 6 7 8
  W = [0,0,0,1,1,1,0,0; % 1
      0,0,0,1,1,0,0,1 ; % 2  
      0,0,0,1,1,0,0,0 ; % 3
      0,0,0,0,0,1,1,0 ; % 4
      0,0,0,0,0,1,1,0 ; % 5
      0,0,0,0,0,0,0,1 ; % 6
      0,0,0,0,0,0,0,1 ; % 7
      0,0,0,0,0,0,0,0]; % 8

% 3 Layer = 3 Iterations:

for c = 0:2

% Calculate Outputvektor (t+1):
A = O*W;

% Assing new Input vektor:
O = A;

% This seems not correct:
% I want to have Identityfunctions on all Neurons except on Neurons 6 and 7
% However I do not get the correct solutions at the end
O(6) = 1/(1+exp(-O(6)));
O(7) = 1/(1+exp(-O(7)));

% Result of the whole Net:
C = C + O
end

有兴趣的朋友,我自己找到了解决办法:

clear;
% Input Layer
o1 = 0.1;
o2 = 0.1;
o3 = 0.1;

% Hidden Layer
o4 = 0;
o5 = 0;
o6 = 0;
o7 = 0;

% Output Layer
o8 = 0;

Org = [o1,o2,o3,o4,o5,o6,o7,o8];
O = Org;
C = 0;


   % 1 2 3 4 5 6 7 8
W = [0,0,0,1,1,1,0,0; % 1
    0,0,0,1,1,0,0,1 ; % 2  
    0,0,0,1,1,0,0,0 ; % 3
    0,0,0,0,0,1,1,0 ; % 4
    0,0,0,0,0,1,1,0 ; % 5
    0,0,0,0,0,0,0,1 ; % 6
    0,0,0,0,0,0,0,1 ; % 7
    0,0,0,0,0,0,0,0]; % 8

for c = 0:2

 A = O*W;

 O = A;

 O(6) = 1/(1+exp(-1*O(6)));
 O(7) = 1/(1+exp(-1*O(7)));

  % THIS IS THE SOLUTION:
  O = O + Org
end