Everything on the site.

Big-O notationAlgorithms · Count the steps in real loops, then compare n, n log n, n² and 2ⁿ on a live chart.RecursionAlgorithms · Watch frames push and pop on the call stack for factorial and Fibonacci.BFS vs DFSAlgorithms · A queue against a stack: draw a graph and see which order each search visits it in.Sorting algorithmsAlgorithms · Seven sorts on the same input, with comparison, swap and write counts side by side.Binary searchAlgorithms · Halve the range, probe the middle, repeat: with lo, mid and hi drawn on the array.Sets, relations and functionsDiscrete maths · Shade any set expression on a Venn diagram and test a relation for its properties.Proof by inductionDiscrete maths · Four worked proofs revealed one step at a time, and a broken one to diagnose.CombinatoricsDiscrete maths · An exact nPr and nCr calculator, and a Pascal’s triangle that shows its own addition rule.Boolean algebraDiscrete maths · The laws, De Morgan, and normal forms, with a truth-table generator built in.Finite-state machinesTheory · Build a DFA in a table, see it drawn, and run strings through it one symbol at a time.Domain theoryTheory · Why recursion needs least fixed points, and how CPOs, Scott continuity and powerdomains supply them.Truth table generatorTools · Expression in, truth table out: with DNF, CNF, a minimal form and LaTeX.Graph traversal visualiserTools · Draw a graph, then animate BFS, DFS and Dijkstra with the frontier shown.Recursion tree visualiserTools · Paste a recursive function or a recurrence and see its call tree and call count.Gradient descentML maths · Drag the starting point, set the learning rate, and watch it converge or blow up.Vectors and embeddingsML maths · Bend the plane with a 2×2 matrix and measure how close toy word vectors are.Softmax and cross-entropyML maths · Edit the logits and watch the probabilities, the loss and the gradient update live.AttentionML maths · Q, K and V for three tokens, a live score heatmap, and the weighted sum of values.Formatting a CS paper in LaTeXLaTeX · Page limits, \documentclass, front matter, theorem environments and the bibliography.Camera-ready checklistLaTeX · Fonts embedded, PDF/A, copyright form, source bundle, and why final versions get rejected.LaTeX templatesLaTeX · Where the official classes live, plus a minimal article template you can copy.AlgorithmsSection · Step-through visualisations of sorting, searching, recursion, graph traversal and Big-O growth, each with pseudocode that highlights the line being run.Discrete mathsSection · Sets, relations and functions, proof by induction, counting, and Boolean algebra, explained with worked examples and small interactive checkers.TheorySection · Finite-state machines, automata and the mathematical semantics of programming languages, explained from first principles.ML mathsSection · Gradient descent, vectors and embeddings, softmax and cross-entropy, and attention, each with a formula, a worked numeric example and a live version.ToolsSection · A truth-table generator with CNF, DNF and LaTeX output, a graph-traversal visualiser for BFS, DFS and Dijkstra, and a recursion-tree visualiser.LaTeXSection · How to format a CS conference or workshop paper in LaTeX, a camera-ready checklist, and a minimal template you can adapt.
ML maths

Softmax and cross-entropy loss, worked through

A classifier’s last layer produces raw scores called logits. Softmax turns them into probabilities, and cross-entropy measures how much probability the model gave to the right answer. Together they are the standard output and loss for classification, and their gradient is remarkably simple: predicted minus actual.

Interactive: Editable logits with live probabilities, loss and gradientUpdated

From scores to probabilities

Suppose an image classifier with three classes outputs the logits z=(2,1,0.1)z = (2, 1, 0.1) for cat, dog and bird. Logits can be any real numbers, and we want a probability distribution: non-negative numbers that sum to 1, with larger logits getting more probability. Softmax does this by exponentiating and normalising:

softmax⁡(z)i=ezi∑jezj.\operatorname{softmax}(z)_i = \frac{e^{z_i}}{\sum_{j} e^{z_j}}.

Exponentiating makes every value positive and turns differences in logits into ratios of probabilities: if ziz_i is 1 more than zjz_j, class ii is e≈2.718e \approx 2.718 times as likely.

Worked example: z=(2,1,0.1)z = (2, 1, 0.1)

Classze^zp = e^z / Σ
cat27.38917.3891 / 11.2125 = 0.6590
dog12.71832.7183 / 11.2125 = 0.2424
bird0.11.10521.1052 / 11.2125 = 0.0986
Sum11.21251

