Statistics/Numerical Methods/Basic Linear Algebra and Gram-Schmidt Orthogonalization
From Wikibooks, the open-content textbooks collection
Contents |
[edit] Introduction
Basically, all the sections found here can be also found in a linear algebra book. However, the Gram-Schmidt Orthogonalization is used in statistical algorithm and in the solution of statistical problems. Therefore, we briefly jump into the linear algebra theory which is necessary to understand Gram-Schmidt Orthogonalization.
The following subsections also contain examples. It is very important for further understanding that the concepts presented here are not only valid for typical vectors as tuple of real numbers, but also functions that can be considered vectors.
[edit] Fields
[edit] Definition
A set R with two operations + and * on its elements is called a field (or short (R, + , * )), if the following conditions hold:
- For all
holds 
- For all
holds α + β = β + α (commutativity) - For all
holds α + (β + γ) = (α + β) + γ (associativity) - It exist a unique element 0, called zero, such that for all
holds α + 0 = α - For all
a unique element − α, such that holds α + ( − α) = 0 - For all
holds 
- For all
holds α * β = β * α (commutativity) - For all
holds α * (β * γ) = (α * β) * γ (associativity) - It exist a unique element 1, called one, such that for all
holds α * 1 = α - For all non-zero
a unique element α − 1, such that holds α * α − 1 = 1 - For all
holds α * (β + γ) = α * β + α * γ (distributivity)
The elements of R are also called scalars.
[edit] Examples
It can easily be proven that real numbers with the well known addition and multiplication (IR, + , * ) are a field. The same holds for complex numbers with the addition and multiplication. Actually, there are not many more sets with two operations which fulfill all of these conditions.
For statistics, only the real and complex numbers with the addition and multiplication are important.
[edit] Vector spaces
[edit] Definition
A set V with two operations + and * on its elements is called a vector space over R, if the following conditions hold:
- For all
holds 
- For all
holds x + y = y + x (commutativity) - For all
holds x + (y + z) = (x + y) + z (associativity) - It exist a unique element
, called origin, such that for all
holds 
- For all
exists a unique element − v, such that holds 
- For all
and
holds 
- For all
and
holds α * (β * x) = (α * β) * x (associativity) - For all
and
holds 1 * x = x - For all
and for all
holds α * (x + y) = α * x + α * y (distributivity wrt. vector addition) - For all
and for all
holds (α + β) * x = α * x + β * x (distributivity wrt. scalar addition)
Note that we used the same symbols + and * for different operations in R and V. The elements of V are also called vectors.
Examples:
- The set IRp with the real-valued vectors (x1,...,xp) with elementwise addition x + y = (x1 + y1,...,xp + yp) and the elementwise multiplication α * x = (αx1,...,αxp) is a vector space over IR.
- The set of polynomials of degree p, P(x) = b0 + b1x + b2x2 + ... + bpxp, with usual addition and multiplication is a vector space over IR.
[edit] Linear combinations
A vector x can be written as a linear combination of vectors x1,...xn, if

with
.
Examples:
- (1,2,3) is a linear combination of
since (1,2,3) = 1 * (1,0,0) + 2 * (0,1,0) + 3 * (0,0,1) - 1 + 2 * x + 3 * x2 is a linear combination of
since 1 + 2 * x + 3 * x2 = 1 * (1 + x + x2) + 1 * (x + x2) + 1 * (x2)
[edit] Basis of a vector space
A set of vectors x1,...,xn is called a basis of the vector space V, if
- for each vector xinV exist scalars
such that
andx = ∑ αixi i - there is no subset of {x1,...,xn} such that 1. is fulfilled.
Note, that a vector space can have several bases.
Examples:
- Each vector
can be written as α1 * (1,0,0) + α2 * (0,1,0) + α3 * (0,0,1). Therefore is {(1,0,0),(0,1,0),(0,0,1)} a basis of IR3. - Each polynomial of degree p can be written as linear combination of {1,x,x2,...,xp} and therefore forms a basis for this vector space.
Actually, for both examples we would have to prove condition 2., but it is clear that it holds.
[edit] Dimension of a vector space
A dimension of a vector space is the number of vectors which are necessary for a basis. A vector space has infinitely many number of basis, but the dimension is uniquely determined. Note that the vector space may have a dimension of infinity, e.g. consider the space of continuous functions.
Examples:
- The dimension of IR3 is three, the dimension of IRp is p .
- The dimension of the polynomials of degree p is p + 1.
[edit] Scalar products
A mapping
is called a scalar product if holds for all
and α1,α2inR
- < α1x1 + α2x2,y > = α1 < x1,y > + α2 < x2,y >
- < x,α1y1 + α2y2 > = α1 < x,y1 > + α2 < x,y2 >
with 
with 
Examples:
- The typical scalar product in IRp is
.< x,y > = ∑ xiyi i
is a scalar product on the vector space of polynomials of degree p.
[edit] Norm
A norm of a vector is a mapping
, if holds
for all
and
(positive definiteness)
for all
and all 
for all
(triangle inequality)
Examples:
- The Lq norm of a vector in IRp is defined as
. - Each scalar product generates a norm by
, therefore
is a norm for the polynomials of degree p.
[edit] Orthogonality
Two vectors x and y are orthogonal to each other if < x,y > = 0. In IRp it holds that the cosine of the angle between two vectors can expressed as
.
If the angle between x and y is ninety degree (orthogonal) then the cosine is zero and it follows that < x,y > = 0.
A set of vectors x1,...,xp is called orthonormal, if
.
If we consider a basis e1,...,ep of a vector space then we would like to have a orthonormal basis. Why ?
Since we have a basis, each vector x and y can be expressed by x = α1e1 + ... + αpep and y = β1e1 + ... + βpep. Therefore the scalar product of x and y reduces to
![]() |
![]() |
![]() |
|
![]() |
|
![]() |
Consequently, the computation of a scalar product is reduced to simple multiplication and addition if the coefficients are known. Remember that for our polynomials we would have to solve an integral!
[edit] Gram-Schmidt orthogonalization
[edit] Algorithm
The aim of the Gram-Schmidt orthogonalization is to find for a set of vectors x1,...,xp an equivalent set of orthonormal vectors o1,...,op such that any vector which can be expressed as linear combination of x1,...,xp can also be expressed as linear combination of o1,...,op:
1. Set b1 = x1 and 
2. For each i > 1 set
and
, in each step the vector xi is projected on bj and the result is subtracted from xi.

