⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bam.m

📁 內涵模糊理論與類神經網路的程式碼...提供初學者做研究參考
💻 M
字号:
% ==========================================================
% 
%           Neural Networks A Classroom Approach
%                     Satish Kumar
%             Copyright Tata McGraw Hill, 2004
%
%       MATLAB code that implements the BAM algorithm
%             Reference: Table 10.12;Page 444
%
% ==========================================================

n = 5;    % Dimension of Fx
p = 4;    % Dimension of Fy
q = 2;    % Number of associations

mem_vectorsx = [0 1 0 1 0		% Specify Fx vectors
                1 1 0 0 0];
mem_vectorsy = [1 0 0 1			% Specify Fy vectors
                0 1 0 1];
bip_mem_vecsx = 2*mem_vectorsx-1;
bip_mem_vecsy = 2*mem_vectorsy-1;

wt_matrix = zeros(n,p);		% Initialize weight matrix
for i=1:q						% and recursively compute
  wt_matrix = wt_matrix + bip_mem_vecsx(i,:)'*bip_mem_vecsy(i,:);
end

k = 1;							% Set up time index
probe = [0 1 0 1 1];			% Set up probe
signal_x = 2*probe - 1;		% Set Fx signals to probe
signal_y = randomize(1,p);	% Randomize Fy signals
pattern_x(k,:) = signal_x; %store the pattern on Fx
pattern_y(k,:) = signal_y; %store the pattern on Fy
flag = 0;						%indicates bidirectional equilibrium

while flag ~=1
  act_y = signal_x * wt_matrix;	% Compute Fx activations
  for i = 1 : p						% Set up signals
    if act_y(i) > 0
      signal_y(i) =  1;
    elseif act_y(i) < 0
      signal_y(i) = -1;
    end
  end
  if (k > 1)	% Compare for stability if iteration > 1
    compare_y = isequal(signal_y, pattern_y(k-1,:)); 
 else 
    compare_y = 0;
 end
 
 pattern_y(k,:) = signal_y;	% Store the signal on Fy
 
 act_x = signal_y * wt_matrix';	% Compute activations of Fx  
 for i = 1 : n							% Set up signals
    if act_x(i) > 0
      signal_x(i) = 1;
    elseif act_x(i) < 0
      signal_x(i) = -1;
    end
  end

  k = k + 1;							% Increment time
  compare_x = isequal(signal_x, pattern_x(k-1,:));	% Compare
  pattern_x(k,:) = signal_x; 		% and store the signal on Fx
  flag = compare_x*compare_y;		% Check for bidirectional equilibrium
end

pattern_x	% Display update traces
pattern_y

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -