Borrar filtros
Borrar filtros

Neural Network - MLP

3 visualizaciones (últimos 30 días)
Oscar Tsang
Oscar Tsang el 8 de Dic. de 2019
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');

Respuestas (1)

Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato el 8 de Dic. de 2019
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');

Categorías

Más información sobre Deep Learning Toolbox en Help Center y File Exchange.

Productos


Versión

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by