Summation mathematical notation
The summation symbol Σ (capital Greek sigma) means add up. With i = 1 below it and n above, Σ xᵢ is x₁ + x₂ + … + xₙ: the index starts at the lower value, stops at the upper one, and the expression on the right is added once for each value. A capital Σ with no index, as in N(μ, Σ), is usually a covariance matrix.
Read it as: sum, sigma, the sum from i equals 1 to n of.
Type it: Unicode U+2211 (the Greek letter Σ is U+03A3) · HTML ∑ · LaTeX \sum
Mac: press Option-W on the US or ABC keyboard layout.
Windows: in Word, type 2211 and press Alt+X. Alt+228 on the numeric keypad types the Greek letter Σ, which looks similar.
Sum over an index: Adds the expression once for each integer value of the index, from the lower limit to the upper limit, both included.
$$\sum_{i=1}^{4}i^2=1+4+9+16=30$$
In Python, sum(i**2 for i in range(1, 5)) returns 30. range stops before 5, while the sum's upper limit 4 is included.
The index is a dummy variable: Σᵢ i² and Σₖ k² are the same sum. With no limits, as in Σᵢ xᵢ, the sum runs over every index the text has defined.
Sum over a dataset: Adds one term per training example. Most losses and averages in machine learning are a sum over examples divided by their count.
$$\operatorname{MSE}=\frac1n\sum_{i=1}^{n}(y_i-\hat y_i)^2$$
For targets 3, 5, 2 and predictions 2.5, 5, 4, the squared errors are 0.25, 0 and 4. They add up to 4.25, and the mean squared error is 4.25/3 ≈ 1.417.
Check whether a loss is a sum or a mean. PyTorch's MSELoss and CrossEntropyLoss average by default (reduction='mean'); reduction='sum' multiplies the loss and its gradients by the number of terms, the batch size when each example has one output.
Sum over a shared index: A sum over an index that appears in two factors. Matrix multiplication is the standard case: entry (i, j) of AB sums row i of A times column j of B.
$$(AB)_{ij}=\sum_{k=1}^{n}A_{ik}B_{kj}$$
For A = [[1, 2], [3, 4]] and B = [[5, 6], [7, 8]], entry (1, 1) of AB is 1·5 + 2·7 = 19. np.einsum('ik,kj->ij', A, B) computes the same sums.
Einstein notation drops the Σ: a repeated index, like k in A[i, k] B[k, j], means sum over k. einsum strings follow the same rule.
Infinite sum: With ∞ as the upper limit, the sum is the limit of its partial sums, and it has a value only when that limit exists.
$$G_t=\sum_{k=0}^{\infty}\gamma^kR_{t+k+1}$$
In reinforcement learning, the return Gₜ adds discounted future rewards. If every reward is 1 and γ = 0.9, Gₜ = 1 + 0.9 + 0.81 + … = 1/(1 − 0.9) = 10.
Not every infinite sum has a value: 1 + 1/2 + 1/3 + … grows without bound, while 1 + 1/4 + 1/9 + … converges to π²/6 ≈ 1.645.