本文介绍了我想要在Matlab中为神经网络使用X-OR代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做有关神经网络的项目.我想要一个关于AND,OR,X-OR或matlab中任何小型应用程序的演示代码.谢谢

解决方案

以下是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

它需要神经网络工具箱

i m doing project on neural network.i want a demo code for AND,OR,X-OR or any SMALL APPLICATION in matlab.thanks

解决方案

Here's a simple example of the XOR problem (non-linearly separable):

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)

with a perfect result of:

err =
     0
cm =
     2     0
     0     2

It requires the Neural Network Toolbox

这篇关于我想要在Matlab中为神经网络使用X-OR代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 23:05