Skip to content
Glacius
ProbabilityConcept reference

Expected transformed values

E[g(X)] is the probability-weighted sum of g(x) over possible values x.

On this page 7 sections
  1. Overview
  2. To find the expected value of a function g(X), apply g to each possible value first
  3. The same procedure works for a supplied cost rule
  4. In the example, E[X]=0, so (E[X])^2=0
  5. Key takeaway
  6. Sources & further reading
  7. Concept connections

01To find the expected value of a function g(X), apply g to each possible value first#

To find the expected value of a function g(X)g(X), apply gg to each possible value first. Keep its original probability as the weight.

E[g(X)]=xg(x)p(x)\begin{gathered}E[g(X)]\\=\sum_x g(x)p(x)\end{gathered}

If XX is equally likely to be 2-2 or 22, both values square to 44, giving E[X2]=4E[X^2]=4.

X is −2 or 2 with probability 1/2 each. The top number line carries those masses. Under squaring both outcomes map to 4, so the lower transformed distribution has all mass at 4. Thus E[X²]=4, while E[X]=0.X is −2 or 2 with probability 1/2 each. The top number line carries those masses. Under squaring both outcomes map to 4, so the lower transformed distribution has all mass at 4. Thus E[X²]=4, while E[X]=0.
Figure 1X is −2 or 2 with probability 1/2 each. The top number line carries those masses. Under squaring both outcomes map to 4, so the lower transformed distribution has all mass at 4. Thus E[X²]=4, while E[X]=0.
Link to this figure ↗Download SVGDownload PNG
Check your reasoning

PMF: p(1)=0.4p(-1)=0.4, p(2)=0.6p(2)=0.6. Find E[X2]E[X^2].

Show answer and explanation
2.8

Transformed values: 1,41, 4. Weighted sum: 0.4+2.4=2.80.4+2.4=2.8.

02The same procedure works for a supplied cost rule#

The same procedure works for a supplied cost rule. If g(x)=x2+1g(x)=x^2+1, compute each cost g(x)g(x), multiply by p(x)p(x), and sum.

You can work directly from the original distribution; a separate probability table for the transformed values is optional.

Check your reasoning

PMF: p(1)=0.5p(1)=0.5, p(3)=0.5p(3)=0.5. Cost is g(x)=x2+1g(x)=x^2+1. Find E[g(X)]E[g(X)].

Show answer and explanation
6

Transformed values: 2,102, 10. Weighted sum: 1+5=61+5=6.

03In the example, E[X]=0, so (E[X])^2=0#

In the example, E[X]=0E[X]=0, so (E[X])2=0(E[X])^2=0. But E[X2]=4E[X^2]=4. Squaring and averaging give different results when their order is swapped.

For a nonlinear function, transform each possible value before you average.

Check your reasoning

PMF: p(1)=0.5p(-1)=0.5, p(1)=0.5p(1)=0.5. A learner uses (E[X])2(E[X])^2. Repair the calculation of E[X2]E[X^2].

Show answer and explanation
1

Transformed values: 1,11, 1. Weighted sum: 0.5+0.5=10.5+0.5=1.

Key takeaway

Apply the function to each value before taking the weighted average.

  • Compute the expectation of a function of a discrete random variable.

Sources & further reading

  1. [1]
    Pishro-Nik, Introduction to Probability: Functions of Random VariablesPishro-Nik: Introduction to Probability · Article

Reference this concept

Link to this page, a section, or an individual figure.

Glacius. “Expected transformed values.” Math behind ML. /learn/p-lotus