Difference between revisions of "Neural Networks"
Jump to navigation
Jump to search
| (11 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
===Basics=== | ===Basics=== | ||
* simplest unit is the perceptron. It outputs a weighted sum of inputs and passes it through an binary activation function | * simplest unit is the perceptron. It outputs a weighted sum of inputs and passes it through an binary activation function | ||
| − | # Feedforward: <math>\hat{y} = \text{activation} (\sum x_i \cdot w_i + b) </math> | + | # Feedforward: <math>\hat{y} = \text{activation} \left(\sum x_i \cdot w_i + b \right ) </math> |
# Calculate the error, <math>y - \bar{y}</math> | # Calculate the error, <math>y - \bar{y}</math> | ||
| − | # Update the weight vector. Repeat 1-3 | + | # Update the weight vector. |
| + | # Repeat 1-3 | ||
;MLPs: Multilayer Perceptrons | ;MLPs: Multilayer Perceptrons | ||
| Line 17: | Line 18: | ||
# error function: usually MSE for regression, cross-entropy for classification | # error function: usually MSE for regression, cross-entropy for classification | ||
# optimizer: finds optimal weights. Batch, mini-batch and stochastic gradient descent are common. Adam and RMSprop also popular | # optimizer: finds optimal weights. Batch, mini-batch and stochastic gradient descent are common. Adam and RMSprop also popular | ||
| − | # batch size: number of sub-samples given to the network before parameters start to be updated. | + | # batch size: number of sub-samples given to the network before parameters start to be updated. ESL says start with 32, and increase by powers of 2 |
# number of epochs: number of times entire training set is pass through the network | # number of epochs: number of times entire training set is pass through the network | ||
# learning rate: too small converges to 0 (in infinite time) but overfits, too big accelerates learning but won't necessarily find the minimum error | # learning rate: too small converges to 0 (in infinite time) but overfits, too big accelerates learning but won't necessarily find the minimum error | ||
| Line 30: | Line 31: | ||
* Tanh: similar to sigmoid but on [-1,1] scale rather than [0,1] | * Tanh: similar to sigmoid but on [-1,1] scale rather than [0,1] | ||
::<math>\tanh(x) = \dfrac{\sinh(x)}{\cosh(x)} = \dfrac{e^x-e^{-x}}{e^x+e^{-x}}</math> | ::<math>\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: <math>E(W,b) = \dfrac{1}{N}\displaystyle\sum^N_{i=1}(\hat{y}_i - y_i)^2 </math> | ||
| + | * MAE: <math>E(W,b) = \dfrac{1}{N}\displaystyle\sum^N_{i=1}|\hat{y}_i - y_i| </math> | ||
| + | * Cross-entropy: <math> E(W,b) = -\displaystyle\sum^m_{i=1}\hat{y}_i\log(p_i)</math> | ||
| + | |||
| + | ===Optimization Functions=== | ||
| + | * Batch gradient descent | ||
| + | ** Feed entire dataset to network at once, apply feedforward process, calculate error and gradient, and backpropagate to update the weights. | ||
| + | ** Optimizer calculates gradient after seeing ''all'' the train data, then updates weights once after each epoch | ||
| + | ** Relatively low noise and bigger steps | ||
| + | ** Requires lots of RAM | ||
| + | * Stochastic gradient descent | ||
| + | ** aka ''online learning''. Takes single instance of train data to do forward pass, error calculation, gradient calculation and backpropagation to update weights. | ||
| + | ** Weights updated after each single instance, as opposed to BGD which processes entire dataset first). | ||
| + | ** Noisy due to wrong directional step possibility. Reduce this by using a smaller learning rate. | ||
| + | * Mini-batch gradient descent | ||
| + | ** Compromise between BGD and SGD. | ||
| + | ** Trains on mini-batches, as opposed to all the data (BGD) or one instance at a time (SGD) | ||
| + | * Backpropagation | ||
| + | |||
| + | ===Hyperparameters for Neural Networks=== | ||
| + | * Network architecture | ||
| + | ** Number of hidden layers (network depth) | ||
| + | ** Number of neurons in each layer (layer width) | ||
| + | ** Activation type | ||
| + | * Learning and optimization | ||
| + | ** Learning rate and decay schedule | ||
| + | ** Mini-batch size | ||
| + | ** Optimization algorithms | ||
| + | ** Number of epochs (and early stopping criteria) | ||
| + | * Regularization techniques to avoid overfitting | ||
| + | ** L2 regularization | ||
| + | ** Dropout layers | ||
| + | ** Data augmentation | ||
Latest revision as of 16:46, 28 May 2021
Basics[edit]
- simplest unit is the perceptron. It outputs a weighted sum of inputs and passes it through an binary activation function
- Feedforward: [math]\displaystyle{ \hat{y} = \text{activation} \left(\sum x_i \cdot w_i + b \right ) }[/math]
- Calculate the error, [math]\displaystyle{ y - \bar{y} }[/math]
- Update the weight vector.
- Repeat 1-3
- MLPs
- Multilayer Perceptrons
Most basic neural network architecture
- Input layer containing the feature vector
- Hidden Layers take the input from one layer and output the input to another layer
- Weight connections between nodes reflect relative importance (graph theory: edges connect nodes)
- Output layer may be a classifier or a regressor. The activation function determines the type of output
Common Parameters[edit]
- number of hidden layers
- activation function (ReLU, softmax, sigmoid)
- error function: usually MSE for regression, cross-entropy for classification
- optimizer: finds optimal weights. Batch, mini-batch and stochastic gradient descent are common. Adam and RMSprop also popular
- batch size: number of sub-samples given to the network before parameters start to be updated. ESL says start with 32, and increase by powers of 2
- number of epochs: number of times entire training set is pass through the network
- 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[edit]
- 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[edit]
- MSE: [math]\displaystyle{ E(W,b) = \dfrac{1}{N}\displaystyle\sum^N_{i=1}(\hat{y}_i - y_i)^2 }[/math]
- 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]
Optimization Functions[edit]
- Batch gradient descent
- Feed entire dataset to network at once, apply feedforward process, calculate error and gradient, and backpropagate to update the weights.
- Optimizer calculates gradient after seeing all the train data, then updates weights once after each epoch
- Relatively low noise and bigger steps
- Requires lots of RAM
- Stochastic gradient descent
- aka online learning. Takes single instance of train data to do forward pass, error calculation, gradient calculation and backpropagation to update weights.
- Weights updated after each single instance, as opposed to BGD which processes entire dataset first).
- Noisy due to wrong directional step possibility. Reduce this by using a smaller learning rate.
- Mini-batch gradient descent
- Compromise between BGD and SGD.
- Trains on mini-batches, as opposed to all the data (BGD) or one instance at a time (SGD)
- Backpropagation
Hyperparameters for Neural Networks[edit]
- Network architecture
- Number of hidden layers (network depth)
- Number of neurons in each layer (layer width)
- Activation type
- Learning and optimization
- Learning rate and decay schedule
- Mini-batch size
- Optimization algorithms
- Number of epochs (and early stopping criteria)
- Regularization techniques to avoid overfitting
- L2 regularization
- Dropout layers
- Data augmentation