我想在matlab中使用神经网络的X-OR代码

时间:2010-08-25 07:54:07

标签: matlab biological-neural-network

我在神经网络上做项目。 我想在matlab中使用AND,OR,X-OR或任何SMALL应用程序的演示代码。 感谢

1 个答案:

答案 0 :(得分:7)

以下是XOR问题的简单示例(非线性可分离):

input = [0 0; 0 1; 1 0; 1 1]';    %#'
target = [0 1 1 0];               %# target = xor(input(1,:), input(2,:));

%# create ANN: 1 hidden layer with 2 neurons, 
%# and an output layer with a sigmoid transfer function
net = newpr(input, target, 2);
net.divideFcn = '';               %# no data split (training/testing/validation)
net.trainParam.epochs = 50;

net = init(net);
[net,tr] = train(net, input, target);
output = sim(net, input);

[err,cm] = confusion(target,output)

完美的结果:

err =
     0
cm =
     2     0
     0     2

它需要神经网络工具箱