我必须实现单层神经网络或感知器.为此,我有2个文件数据集,一个用于输入,一个用于输出.我必须在matlab中执行此操作而不使用神经工具箱.2个文件的格式是如下.
In:
0.832 64.643
0.818 78.843
1.776 45.049
0.597 88.302
1.412 63.458
Out:
0 0 1
0 0 1
0 1 0
0 0 1
0 0 1
Run Code Online (Sandbox Code Playgroud)
目标输出为"1表示相应输入所属的特定类,"0表示其余2个输出.
我试图这样做,但它不适合我.
load in.data
load out.data
x = in(:1);
y = in(:2);
learning rate = 0.2;
max_iteration = 50;
function result = calculateOutput(weights,x, y)
s = x*(weights(1) +weight(2) +weight(3));
if s>=0
result = 1
else:
result = -1
end
end
Count = length(x);
weights[0] = rand();
weights[1] = rand();
weights[2] = rand(); …Run Code Online (Sandbox Code Playgroud) 对于单层神经网络的实现,我有两个数据文件.
In:
0.832 64.643
0.818 78.843
Out:
0 0 1
0 0 1
Run Code Online (Sandbox Code Playgroud)
以上是2个数据文件的格式.
目标输出为"1表示相应输入所属的特定类,"0表示其余2个输出.
问题如下:
您的单层神经网络将在Y = A*X + b中找到A(3乘2矩阵)和b(3乘1矢量),其中Y是[C1,C2,C3]',X是[x1,x2]' .
为了用神经网络解决上述问题,我们可以重新编写如下公式:Y = A'*X'其中A'= [A b](3乘3矩阵),X'是[x1,x2, 1]"
现在您可以使用具有三个输入节点(分别用于x1,x2和1)和三个输出(C1,C2,C3)的神经网络.
由此产生的9(因为我们在3个输入和3个输出之间有9个连接)权重将等同于A'矩阵的元素.
基本上,我试图做这样的事情,但它不起作用:
function neuralNetwork
load X_Q2.data
load T_Q2.data
x = X_Q2(:,1);
y = X_Q2(:,2);
learningrate = 0.2;
max_iteration = 50;
% initialize parameters
count = length(x);
weights = rand(1,3); % creates a 1-by-3 array with random weights
globalerror = 0;
iter = 0;
while globalerror ~= 0 && iter <= max_iteration …Run Code Online (Sandbox Code Playgroud)