This is a cheat sheet for Recurrent Neural Network learner, covers from math essentials of neural network to several different kinds of RNN. If you go through the whole content and understand thoroughly, you will at least be able to make your own neural network architecture, derive forward/backward propagation equations, which are fundamental to building your own working neural network.

# Math Essentials

Notation Meaning
a ∈ A set membership
| B | A cardinality: number of items in set B
|| v || norm: length of vector v
$\Sigma$ summation
$\int$ integral
$\Re$ the set of real numbers
$\Re^{n}$ real number space of dimension n
n = 2 : plane or 2-space
n = 3 : 3- (dimensional) space
n > 3 : n-space or hyperspace
x, y, z, u, v vector (bold, lower case)
A, B, X matrix (bold, upper case)
$y=f(x)$ function(map):assigns unique value in range of y to each value in domain of x
$dy / dx$ derivative of y with respect to single
$y=f(x)$ function on multiple variables,i.e. a vector of variables; function in n-space
$∂y / ∂x_i$ partial derivative of y with respect to element i of vector x
$$|Ω|$$ the set of possible outcomes O
F the set of possible events E
P the probability distribution

## Types of probability spaces

Define $\|Ω\|$; = number of possible outcomes

Discrete space $|Ω|$ is finite – Analysis involves summations $(∑)$

Continuous space $|Ω|$ is infinite – Analysis involves integrals $(∫)$

## Expected value

Given:

• A discrete random variable X, with possible values x = x1, x2, … xn
• Probabilities $p( X = xi )$ that X takes on the various values of xi
• A function $y_i = f( x_i )$ defined on X The expected value of f is the

probability-weighted “average” value of $f( x_i )$: $E( f ) = ∑_i p( x_i ) ⋅ f( x_i )$

## Correlation

Pearson’s correlation coefficient is covariance normalized by the standard deviations of the two variables

• Always lies in range -1 to 1
• Only reflects linear dependence between variables

## Complement rule

Given: event A, which can occur or not

## Product rule

Given: events A and B, which can co-occur (or not)

## Rule of total probability

Given: events A and B, which can co-occur (or not)

## Independence

Given: events A and B, which can co-occur (or not)

$p(A \| B)=p(A)$ or $p(A,B)=p(A)⋅p(B)$

## Bayes rule

A way to find conditional probabilities for one variable when conditional probabilities for another variable are known.

posterior probability ∝ likelihood × prior probability

where $p( A ) = p( A, B ) + p( A, not B )$

## Matrix arithmetic

• Multiplication is associative

$A ⋅( B ⋅ C ) = ( A ⋅B ) ⋅C$

• Multiplication is not commutative

$A ⋅ B ≠ B ⋅ A$ (generally)

• Transposition rule:

## Vector projection

Orthogonal projection of y onto x is the vector

(using dot product alternate form)

Stanford Machine Learning Tutorial:

TODO

TODO

TODO

TODO: more

# RNN (Recurrent Neural Network)

## LSTM

### Intuition

1. New memory generation:This stage is analogous to the new memory generation stage we saw in GRUs. We essentially use the input word $x_t$ and the past hidden state $h_{t−1}$ to generate a new memory $\tilde{c_t}$ which includes aspects of the new word $x_{(t)}$.

2. Input Gate: We see that the new memory generation stage doesn’t check if the new word is even important before generating the new memory – this is exactly the input gate’s function. The input gate uses the input word and the past hidden state to determine whether or not the input is worth preserving and thus is used to gate the new memory. It thus produces it as an indicator of this information.

3. Forget Gate: This gate is similar to the input gate except that it does not make a determination of usefulness of the input word – instead it makes an assessment on whether the past memory cell is useful for the computation of the current memory cell. Thus, the forget gate looks at the input word and the past hidden state and produces $f_t$.

4. Final memory generation: This stage first takes the advice of the forget gate $f_t$ and accordingly forgets the past memory $c_{t−1}$. Similarly, it takes the advice of the input gate it and accordingly gates the new memory $\tilde{c_t}$. It then sums these two results to produce the final memory $$c_t. 5. Output/Exposure Gate: This is a gate that does not explicitly exist in GRUs. It’s purpose is to separate the final memory from the hidden state. The final memory $c_t$ contains a lot of information that is not necessarily required to be saved in the hidden state. Hidden states are used in every single gate of an LSTM and thus, this gate makes the assessment regarding what parts of the memory ct needs to be exposed/present in the hidden state ht. The signal it produces to indicate this is ot and this is used to gate the point-wise tanh of the memory. ### Equations $i_t = σ(W^{(i)}x_t + U^{(i)}h_{t−1})$ (Input gate) $f_t = σ(W^{(f)}x_t + U^{(f)}h_{t−1})$ (Forget gate) $o_t = σ(W^{(o)}x_t + U^{(o)}h_{t−1})$ (Output/Exposure gate) $\tilde{c_t} = tanh(W^{(c)}x_t + U^{(c)}h_{t−1})$ (New memory cell) $c_t = f_t ◦ c_{t−1} + i_t ◦ \tilde{c_t}$ (Final memory cell) ### How LSTM backward propagation works? Here’s a slide explaining this: LSTM Forward and Backward Pass ## GRU ### Overview of GRU cell ### Details of GRU cell ### Intuition 1. New memory generation: A new memory \(\tilde{h_t}$$ is the consolidation of a new input word $$x_t$$ with the past hidden state $$h_{t−1}$$. Anthropomorphically, this stage is the one who knows the recipe of combining a newly observed word with the past hidden state $$h_{t−1}$$ to summarize this new word in light of the contextual past as the vector $$\tilde{h_t}$$.

2. Reset Gate: The reset signal $$r_t$$ is responsible for determining how important $$h_{t−1}$$ is to the summarization $$\tilde{h_t}$$. The reset gate has the ability to completely diminish past hidden state if it finds that $$h_{t−1}$$ is irrelevant to the computation of the new memory.

3. Update Gate: The update signal $$z_t$$ is responsible for determining how much of $$h_{t−1}$$ should be carried forward to the next state. For instance, if $$z_t ≈ 1$$, then $$h_{t−1}$$ is almost entirely copied out to ht. Conversely, if $$z_t ≈ 0$$, then mostly the new memory $$\tilde{h_t}$$ is forwarded to the next hidden state.

4. Hidden state: The hidden state ht is finally generated using the past hidden input $$h_{t−1}$$ and the new memory generated $$\tilde{h_{t-1}}$$ with the advice of the update gate.

### Equations

$r_t = sigm (W_{xr}x_t + W_{hr}h_t−1 + b_r)$ (Reset gate)

$z_t = sigm(W_{xz}x_t + W_{hz}h_t−1 + b_z)$ (Update gate)

$\tilde{h_t} = tanh(W_{xh}x_t + W_{hh}(r_t ⊙ h_{t−1}) + b_h)$ (New memory)

$h_t = z_t ⊙h_{t−1} +(1−z_t)⊙\tilde{h_t}$ (Hidden state)

TODO: more RNN network and math