Logo
Overview
Pearson Correlation in L2 Space

Pearson Correlation in L2 Space

Mard Mard
August 10, 2025
7 min read
index

Defining Pearson Correlation on L2L^2

Motivation

Pearson correlation sketch

(From my presentation, “Introduction to Laser Fault Injection.” The slide reads: “I was going to talk about Elliptic Curves, but if you don’t have a mathematical background, it will be very boring, and you will end up in Graduate school majoring in mathematics, lol”)

Following a RubiyaLab seminar, I had a discussion with my great friend and cryptographer Donghyeon Kim (@1s0m0rph1sm). Our conversation on side-channel attacks and Correlation Power Analysis (CPA) led him to pose an interesting thought, “I’ve heard people say that you can define the Pearson Correlation Coefficient formally within the context of an L2L^2 space”

This gave me some spark and challenge to work on during my free time, which I encountered some good papers that talk about this, and also was able to revise my knowledge on basics of Quantum computation lol!

Introduction to Pearson Correlation in Euclidean Space

In statistics, the Pearson Correlation Coefficient (PCC) is a correlation coefficient that measures linear correlation between two sets of data.

It is the ratio between the covariance of two variables and the product of their standard deviations. It is essentially a normalized measurement of the covariance, such that the result always has a value between 1-1 and 11.

For example if we have two discrete datasets X={x1,,xn}X = \{ x_1, \dots, x_n \} and Y={y1,,yn}Y = \{ y_1 , \dots, y_n \}, the sample Pearson Correlation Coefficient (PCC) is given by:

ρX,Y=(XXˉ)(YYˉ)(XXˉ)2(YYˉ)2 \rho_{X,Y} = \frac{\sum(X-\bar{X})(Y-\bar{Y})}{\sqrt{\sum(X-\bar{X})^2 \sum(Y-\bar{Y})^2}}

The formula suggests geometric interpretation. We can define centered vectors in Rn\mathbb{R}^n:

X=XXˉ X' = X- \bar{X} Y=YYˉ Y' = Y- \bar{Y}

Here, XX and YY are treated as vectors in Rn\mathbb{R}^n, and Xˉ\bar{X} and Yˉ\bar{Y} are scalar multiples of the vector of ones. With the standard Euclidean inner product A,B=AiBi\langle A, B \rangle = \sum{A_i B_i} the PCC formula can be transformed into the cosine of the angle θ\theta between these centered vectors:

ρX,Y=X,YXY=cos(θ) \rho_{X,Y} = \frac{\langle X',Y'\rangle}{\Vert X' \Vert \cdot \Vert Y' \Vert} = \cos (\theta)

This gives us some clear understanding using geometric foundation. But to generalize this concept from finite data points to continuous random variables, we have to change our perspective from finite-dimensional Euclidean space to an infinite-dimensional function space, which brings us to the Hilbert’s space.

Introduction to Hilbert’s space

A Hilbert space is a mathematical concept that generalizes the familiar notion of Euclidean space. It’s an inner product space, meaning that it’s a vector space where you can measure lengths and angles, and it’s also complete, which means all of its limit points exist within the space. This makes us able to bring topics such as geometric concepts. If we say in one paragraph, we can say that “Hilbert space is a complete complex vector space that has a scalar product”.

A Hilbert space, denoted as H\mathbb{H}, is defined by two characteristics: being a vector space with an inner product, and completeness.

To explain this smoothly, I will bring some definitions from the book “Mathematics of Quantum Computing.”

Definition: A Hilbert Space H\mathbb{H} is a

(i) complete complex vector space, that is, ψ,φH and a,bCaψ+bφH \psi, \varphi \in \mathbb{H} \space \text{and} \space a,b \in \mathbb{C} \Rightarrow a\psi + b\varphi \in \mathbb{H}

(ii) with a (positive-definite) scalar product :H×HC\langle \cdot\vert\cdot \rangle : \mathbb{H} \times \mathbb{H} \longrightarrow \mathbb{C} (ψ,φ)ψφ(\psi, \varphi) \longmapsto \langle \psi \vert\varphi \rangle such that for all φ,ψ,φ1,φ2\varphi, \psi, \varphi_{1}, \varphi_{2} ψφ=φψ\langle\psi \vert\varphi\rangle = \overline{\langle\varphi\vert\psi\rangle} ψψ0\langle \psi\vert\psi \rangle \ge 0 ψψ=0    ψ=0\langle \psi\vert\psi \rangle = 0 \iff \psi = 0 ψaφ1+bφ2=aψφ1+bψφ2\langle \psi\vert a\varphi_1 + b\varphi_2 \rangle = a\langle \psi\vert\varphi_1 \rangle + b\langle \psi\vert\varphi_2 \rangle

and this scalar product induces a norm :HR\Vert \cdot \Vert : \mathbb{H} \longrightarrow \mathbb{R} ψψψ\psi \mapsto \sqrt{\langle \psi\vert\psi \rangle} in which H\mathbb{H} is complete. If the metric defined by the norm is not complete, then H\mathbb{H} is instead known as an inner product space.

A subset HsubH\mathbb{H}_{sub} \subset \mathbb{H} which is a vector space and inherits the scalar product and the norm from H\mathbb{H} is called a sub-Hilbert space or simply a subspace of H\mathbb{H}.

L2L^2 space

IMPORTANT: To ease reading the formula we will substitute ψ\psi to ff, φ\varphi to gg.

