Neural Networks

From Bitnami MediaWiki
Jump to navigation Jump to search

Basics

  • simplest unit is the perceptron. It outputs a weighted sum of inputs and passes it through an binary activation function
  1. Feedforward: [math]\displaystyle{ \hat{y} = \text{activation} (\sum x_i \cdot w_i + b) }[/math]
  2. Calculate the error, [math]\displaystyle{ y - \bar{y} }[/math]
  3. Update the weight vector.
  4. Repeat 1-3
MLPs
Multilayer Perceptrons

Most basic neural network architecture

  1. Input layer containing the feature vector
  2. Hidden Layers take the input from one layer and output the input to another layer
  3. Weight connections between nodes reflect relative importance (graph theory: edges connect nodes)
  4. Output layer may be a classifier or a regressor. The activation function determines the type of output

Common Parameters

  1. number of hidden layers
  2. activation function (ReLU, softmax, sigmoid)
  3. error function: usually MSE for regression, cross-entropy for classification
  4. optimizer: finds optimal weights. Batch, mini-batch and stochastic gradient descent are common. Adam and RMSprop also popular
  5. batch size: number of sub-samples given to the network before parameters start to be updated. Start with 32.
  6. number of epochs: number of times entire training set is pass through the network
  7. learning rate: too small converges to 0 (in infinite time) but overfits, too big accelerates learning but won't necessarily find the minimum error

Activation Functions

  • Linear transfer: passes signal through unchanged
  • (Heaviside) Step function: usually used for classification since output is 0 or 1
  • Sigmoid/logistic: usually used to predict probabilities (in logistic regression). More flexible version of step function
[math]\displaystyle{ \sigma(z) = \dfrac{1}{1 + e^{-z}} }[/math]
  • Softmax: used instead of sigmoid for multiclass output problems
[math]\displaystyle{ \sigma(x_j) = \dfrac{e^{x_j}}{\sum_i e^{x_i}} }[/math]
  • Tanh: similar to sigmoid but on [-1,1] scale rather than [0,1]
[math]\displaystyle{ \tanh(x) = \dfrac{\sinh(x)}{\cosh(x)} = \dfrac{e^x-e^{-x}}{e^x+e^{-x}} }[/math]
  • Rectified linear unit (ReLU): looks like a hockey stick/call option. Tends to train better than tanh or sigmoid in hidden layers
  • Leaky ReLU: f(x) = max(0.01x, x). Increases threshold from 0 to 0.01 to avoid vanishing derivatives which slow gradient descent

Error Functions

  • MSE
  • MAE: [math]\displaystyle{ E(W,b) = \dfrac{1}{N}\displaystyle\sum^N_{i=1}|\hat{y}_i - y_i| }[/math]
  • Cross-entropy: [math]\displaystyle{ E(W,b) = -\displaystyle\sum^m_{i=1}\hat{y}_i\log(p_i) }[/math]