The model puts 65.9% on cat. Check it on a calculator: e2≈7.389e^2 \approx 7.389, e1≈2.718e^1 \approx 2.718, e0.1≈1.105e^{0.1} \approx 1.105.

Useful properties

  • Adding a constant to every logit changes nothing. ezi+c/∑jezj+c=ezi/∑jezje^{z_i + c} / \sum_j e^{z_j + c} = e^{z_i} / \sum_j e^{z_j}, since ece^c cancels. Only differences between logits matter.
  • Numerical stability. That property is how softmax is computed safely. e1000e^{1000} overflows a floating-point number, so implementations subtract the largest logit first. The widget below does this; the “z / T − max” column shows the shifted values.
  • It is a soft version of argmax. The largest logit always gets the largest probability, but the others keep some, and the result changes smoothly with the logits, which is what gradient descent needs.

Temperature

Dividing the logits by a temperature T>0T > 0 before softmax controls how peaked the distribution is: pi∝ezi/Tp_i \propto e^{z_i / T}. With T=0.5T = 0.5 the example becomes (0.864, 0.117, 0.019), sharper; with T=2T = 2 it becomes (0.502, 0.304, 0.194), flatter. As T→0T \to 0 softmax approaches a one-hot argmax; as T→∞T \to \infty it approaches uniform. Language models expose temperature as a sampling setting, and a single temperature fitted after training is a simple, effective way to make a classifier’s confidence better calibrated.

Cross-entropy loss

During training we know the true class yy. The cross-entropy loss is the negative log of the probability the model assigned to it:

L=−log⁡py=−zy+log⁡∑jezj.\mathcal{L} = -\log p_y = -z_y + \log \sum_j e^{z_j}.

If the model is certain and right, py=1p_y = 1 and the loss is 0. As pyp_y shrinks the loss grows without bound, so confident mistakes are punished hard. In the example, if the image really is a cat the loss is −ln⁡-\ln 0.6590 = 0.4170; if it is a bird the loss is −ln⁡-\ln 0.0986 = 2.3170.

Why the logarithm? Minimising −log⁡py-\log p_y summed over a dataset is the same as maximising the probability the model assigns to all the correct labels together, so it is maximum-likelihood training. In information-theory terms it is the number of nats (or bits, with log⁡2\log_2) needed to encode the true label using the model’s probabilities. A model that guesses uniformly among kk classes scores ln⁡k\ln k, a useful baseline: about 1.099 for three classes.

The gradient is p − y

Write yy as a one-hot vector (1 for the true class, 0 elsewhere). Differentiating L=−zy+log⁡∑jezj\mathcal{L} = -z_y + \log \sum_j e^{z_j} with respect to ziz_i:

∂L∂zi=−[i=y]+ezi∑jezj=pi−yi.\frac{\partial \mathcal{L}}{\partial z_i} = -[i = y] + \frac{e^{z_i}}{\sum_j e^{z_j}} = p_i - y_i.

For the cat example that is (−0.3410, 0.2424, 0.0986). Gradient descent subtracts this, so it raises the logit of the true class and lowers the others, each in proportion to how much probability it wrongly holds. The gradient never explodes (every entry is between −1-1 and 1) and it vanishes only when the prediction is exactly right. This clean form is a big reason softmax and cross-entropy are always used together, and why libraries fuse them into one numerically stable function.

Softmax and cross-entropy, live

2
1
0.1

The radio button marks the true class y. The bars show the probabilities p = softmax(z / T).

Classzz / T − maxe^(·)p∂Loss/∂z = p − y

Things to try: press “All equal” to see the uniform baseline loss of ln⁡3\ln 3; press “Confidently wrong” and watch the loss climb; then drag the true class’s logit up and watch the gradient entries shrink towards zero.

Two classes: the sigmoid With two classes, softmax depends only on the difference z1−z0z_1 - z_0, and p1=1/(1+e−(z1−z0))p_1 = 1 / (1 + e^{-(z_1 - z_0)}), the logistic sigmoid. Binary cross-entropy is the same loss, and logistic regression is softmax regression with two classes.

References

  1. J. S. Bridle, “Probabilistic interpretation of feedforward classification network outputs, with relationships to statistical pattern recognition”, in Neurocomputing, NATO ASI Series F68, Springer, 1990. The paper that named softmax.
  2. C. Guo, G. Pleiss, Y. Sun and K. Q. Weinberger, “On calibration of modern neural networks”, ICML 2017. arXiv:1706.04599
  3. I. Goodfellow, Y. Bengio and A. Courville, Deep Learning, MIT Press, 2016. Section 6.2.2.