How to use bias vector in Neural Network to show the decision boundary
1 view (last 30 days)
Show older comments
topics: Recently I use Neural network tools. My problem is : There are 4 points in 2-d plane,I want to classify them into 2 classes. Description: So I use function"learnp()" to implement my idea.The code works to my object.But when I want to draw a decision boundary,I found it's difficult to use bias vector B to plot the line which can separate the 2 classes points,the elements in vector B have different values.Which bias in B could I take to plot the perfect decision boundary line?
clc;
clear all;
P = [ -0.8 -0.5 0.3 0;1.1 0.5 -0.5 1 ];
T = [ 1 1 0 0 ];
[ R, Q ] = size (P); [S, Q ] =size (T);
W =rand( S, R );
% W=[-2.161 -0.074];
b=rand();
max_epoch = 20;
B = cat(2,b,b,b,b);
A = hardlim ( W*P + B );
for epoch = 1 : max_epoch
% if all ( A == T )
% epoch = epoch - 1;
% break
% end
% 学习
e = T - A;
dW = learnp([],P,[],[],[],[],e,[],[],[],[],[]);
db = learnp(b,ones(1,S),[],[],[],[],e,[],[],[],[],[]);
W = W + dW;
B = B + db;
A = hardlim ( W*P + B );
end
%%Result Visualization
% set(gca,'XTick',-pi:pi/2:pi);
figure();
scatter(P(1,:),P(2,:),'*');
hold on;
xmin=min(P(1,:));
xmax=max(P(1,:));
ymin=min(P(2,:));
ymax=max(P(2,:));
xindex=xmin-1:(xmax-xmin)/100:xmax+1;
yindex=-W(1)*xindex/W(2)-mean(B)/W(2);
plot(xindex,yindex);
hold off;
end
0 Comments
Answers (0)
See Also
Categories
Find more on Define Shallow Neural Network Architectures in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!