我训练了感知器神经网络并使用matlab获得了权重矩阵。
得到的权重矩阵的维度是<50x1 double>
现在,在提供测试输入时,我有一个 <1x1 double> 值,需要对其进行测试。
如果我将权重矩阵乘以该值,我得到 <50x1 double>。如何设置 <50x1 double> 值的阈值。
有没有办法解决这个问题?
这是代码
tic
clc; clear all; close all;
%function [ w1, bias ] = percep1( x )
zzz = xlsread('D:\matlab\NN_FILES\train_mean.xlsx')
s = zzz;
learning_rate = 0.1; % go with the loop mohan
theta = 10000;
w1=0;
for j = 1:50
x=s(:,j);t=1; bias=0; stopp=1; count=0;
while stopp
yin = bias + (w1*x);
% activation function
if yin > theta
y = 1;
elseif yin < -theta
y = -1;
else
y = 0;
end
if (t ~= y)
% for i = 1 : 7
%if ( x(i) ~= 0 )
w1 = w1 + ( learning_rate * t * x);
%end
% end
bias = bias + ( learning_rate * t);
end
count = count + 1;
if t==y
stopp = 0;
count;
end
end
w(j,:) = w1;
b1(j) = bias;
e1(j) = count;
end
new_weights_2 = w(50,:)
yyy= xlsread('D:\matlab\NN_FILES\test_mean.xlsx');
st=yyy;
theta2 = 1.0e+04 * 1.2 ;
for j=1:20
x=st(:,j);
yin=(new_weights_2(1))*(x)
output(j) = yin;
if yin > theta2
y = 1;
elseif yin < -theta2
y = -1;
else y = 0;
end
y1(j)=y;
end
toc
现在我只使用了权重矩阵的第一个值以满足乘法规则。有没有办法将权重矩阵与测试输入相乘?