# Computation of Conditional Expectation as a random variable

I am trying to understand the following computation of the conditional expectation: $$\mathbb{E}\exp(\lambda s_i g_i g_i') = \mathbb{E}(\mathbb{E}(\exp(\lambda s_i g_i g_i')|g_i)) = \mathbb{E}\exp(\lambda^2s_i^2 g_i^2/2),$$ where $$g_i, g_i'$$ are independent standard normal random variables, $$s_i \in \mathbb{R}$$. I understand that if we treat $$g_i$$ as a given constant, the last equality simply follows from the MGF of a Gaussian variable. However, why exactly can we treat $$g_i$$ as a constant in the second term of the equality?

My definition of conditional expectation is the measure theoretical definition, where the conditional expectation is a random variable such that the integral of the conditional expectation is equal to the integration of the variable we are taking the conditional expectation for on all $$\sigma(g_i)$$-measurable sets. How does this "substituting $$g_i$$ as a constant" intuition follow from this definition?

I believe I might just be missing some basic rules of conditional expectations here.

For any non-negative measurable function $$f$$ and indepenednent random variables $$X$$ and $$Y$$ we have

$$Ef(X,Z)=\int Ef(X,t)dF_Z(t)$$

This means we can first treat $$Z$$ as constant $$t$$ , compute the expectation and then integrate w.r.t. the distribution of $$Z$$. In terms of conditional expectation this can be written as $$Ef(X,Z) =EE(f(X,Z)|Z)$$

Proof of above formula is a simple application of Fubini/Tonelli Theorem since the joint distribution of $$(X,Z)$$ is a product measure.

• This must be obvious, but why is what you are saying here solves the question? How do we apply this rule in this context? Taking $Z$ out doesn't change the fact that $Z$ is still a r.v., not a constant, right? Commented Nov 2, 2023 at 0:45
• I believe I understand the lemma that you are proving. However, how do we "pull out $g_i$" when $g_i$ is actually in a non-linear exponential function? Could you write out the computation that is happening between the lines using this lemma? Commented Nov 3, 2023 at 3:48
• Are you claiming that $\mathbb{E}(\mathbb{E}(e^{\lambda s_i g_i g_i'}|g_i)) = \mathbb{E}(g_i \mathbb{E}(e^{\lambda s_i g_i'}|g_i)) = \mathbb{E}(g_i \mathbb{E}(e^{\lambda s_i g_i'})) = RHS$? I don't think this is what you meant by "pulling out" $g_i$, right? I am still not seeing how you can use your lemma here. Commented Nov 3, 2023 at 19:16
• @PartialT I have edited my answer. Commented Nov 4, 2023 at 4:55

What happened is $$E(\exp(\lambda s_i g_i g_i') \mid g_i = x) = E(\exp(\lambda s_i x g_i') \mid g_i = x) = E(\exp(\lambda s_i x g_i')).$$ In general, if $$X$$ and $$Y$$ are independent, you can easily prove by definition of conditional expectation that $$E(f(X, Y) \mid X = x) = E(f(x, Y) \mid X = x) = E(f(x, Y)),$$ that is, $$E(f(X, Y) \mid X) = E(f(x, Y))|_{x = X}.$$
{"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 21, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "url": "https://math.stackexchange.com/questions/4798128/computation-of-conditional-expectation-as-a-random-variable", "fetch_time": 1721725037000000000, "content_mime_type": "text/html", "warc_filename": "crawl-data/CC-MAIN-2024-30/segments/1720763518029.81/warc/CC-MAIN-20240723072353-20240723102353-00768.warc.gz", "warc_record_offset": 332389301, "warc_record_length": 37325, "token_count": 842, "char_count": 2896, "score": 3.671875, "int_score": 4, "crawl": "CC-MAIN-2024-30", "snapshot_type": "latest", "language": "en", "language_score": 0.9115172028541565, "file_path": "/sailhome/yjruan/project/latent-lm/data/processed/finemath-4plus/finemath-4plus/train-00037-of-00064.parquet"}