liveBook · Manning

Projection

As explained in Fabulous Adventures in Data Structures and Algorithms

A projection is a mapping or function that selects or derives specified components or values from a structured input.

A projection maps each input to a chosen output. For a discrete distribution, it samples the underlying distribution, applies a function, and returns the mapped value. Several inputs may collapse into one output, so the projected support can be smaller. section 12.7

Projection changes more than the displayed labels: it recomputes each output’s weight by grouping all underlying inputs that map to it, summing their weights, and reducing them by their greatest common divisor. A one-value result can become a singleton distribution. section 12.7

The same operation composes naturally with other finite-distribution machinery:

  • Map die faces to categories to create an unfair categorical distribution. section 12.7
  • Form a joint distribution of independent rolls, then project each pair to its maximum, minimum, or another aggregate. section 13.5
  • Add a projection after a Cartesian product to return a derived value instead of a tuple. section 6.4

Turning six faces into three colors

Assign the six faces of a fair die the labels green, blue, red, blue, red, blue. Projection merges the six equally weighted inputs into green:1, blue:3, and red:2, producing a three-category unfair die. section 12.7

var advantage = d20.ToJoint(_ => d20)
    .Project(pair => Math.Max(pair.Item1, pair.Item2));
Console.WriteLine(advantage.ShowWeights());

Projecting the joint distribution of two d20 rolls onto their larger value models rolling with advantage; the resulting weights rise from 1 for a 1 to 39 for a 20. section 13.5

How Fabulous Adventures in Data Structures and Algorithms covers it

How deep it goes
Explains mapping, support collapse, grouped weight calculation, greatest-common-divisor reduction, and composition with joint distributions.
Examples
Uses colored die faces, roll-with-advantage maxima, Cartesian-product results, and posterior calculations from filtered joint distributions.
What it assumes
Assumes familiarity with functions, finite sequences, discrete distributions, joint distributions, and conditional probability.
What you can do after
Build projected discrete distributions and combine projections with joint distributions to model categories, maxima, minima, and sums.
How it connects
Connects projection to discrete probability distributions, categorical distributions, joint distributions, Cartesian products, and Bayesian probability.

Also explained in

Compare how 6 books explain projection →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Fabulous Adventures in Data Structures and Algorithms. The section links point to the parts of the book it draws on.