Just like random variables are characterized by distribution functions, random vectors can be characterized by distribution functions. Like distribution functions for random variables that accept a possible value, , and return a single output chance (, , etc.), distribution functions for random vectors accept a possible value of the random vector , and return a single output chance. When we work with random variables, the possible values, , are scalars. When we work with random vectors, the possible values are vectors, so the distribution functions must be functions of multiple variables. They accept vectors, .
For example:
is a scalar-valued function of bivariate inputs since it accepts vectors with two entries, and returns scalars.
is a scalar-valued function that accepts vectors with four entries.
is a vector valued function of multiple variables since it returns a vector with two entries from a vector with four entries. Every vector-valued function can be represented as a collection of scalar valued functions: . In this example, , .
We will start by focusing on the simplest case. Scalar valued function of two variables. A scalar valued function of two variables is a surface.
When working with functions on two variables, it is convention to denote the pair of input variables and the output variable so returns a height on the axis. Typically, is represented with a horizontal axis, is represented with an axis pointing out of the page (imagine, and axis pointing directly at you, perpendicular to your computer screen), and is represented with a vertical axis.
The video below illustrates a scalar-valued function of two variables. To build up the surface, first evaluate it a series of pairs. Varying the input values varies the height of the output value. Then, fill in the surface.
An example surface.
Visualizing Surfaces ...¶
Here are three distinct ways to visualize surfaces:
... Using Cross Sections¶
Suppose that is a scalar valued function on two variables. To define a cross-section, fix one of the input variables, and vary the other. For example, we can produce cross-sections by defining a new function where for some fixed value . Varying produces different cross-sections. We could call these “-cross section” since they are cross-sections produced by fixing the input , and varying the input . These are scalar valued functions of .
Visually, you can imagine each cross section as the curve produced by starting from some , then cutting the surface in the horizontal direction.
The video below shows two different cross sections of a surface. Each correspond to a different fixed value of . In this video the x-axis is oriented out of the screen.
Two example x cross sections ( and ).
We can also define “-cross sections” by fixing and varying , . As before, we get a new cross-section each time we change the value .
You can imagine each cross section as the curve produced by starting from some then cutting the surface along the axis pointing out of the screen. In the video below, the y-axis is oriented horizontally.
Two example y cross sections ( and ).
To build up the full surface, we can generate a collection of x cross sections and y cross sections. Plotting both creates a mesh, or net, whose height corresponds to the height of the surface. The mesh shown on the full surface plot in the first animation is a collection of cross sections.
Cross section plots are useful if we want to emphasize how the height of a surface varies as we vary a single coordinate at a time. They are expecially useful in probability since the cross sections of a distribution function are proportional to conditional distributions.
... Using a Heatmap¶
We can also avoid drawing in three dimensions by coloring the surface according to its height. If we assign each height a different color, then we can view the surface from above, and use the colors to read off the height of the surface at each pair. For instance, we could use a color bar that assigns blue to large positive values of , and gold to large negative values of .
The animation below starts with a cross section plot, then colors by height, and rotates to a top down view to produce a heat map.
An example heatmap.
This view is helpful since we don’t need three axes. However, it can be hard to distinguish fine details about the shape of the surface.
... Using Level Sets¶
We can also visualize surfaces by studying the collection of all inputs, , that return a fixed value. These are all points in the plane where the function returns the same value, or, where the surface attains the same height. We call these collections, level sets.
You can imagine level sets as the curve produced by intersecting with the constant function for varying . Equivalently, the level set is the curve produced by cutting the surface in two along a plane parallel to the input plane, with height on the axis.
The level set corresponding to .
Varying the height of the contour produces different level sets. Here’s a video showing how the contours change as we vary the height.
The level set varies with height.
Plotting multiple level sets, at regularly spaced heights, produces a contour plot.
Notice, if you’ve ever read a topographic map, which illustrates the elevation of land using level sets, then you’ve read a contour plot. Contour plots are very useful since they let us draw surfaces without drawing in three dimensions.
Often, the best way to visualize a surface is with a combination of a heatmap, and a contour plot. The color provides an immediate visual reference for height, while the contours provide precise visualization of the surface’s shape.
Run the code cell below to experiment with some example surfaces:
from utils_lsg import show_level_sets
show_level_sets()