这表明,批处理方法需要更多的时间来训练神经网络,以产生与SGD方法类似的精度水平。

This indicates that the batch methodrequires more time to train the neural network to yield a similar level ofaccuracy of that of the SGD method.

换句话说,批处理方法学习缓慢。

In other words, the batch method learnsslowly.

比较SGD与批处理方法(Comparison of the SGD and the Batch)

在这一节中,我们将实际地研究SGD和批处理方法的学习速度。

In this section, we practically investigatethe learning speeds of the SGD and the batch.

在整个训练数据的训练过程结束时,比较这些方法的误差。

The errors of these methods are compared atthe end of the training processes for the entire training data.

下面的程序清单显示了SGDvsBatch.m文件的详细内容,它比较了两种方法的平均误差。

The following program listing shows theSGDvsBatch.m file, which compares the mean error of the two methods.

为了实现公平的比较,两种方法的权重以相同的值初始化。

In order to evaluate a fair comparison, theweights of both methods are initialized with the same values.

clear all
X = [ 0 0 1;
0 1 1;
1 0 1;
1 1 1;
];

D = [ 0 0 1 1];
E1 = zeros(1000, 1);
E2 = zeros(1000, 1);
W1 = 2*rand(1, 3) - 1;
W2 = W1;

for epoch = 1:1000 % train

   W1= DeltaSGD(W1, X, D);

   W2= DeltaBatch(W2, X, D);

   es1= 0;

   es2= 0;

N = 4;

for k = 1:N

x = X(k, 😃’;
d = D(k);
v1 = W1x;
y1 = Sigmoid(v1);
es1 = es1 + (d - y1)^2;
v2 = W2
x;
y2 = Sigmoid(v2);
es2 = es2 + (d - y2)^2;

end

E1(epoch) = es1 /N;

E2(epoch) = es2/ N;
end
plot(E1, ‘r’)
hold on
plot(E2, ‘b:’)
xlabel(‘Epoch’)
ylabel(‘Average of Training error’)
legend(‘SGD’, ‘Batch’)

以上代码对函数DeltaSGD和DeltaBatch分别训练了1000次。

This program trains the neural network1,000 times for each function, DeltaSGD and DeltaBatch.

在每一代训练中,它将训练数据输入神经网络,并计算输出的均方误差(E1, E2)。

At each epoch, it inputs the training datainto the neural network and calculates the mean square error (E1, E2) of theoutput.

当程序完成1000次训练,将会生成一幅图表来显示每一代训练中的平均误差。

Once the program completes 1,000 trainings,it generates a graph that shows the mean error at each epoch.

如图2-20所示,与批处理方法相比,SGD的学习误差下降得更快,即SGD学习得更快。

As Figure 2-20 shows, the SGD yields fasterreduction of the learning error than the batch; the SGD learns faster.

【读书1】【2017】MATLAB与深度学习——批处理方法的实现(2)-LMLPHP

图2-20 SGD的学习速度优于批处理方法The SGD method learnsfaster than the batch method

——本文译自Phil Kim所著的《Matlab Deep Learning》

更多精彩文章请关注微信号:【读书1】【2017】MATLAB与深度学习——批处理方法的实现(2)-LMLPHP

10-05 08:52