L2L^2 is a great example of an infinite-dimensional Hilbert space. For our purposes, we consider the space of random variables ff with finite second moments (E[f2]<E[f^2] < \infty). For random variables defined over a continuous domain, the inner product is:

f,g=E[fg]=f(t)g(t)p(t)dt \langle f, g \rangle = E[fg] = \int_{-\infty}^{\infty}f(t)g(t)p(t)dt

where p(t)p(t) is the probability density function.

The length of a vector is defined as f\Vert f \Vert:

f=f,f=E[f2] \Vert f \Vert = \sqrt{ \langle f,f \rangle} = \sqrt{E[f^2]}

Reconstructing Correlation in L2L^2

Using the L2L^2 space, we can translate statistical concepts into functional analysis. Let XX and YY be two random variables in L2L^2.

The covariance of XX and YY can be defined as:

Cov(X,Y)=E[(XE[X])(YE[Y])] Cov(X,Y) = E[(X-E[X])(Y-E[Y])]

Define the centered random variables, which are also elements of L2L^2:

X=XE[X] X' = X - E[X] Y=YE[Y] Y' = Y - E[Y]

Note that E[X]=0E[X'] = 0 and E[Y]=0E[Y'] = 0.

The covariance can now be expressed as an inner product of these centered variables:

Cov(X,Y)=E[XY]=X,Y Cov(X,Y) = E[X'Y'] = \langle X',Y'\rangle

For the variance,

σX2=E[(XE[X])2]=E[(X)2] \sigma^2_X = E[(X-E[X])^2] = E[(X')^2]

So we will be able to get:

σX2=X,X \sigma^2_X = \langle X', X' \rangle

This reveals that the variance is the squared norm of the centered random variable:

σX2=X2 \sigma^2_X = \Vert X' \Vert^2

So at the end of the day, the standard deviation is the norm of the centered variable:

σX=XandσY=Y \sigma_X = \Vert X' \Vert \quad \text{and} \quad \sigma_Y = \Vert Y' \Vert

Pearson Correlation as the Cosine in L2L^2

We can now use this knowledge and glue it together. The Pearson Correlation Coefficient is the ratio of the covariance to the product of the standard deviations:

ρX,Y=Cov(X,Y)σXσY \rho_{X,Y} = \frac{Cov(X,Y)}{\sigma_X \sigma_Y}

By substituting our Hilbert space representation for each term, we can get this elegant formulation:

ρX,Y=X,YXY \rho_{X,Y} = \frac{\langle X', Y' \rangle}{\Vert X' \Vert \cdot \Vert Y' \Vert}

This is the answer to the initial question. The Pearson Correlation Coefficient is defined in the Hilbert space L2L^2 as the cosine of the angle between the centered random variables XX' and YY'.

This is a well-known property that 1ρX,Y1-1 \le \rho_{X,Y} \le 1 is an immediate and direct consequence of the Cauchy-Schwarz Inequality.

Huh????? What is this buckeroo Cauchy-Schwarz inequality? And why is this inequality an inherent property of all inner product spaces? Well, let’s get into it!

Intro to Cauchy-Schwarz Inequality

The Cauchy-Schwarz inequality states that for any two vectors uu and vv in an inner product space:

u,vuv \vert \langle u , v \rangle \vert \le \Vert u \Vert \Vert v \Vert

This isn’t an arbitrary rule; it arises directly from the axioms of the inner product itself, particularly the property of positive-definiteness, which states that the inner product of any vector with itself is non-negative (w,w0\langle w,w \rangle \ge 0).

For example, consider any two vectors u,vu, v and a real scalar tt. Now form a new vector w=utvw = u - tv. Because of the axioms, we know its squared norm must be non-negative:

utv2=utv,utv0 \Vert u - tv \Vert^2 = \langle u - tv, u - tv \rangle \ge 0

Expanding this using the properties of the inner product we saw before, we get:

u,u2tu,v+t2v,v0 \langle u,u \rangle- 2t \langle u,v \rangle + t^2 \langle v,v \rangle \ge 0

We can rewrite this with the norm notation:

v2t22u,vt+u20 \Vert v \Vert^2t^2 - 2 \langle u,v \rangle t + \Vert u \Vert^2 \ge 0

This is a quadratic polynomial in the variable tt. For this quadratic to always be non-negative, it can have at most one real root. This means its discriminant must be less than or equal to zero:

(2u,v)24(v2)(u2)0 (-2 \langle u,v \rangle)^2 - 4(\Vert v \Vert^2)(\Vert u \Vert^2) \le 0 4(u,v)24u2v2 4(\langle u,v \rangle)^2 \le 4\Vert u \Vert^2 \Vert v \Vert^2 (u,v)2u2v2 (\langle u,v \rangle)^2 \le \Vert u \Vert^2 \Vert v \Vert^2

We can take the square root of both sides which gives us the Cauchy-Schwarz inequality:

u,vuv \vert \langle u,v \rangle \vert \le \Vert u \Vert \Vert v \Vert

This shows us that the inequality is not an external fact but a direct logical consequence of the geometric structure we imposed on the vector space. If we apply this to our centered random variables XX' and YY', this guarantees:

Cov(X,Y)=X,YXY=σXσY \vert\text{Cov}(X,Y)\vert = \vert\langle X', Y' \rangle\vert \le \Vert X' \Vert \Vert Y' \Vert = \sigma_X \sigma_Y