added some discussion to neural nets

This commit is contained in:
mhjensen
2018-10-12 05:44:26 +02:00
parent 652f00be7f
commit e6ed842d7b
72 changed files with 4975 additions and 159 deletions
+148
View File
@@ -2187,3 +2187,151 @@ ax.set_ylabel("$\eta$")
ax.set_xlabel("$\lambda$")
plt.show()
!ec
!split
===== Which activation function should I use? =====
Backpropagation algorithm works by going from the output layer to the
input layer, propagating the error gradient on the way. Once the algorithm has computed the gradient of the
cost function with regards to each parameter in the network, it uses these gradients to update each
parameter with a Gradient Descent step.
Unfortunately, gradients often get smaller and smaller as the algorithm progresses down to the lower
layers. As a result, the Gradient Descent update leaves the lower layer connection weights virtually
unchanged, and training never converges to a good solution. This is called the vanishing gradients
problem. In some cases, the opposite can happen: the gradients can grow bigger and bigger, so many
layers get insanely large weight updates and the algorithm diverges. This is the exploding gradients
problem, which is mostly encountered in recurrent neural networks. More generally,
deep neural networks suffer from unstable gradients, different layers may learn at widely different speeds
!split
===== Is the Logistic activation function (Sigmoid) our choice? =====
Although this unfortunate behavior has been empirically observed for quite a while (it was one of the
reasons why deep neural networks were mostly abandoned for a long time), it is only around 2010 that
significant progress was made in understanding it.
A paper titled _Understanding the Difficulty of Training Deep Feedforward Neural Networks_ by Xavier Glorot and Yoshua Bengio1 found a few suspects,
including the combination of the popular logistic sigmoid activation function and the weight initialization
technique that was most popular at the time, namely random initialization using a normal distribution with
a mean of 0 and a standard deviation of 1. In short, they showed that with this activation function and this
initialization scheme, the variance of the outputs of each layer is much greater than the variance of its
inputs. Going forward in the network, the variance keeps increasing after each layer until the activation
function saturates at the top layers. This is actually made worse by the fact that the logistic function has a
mean of 0.5, not 0 (the hyperbolic tangent function has a mean of 0 and behaves slightly better than the
logistic function in deep networks).
!split
===== The derivative of the Logistic funtion =====
Looking at the logistic activation function, when inputs become large
(negative or positive), the function saturates at 0 or 1, with a derivative extremely close to 0. Thus when
backpropagation kicks in, it has virtually no gradient to propagate back through the network, and what
little gradient exists keeps getting diluted as backpropagation progresses down through the top layers, so
there is really nothing left for the lower layers.
In their paper, Glorot and Bengio propose a way to significantly alleviate this problem. We need the
signal to flow properly in both directions: in the forward direction when making predictions, and in the
reverse direction when backpropagating gradients. We dont want the signal to die out, nor do we want it
to explode and saturate. For the signal to flow properly, the authors argue that we need the variance of the
outputs of each layer to be equal to the variance of its inputs, and we also need the gradients to have
equal variance before and after flowing through a layer in the reverse direction (please check out the
paper if you are interested in the mathematical details).
One of the insights in the 2010 paper by Glorot and Bengio was that the vanishing/exploding gradients
problems were in part due to a poor choice of activation function. Until then most people had assumed
that if Nature had chosen to use roughly sigmoid activation functions in biological neurons, they
must be an excellent choice. But it turns out that other activation functions behave much better in deep
neural networks, in particular the ReLU activation function, mostly because it does not saturate for
positive values (and also because it is quite fast to compute).
!split
===== The RELU function family =====
The ReLU activation function suffers from a problem known as the dying
ReLUs: during training, some neurons effectively die, meaning they stop outputting anything other than 0.
In some cases, you may find that half of your networks neurons are dead, especially if you used a large
learning rate. During training, if a neurons weights get updated such that the weighted sum of the neurons
inputs is negative, it will start outputting 0. When this happen, the neuron is unlikely to come back to life
since the gradient of the ReLU function is 0 when its input is negative.
To solve this problem, you may want to use a variant of the ReLU function, such as the leaky ReLU discussed before or the so-called exponential linear unit (ELU) function
!bt
\[
ELU(z) = \left\{\begin{array}{cc} \alpha\left( \exp{(z)}-1\right) & z > 0,\\ z & z \le 0.\end{array}\right.
\]
!et
So which activation function should you use for the hidden layers of your deep neural networks? Although your mileage will vary,
in general ELU is better than leaky ReLU (and its variants), which is better than ReLU. ReLU performs better than $\tanh$ which in turn performs better than the logistic function. If you care a lot about runtime performance, then you
may prefer leaky ReLUs over ELUs. If you dont want to tweak yet another hyperparameter, you may just use the default $\alpha$ of
$0.01$ for the leaky ReLU, and $1$ for ELU. If you have spare time and computing power, you can use
cross-validation or bootstrap to evaluate other activation functions.
huge training set.
!split
===== A top-down perspective on Neural networks =====
The first thing we would like to do is divide the data into two or three
parts. A training set, a validation or dev (development) set, and a
test set. The test set is the data on which we want to make
predictions. The dev set is a subset of the training data we use to
check how well we are doing out-of-sample, after training the model on
the training dataset. We use the validation error as a proxy for the
test error in order to make tweaks to our model. It is crucial that we
do not use any of the test data to train the algorithm. This is a
cardinal sin in ML. Then:
* Estimate optimal error rate
* Minimize underfitting (bias) on training data set.
* Make sure you are not overfitting.
If the validation and test sets are drawn from the same distributions,
then good performance on the validation set should lead to similarly
good performance on the test set.
However, sometimes
the training data and test data differ in subtle ways because, for
example, they are collected using slightly different methods, or
because it is cheaper to collect data in one way versus another. In
this case, there can be a mismatch between the training and test
data. This can lead to the neural network overfitting these small
differences between the test and training sets, and a poor performance
on the test set despite having a good performance on the validation
set. To rectify this, Andrew Ng suggests making two validation or dev
sets, one constructed from the training data and one constructed from
the test data. The difference between the performance of the algorithm
on these two validation sets quantifies the train-test mismatch. This
can serve as another important diagnostic when using DNNs for
supervised learning.
!split
===== Limitations of supervised learning with deep networks =====
Like all statistical methods, supervised learning using neural
networks has important limitations. This is especially important when
one seeks to apply these methods, especially to physics problems. Like
all tools, DNNs are not a universal solution. Often, the same or
better performance on a task can be achieved by using a few
hand-engineered features (or even a collection of random
features).
Here we list some of the important limitations of supervised neural network based models.
* _Need labeled data_. All supervised learning methods, DNNs for supervised learning require labeled data. Often, labeled data is harder to acquire than unlabeled data (e.g. one must pay for human experts to label images).
* _Supervised neural networks are extremely data intensive._ DNNs are data hungry. They perform best when data is plentiful. This is doubly so for supervised methods where the data must also be labeled. The utility of DNNs is extremely limited if data is hard to acquire or the datasets are small (hundreds to a few thousand samples). In this case, the performance of other methods that utilize hand-engineered features can exceed that of DNNs.
* _Homogeneous data._ Almost all DNNs deal with homogeneous data of one type. It is very hard to design architectures that mix and match data types (i.e.~some continuous variables, some discrete variables, some time series). In applications beyond images, video, and language, this is often what is required. In contrast, ensemble models like random forests or gradient-boosted trees have no difficulty handling mixed data types.
* _Many problems are not about prediction._ In natural science we are often interested in learning something about the underlying distribution that generates the data. In this case, it is often difficult to cast these ideas in a supervised learning setting. While the problems are related, it is possible to make good predictions with a *wrong* model. The model might or might not be useful for understanding the underlying science.
Some of these remarks are particular to DNNs, others are shared by all supervised learning methods. This motivates the use of unsupervised methods which in part circumnavigate these problems.