我通过此代码创建了两类点
clf;
%# random points
N = 1000;
a1=-1; b1=4;
a2=-4; b2=4;
x1 = a1 + (b1-a1).*rand(N,1);
y1 = a2 + (b2-a2).*rand(N,1);
x2 = a1 + (b1-a1).*rand(N,1);
y2 = a2 + (b2-a2).*rand(N,1);
hold all;
% Plot line y=-3/2*x+3
t = -1:.1:4;
z = -3/2*t+3;
plot(t,z)
n=300;
x1new=zeros(n,1);
y1new=zeros(n,1);
error1=zeros(n,1);
x2new=zeros(n,1);
y2new=zeros(n,1);
error2=zeros(n,1);
p1=rand(N,1); % make error distribution for class 1
d1=0;
d2=0;
i=1;
while d1<n && i<N
if (3*x1(i)+2*y1(i)<=6)
if p1(i) > 0.2
d1=d1+1;
x1new(d1)=x1(i);
y1new(d1)=y1(i);
error1(d1)=0;
plot(x1new(d1), y1new(d1),'-bs', 'MarkerFaceColor','b', 'MarkerSize',5)
else
d2=d2+1;
x2new(d2)=x1(i);
y2new(d2)=y1(i);
error2(d2)=1;
plot(x2new(d2), y2new(d2),'-bs', 'MarkerFaceColor','r', 'MarkerSize',5)
end
end
i=i+1;
p2=rand(N,1); % make error distribution for class 2
if (3*x2(i)+2*y2(i)>6)
if p2(i) > 0.2
d2=d2+1;
x2new(d2)=x2(i);
y2new(d2)=y2(i);
error2(d2)=0;
plot(x2new(d2), y2new(d2),'-bs', 'MarkerFaceColor','r', 'MarkerSize',5)
else
d1=d1+1;
x1new(d1)=x2(i);
y1new(d1)=y2(i);
error1(d1)=1;
plot(x1new(d1), y1new(d1),'-bs', 'MarkerFaceColor','b', 'MarkerSize',5)
end
end
i=i+1;
end
% Export to workplace
assignin('base', 'Class1', [x1new,y1new,error1]);
assignin('base', 'Class2', [x2new,y2new,error2]);
结果如下 http://i.stack.imgur.com/nBK8D.png
每节课有300分。生成的数据不是线性可分的 - 每个类的20%违反线性可分性。
但是,现在我必须使用Delta Rule:
使用感知器,使用Delta规则(Widrow-Hoff)对200个点进行训练,以确定权重和偏差,并对剩余的100个点进行分类。
使用adaline,使用Delta规则(Widrow-Hoff)进行200点训练以确定权重和偏差,并对剩余的100分进行分类。
*对于每种类型的单位,绘制显示收敛速度的图表(垂直轴的均方误差与水平轴训练中的示例数量),
*对于每种类型的单位,绘制图表,显示正确分类的示例的比率(百分比)与训练集中的示例数量(使用100个示例进行学习并对剩余的200个进行分类 - 计算百分比正确分类数据;然后使用125个示例进行培训并对剩余的175个进行分类;使用150个进行培训并对剩余的150个进行分类;使用175个进行培训并对剩余的125个进行分类;使用200个进行培训并对剩余的100个进行分类)
你能帮我用Matlab做Delta Rule吗?
答案 0 :(得分:2)
Dwinnell是否会为DeltaRule学习this并建议输入可能的参数:
% B = DeltaRuleBatchTrain(X,Y,LearningRate,MaximumPasses,MinimumWeightChange,B0)
%
% B = Discovered coefficients
%
% X = Predictors (exemplars in rows, variables in columns)
% Y = Target variable (0/1 values)
% LearningRate = Learning rate (try 0.05)
% MinimumWeightChange = Minimum change in weight norm to continue (try 0.01)
% MaximumPasses = Maximum number of training passes (try 50)
% B0 = Initial guess for coefficients (optional, NaN for none)
他给出了以下示例(我已修改它以使用您创建的数据:
% Generate some random data
X = [Class1; Class2] %Now 600x3
Y = ones(size(X,1),1);
Y(1:size(Class1,1)) = 0;
% Train single neuron model using delta rule
B = DeltaRule(X,Y,0.05,0.01,50);
% Recall using discovered model
Z = Logistic(B(1) + X * B(2:end));
% Measure resubstitution accuracy
mean(Y == (Z > 0.5))