Neural Network - MLP
4 ビュー (過去 30 日間)
古いコメントを表示
As a challenge for myself I have plotted the classification regions for a neural network classifier(using sigmoid activation functions) for ?1∈[−5,5],?2∈[−5,5]. Which gives the following output:

I was wondering, with the following code I have supplied, is there any possible way to shorten the code and still produce the same output?? I tried as much as I can (still drives me crazy) got it down from 322 to 296 characters without any whitespaces. The matlab code I have provided should work if you copy and paste it into MATLAB. It must work with the version R2018a as I'm too poor to upgrade :).
[x1,x2] = meshgrid(-5:0.01:5, -5:0.01:5);
z1=1./(1+exp(-(-4*x1(:)-x2(:)+1)));
z2=1./(1+exp(-(5*x1(:)-5*x2(:)-2)));
g1= 1./(1+exp(-(-1+5*z2-4)));
g2= 1./(1+exp(-(4*z1-4*z2+1)));
[~, al] = max([g1 g2], [], 2);
figure, hold on, grid on,axis on
plot(x1(al==1),x2(al==1), 'r.');
plot(x1(al==2),x2(al==2), 'k.');
legend('1','2');
0 件のコメント
回答 (1 件)
Thiago Henrique Gomes Lobato
2019 年 12 月 8 日
I'm not sure why you want to shorten the code, it is already vectorize and I don't believe it can go so much less than this. Just for fun, here's a very little modified version with 270 characters:
v =-5:0.01:5;
[x1,x2] = meshgrid(v,v);
z1=1./(1+exp((4*x1(:)+x2(:)-1)));
z2=1./(1+exp((5*(x2(:)-x1(:))+2)));
g1= 1./(1+exp((5-5*z2)));
g2= 1./(1+exp((4*z2-4*z1-1)));
[~, al] = max([g1 g2], [], 2);
figure, hold on
plot(x1(al==1),x2(al==1), 'r.');
plot(x1(al==2),x2(al==2), 'k.');
legend('1','2');
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Deep Learning Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!