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

📄 hopfield.m

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

mem_vectors = [
 1 1 0 0 0 0
 0 0 0 0 1 1
 0 0 1 1 0 0];

q = size(mem_vectors,1); % Find the number of vectors
n = size(mem_vectors,2); % Find the dimension of the vectors
bip_mem_vecs = 2*(mem_vectors) - 1;% Convert to bipolar

% Initialize and compute the weight matrix
zd_wt_mat = zeros(n,n);
for i=1:q 
 zd_wt_mat = zd_wt_mat + bip_mem_vecs(i,:)'*bip_mem_vecs(i,:);
end
zd_wt_mat = zd_wt_mat - q*eye(n); % Zero off the diagonal

probe = input('Enter the probe vector: '); %Read probe vector
signal_vector = 2*probe-1; % Convert probe to bipolar form
flag = 0;						% Initialize flag

while flag ~= n 
    permindex = randperm(n);	% Randomize the order of update
    old_signal_vector = signal_vector;	% Keep a copy of the signals

    for j = 1:n 					% Update all neurons once per epoch
      act_vec = signal_vector * zd_wt_mat; 
      if act_vec(permindex(j)) > 0
        signal_vector(permindex(j)) = 1;
      elseif act_vec(permindex(j)) < 0
        signal_vector(permindex(j)) = -1;
      end
    end
  flag = signal_vector*old_signal_vector';	% Generate flag
end

disp('The recalled vector is ')
0.5*(signal_vector + 1)

⌨️ 快捷键说明

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