[edit] Example
Consider the polynomials of degree two in the interval[ − 1,1] with the scalar product
and the norm
. We know that f1(x) = 1,f2(x) = x and f3(x) = x2 are a basis for this vector space. Let us now construct an orthonormal basis:
Step 1a: b1(x) = f1(x) = 1
Step 1b: 
Step 2a: 
Step 2b: 
Step 3a:

Step 3b:

It can be proven that
and
form a orthonormal basis with the above scalarproduct and norm.
[edit] Numerical instability
Consider the vectors x1 = (1,ε,0,0),x2 = (1,0,ε,0) and x3 = (1,0,0,ε). Assume that ε is so small that computing 1 + ε = 1 holds on a computer (see http://en.wikipedia.org/wiki/Machine_epsilon). Let compute a orthonormal basis for this vectors in IR4 with the standard scalar product < x,y > = x1y1 + x2y2 + x3y3 + x4y4 and the norm
.
Step 1a. b1 = x1 = (1,ε,0,0)
Step 1b.
with 1 + ε2 = 1
Step 2a. 
Step 2b. 
Step 3a. 
Step 3b. 
It obvious that for the vectors
- 
- 
- 
the scalarproduct
. All other pairs are also not zero, but they are multiplied with ε such that we get a result near zero.
[edit] Modified Gram-Schmidt
To solve the problem a modified Gram-Schmidt algorithm is used:
- Set bi = xi for all i
- for each i from 1 to n compute

- for each j from i + 1 to n compute

The difference is that we compute first our new bi and subtract it from all other bj. We apply the wrongly computed vector to all vectors instead of computing each bi separately.
[edit] Example (recomputed)
Step 1. b1 = (1,ε,0,0), b2 = (1,0,ε,0), b3 = (1,0,0,ε)
Step 2a.
with 1 + ε2 = 1
Step 2b. 
Step 2c. 
Step 3a. 
Step 3b. 
Step 4a. 
We can easily verify that < o2,o3 > = 0.
[edit] Application
[edit] Exploratory Project Pursuit
In the analysis of high-dimensional data we usually analyze projections of the data. The approach results from the Theorem of Cramer-Wold that states that the multidimensional distribution is fixed if we know all one-dimensional projections. Another theorem states that most (one-dimensional) projections of multivariate data are looking normal, even if the multivariate distribution of the data is highly non-normal.
Therefore in Exploratory Projection Pursuit we jugde the interestingness of a projection by comparison with a (standard) normal distribution. If we assume that the one-dimensional data x are standard normal distributed then after the transformation z = 2Φ − 1(x) − 1 with Φ(x) the cumulative distribution function of the standard normal distribution then z is uniformly distributed in the interval [ − 1;1].
Thus the interesting can measured by
with f(z) a density estimated from the data. If the density f(z) is equal to 1 / 2 < math > intheinterval < math > [ − 1;1] then the integral becomes zero and we have found that our projected data are normally distributed. An value larger than zero indicates a deviation from the normal distribution of the projected data and hopefully an interesting distribution.
[edit] Expansion with orthonormal polynomials
Let Li(z) a set of orthonormal polynomials with the scalar product
and the norm
. What can we derive about a densities f(z) in the interval [ − 1;1] ?
If
for some maximal degree I then it holds

We can also write
or empirically we get an estimator
.
We describe the term
and get for our integral

So using a orthonormal function set allows us to reduce the integral to a summation of coefficient which can be estimated from the data by plugging
in the formula above. The coefficients bi can be precomputed in advance.
[edit] Normalized Legendre polynomials
The only problem left is to find the set of orthonormal polynomials Li(z) upto degree I. We know that 1,x,x2,...,xI form a basis for this space. We have to apply the Gram-Schmidt orthogonalization to find the orthonormal polynomials. This has been started in the first example.
The resulting polynomials are called normalized Legendre polynomials. Up to a sacling factor the normalized Legendre polynomials are identical to Legendre polynomials. The Legendre polynomials have a recursive expression of the form

So computing our integral reduces to computing L0(zk) and L1(zk) and using the recursive relationship to compute the
's. Please note that the recursion can be numerically unstable!
[edit] References
- Halmos, P.R. (1974). Finite-Dimensional Vector Spaces, Springer: New York
- Persson, P.O. (2005). Introduction to Numerical Methods, Lecture 5 Gram-Schmidt




