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
iter = iter + 1;
globalerror = 0;
for p = 1:count
output = calculateOutput(weights,x(p),y(p));
localerror = T_Q2(p) - output
weights(1)= weights(1) + learningrate *localerror*x(p);
weights(2)= weights(1) + learningrate *localerror*y(p);
weights(3)= weights(1) + learningrate *localerror;
globalerror = globalerror + (localerror*localerror);
end
end
在其他一些档案中,我写了这本fu。
function result = calculateOutput (weights, x, y)
s = x * weights(1) + y * weights(2) + weights(3);
if s >= 0
result = 1;
else
result = -1;
end
没有。 我在指挥窗口和报界的守则中穿过......在窗户上没有 app。 如何获得产出?