📄 bsb.m
字号:
% ==========================================================
%
% Neural Networks A Classroom Approach
% Satish Kumar
% Copyright Tata McGraw Hill, 2004
%
% MATLAB code that simulates a BSB network
% Reference: Table 10.6;Page 424
%
% ==========================================================
% Initialize variables
delta = 0;
gamma = 1;
alpha = 1;
lim_u = 1;
lim_l = -1;
lambda1 = 0.04;
lambda2 = 0.03;
% Specify vectors to encode
x1 = [1 -1]';
x2 = [1 1]';
% Normalize them
x1_n = x1/sqrt(2);
x2_n = x2/sqrt(2);
% Encode them
W = lambda1*x1_n * x1_n' + lambda2*x2_n * x2_n';
figure(1);
hold on;
grid on;
% Start at an initial point of (-1,-1) and go to (1,1)
% in steps of 0.1
x = -1;
y = -1;
inc = 0.1;
while(x <=1)
while(y <= 1);
s(:,1) = [x y]';
for i = 2:150
act = gamma * s(:,i-1)' + alpha * s(:,i-1)' * W + delta * s(:,1)';
for j=1:2
if (act(j) <= lim_l)
s(j,i) = lim_l;
elseif (act(j) >= lim_u)
s(j,i) = lim_u;
else s(j,i) = act(j);
end
end
end
if ((s(1,i) == 1) & (s(2,i) == 1)) plot(s(1,:), s(2,:), 'k-.');
elseif ((s(1,i) == 1) & (s(2,i) == -1)) plot(s(1,:), s(2,:), 'k');
elseif ((s(1,i) == -1) & (s(2,i) == 1)) plot(s(1,:), s(2,:), 'k');
elseif ((s(1,i) == -1) & (s(2,i) == -1)) plot(s(1,:), s(2,:), 'k-.');
end
y = y + inc;
end
y = -1;
x = x + inc;
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -