Załóżmy, że zawiera NN ukryte warstwy przykładami treningu, funkcje, a węzłów w każdej warstwie. Jaka jest złożoność czasu, aby trenować ten NN przy użyciu propagacji wstecznej?
Mam podstawowe pojęcie o tym, jak znajdują złożoność czasową algorytmów, ale tutaj należy wziąć pod uwagę 4 różne czynniki, tj. Iteracje, warstwy, węzły w każdej warstwie, przykłady szkolenia i może więcej czynników. Znalazłem tutaj odpowiedź , ale nie była wystarczająco jasna.
Czy istnieją inne czynniki, oprócz tych wymienionych powyżej, które wpływają na złożoność czasową algorytmu szkoleniowego NN?
Odpowiedzi:
Nie widziałem odpowiedzi z zaufanego źródła, ale spróbuję odpowiedzieć na to sam, na prostym przykładzie (z moją obecną wiedzą).
Zasadniczo należy zauważyć, że szkolenie MLP przy użyciu propagacji wstecznej jest zwykle realizowane za pomocą macierzy.
Złożoność czasowa mnożenia macierzy
Złożoność czasowa mnożenia macierzy dlaMij∗Mjk wynosi po prostu O(i∗j∗k) .
Zauważ, że zakładamy tutaj najprostszy algorytm mnożenia: istnieją inne algorytmy o nieco lepszej złożoności czasowej.
Algorytm przekazywania do przodu
Algorytm propagacji do przodu jest następujący.
Po pierwsze, aby przejść z warstwyi do j , musisz
Następnie zastosujesz funkcję aktywacji
If we haveN layers (including input and output layer), this will run N−1 times.
Example
As an example, let's compute the time complexity for the forward pass algorithm for a MLP with4 layers, where i denotes the number of nodes of the input layer, j the number of nodes in the second layer, k the number of nodes in the third layer and l the number of nodes in the output layer.
Assume you havet training examples. For propagating from layer i to j , we have first
and this operation (i.e. matrix multiplcation) hasO(j∗i∗t) time complexity. Then we apply the activation function
and this hasO(j∗t) time complexity, because it is an element-wise operation.
So, in total, we have
Using same logic, for goingj→k , we have O(k∗j∗t) , and, for k→l , we have O(l∗k∗t) .
In total, the time complexity for feedforward propagation will be
I'm not sure if this can be simplified further or not. Maybe it's justO(t∗i∗j∗k∗l) , but I'm not sure.
Back-propagation algorithm
The back-propagation algorithm proceeds as follows. Starting from the output layerl→k , we compute the error signal, Elt , a matrix containing the error signals for nodes at layer l
where⊙ means element-wise multiplication. Note that Elt has l rows and t columns: it simply means each column is the error signal for training example t .
We then compute the "delta weights",Dlk∈Rl×k (between layer l and layer k )
whereZtk is the transpose of Zkt .
We then adjust the weights
Forl→k , we thus have the time complexity O(lt+lt+ltk+lk)=O(l∗t∗k) .
Now, going back fromk→j . We first have
Then
And then
whereWkl is the transpose of Wlk . For k→j , we have the time complexity O(kt+klt+ktj+kj)=O(k∗t(l+j)) .
And finally, forj→i , we have O(j∗t(k+i)) . In total, we have
which is same as feedforward pass algorithm. Since they are same, the total time complexity for one epoch will beO(t∗(ij+jk+kl)).
This time complexity is then multiplied by number of iterations (epochs). So, we haveO(n∗t∗(ij+jk+kl)), where n is number of iterations.
Notes
Note that these matrix operations can greatly be paralelized by GPUs.
Conclusion
We tried to find the time complexity for training a neural network that has 4 layers with respectivelyi , j , k and l nodes, with t training examples and n epochs. The result was O(nt∗(ij+jk+kl)) .
We assumed the simplest form of matrix multiplication that has cubic time complexity. We used batch gradient descent algorithm. The results for stochastic and mini-batch gradient descent should be same. (Let me know if you think the otherwise: note that batch gradient descent is the general form, with little modification, it becomes stochastic or mini-batch)
Also, if you use momentum optimization, you will have same time complexity, because the extra matrix operations required are all element-wise operations, hence they will not affect the time complexity of the algorithm.
I'm not sure what the results would be using other optimizers such as RMSprop.
Sources
The following article http://briandolhansky.com/blog/2014/10/30/artificial-neural-networks-matrix-form-part-5 describes an implementation using matrices. Although this implementation is using "row major", the time complexity is not affected by this.
If you're not familiar with back-propagation, check this article:
http://briandolhansky.com/blog/2013/9/27/artificial-neural-networks-backpropagation-part-4
źródło
For the evaluation of a single pattern, you need to process all weights and all neurons. Given that every neuron has at least one weight, we can ignore them, and haveO(w) where w is the number of weights, i.e., n∗ni , assuming full connectivity between your layers.
The back-propagation has the same complexity as the forward evaluation (just look at the formula).
So, the complexity for learningm examples, where each gets repeated e times, is O(w∗m∗e) .
The bad news is that there's no formula telling you what number of epochse you need.
źródło
e
times for each ofm
examples. I didn't bother to compute the number of weights, I guess, that's the difference.w = ij + jk + kl
. basically sum ofn * n_i
between layers as you noted.A potential disadvantage of gradient-based methods is that they head for the nearest minimum, which is usually not the global minimum.
This means that the only difference between these search methods is the speed with which solutions are obtained, and not the nature of those solutions.
An important consideration is time complexity, which is the rate at which the time required to find a solution increases with the number of parameters (weights). In short, the time complexities of a range of different gradient-based methods (including second-order methods) seem to be similar.
Six different error functions exhibit a median run-time order of approximately O(N to the power 4) on the N-2-N encoder in this paper:
Lister, R and Stone J "An Empirical Study of the Time Complexity of Various Error Functions with Conjugate Gradient Back Propagation" , IEEE International Conference on Artificial Neural Networks (ICNN95), Perth, Australia, Nov 27-Dec 1, 1995.
Summarised from my book: Artificial Intelligence Engines: A Tutorial Introduction to the Mathematics of Deep Learning.
źródło