Notes and Solutions For: Pattern Recognition by Sergios Theodoridis and Konstantinos Koutroumbas.

Download as pdf or txt
Download as pdf or txt
You are on page 1of 209

Notes and Solutions for: Pattern Recognition by

Sergios Theodoridis and Konstantinos Koutroumbas.


John L. Weatherwax

January 19, 2006


Introduction
Here youll nd some notes that I wrote up as I worked through this excellent book. Ive
worked hard to make these notes as good as I can, but I have no illusions that they are perfect.
If you feel that that there is a better way to accomplish or explain an exercise or derivation
presented in these notes; or that one or more of the explanations is unclear, incomplete,
or misleading, please tell me. If you nd an error of any kind technical, grammatical,
typographical, whatever please tell me that, too. Ill gladly add to the acknowledgments
in later printings the name of the rst person to bring each problem to my attention.
All comments (no matter how small) are much appreciated. In fact, if you nd these notes
useful I would appreciate a contribution in the form of a solution to a problem that I did
not work, a mathematical derivation of a statement or comment made in the book that was
unclear, a piece of code that implements one of the algorithms discussed, or a correction to
a typo (spelling, grammar, etc) about these notes. Sort of a take a penny, leave a penny
type of approach. Remember: pay it forward.

[email protected]
1
Classiers Based on Bayes Decision Theory
Notes on the text
Minimizing the average risk
The symbol r
k
is the expected risk associated with observing an object from class k. This
risk is divided up into parts that depend on what we then do when an object from class k
with feature vector x is observed. Now we only observe the feature vector x and not the true
class label k. Since we must still perform an action when we observe x let
ki
represent the
loss associated with the event that the object is truly from class k and we decided that it is
from class i. Dene r
k
as the expected loss when an object of type k is presented to us. Then
r
k
=
M

i=1

ki
P(we classify this object as a member of class i)
=
M

i=1

ki
_
R
i
p(x[
k
)dx,
which is the books equation 2.14. Thus the total risk r is the expected value of the class
dependent risks r
k
taking into account how likely each class is or
r =
M

k=1
r
k
P(
k
)
=
M

k=1
M

i=1

ki
_
R
i
p(x[
k
)P(
k
)dx
=
M

i=1
_
R
i
_
M

k=1

ki
p(x[
k
)P(
k
)
_
dx. (1)
The decision rule that leads to the smallest total risk is obtained by selecting R
i
to be the
region of feature space in which the integrand above is as small as possible. That is, R
i
should be dened as the values of x such that for that value of i we have
M

k=1

ki
p(x[
k
)P(
k
) <
M

k=1

kj
p(x[
k
)P(
k
) j .
In words the index i, when put in the sum above gives the smallest value when compared to
all other possible choices. For these values of x we should select class
i
as our classication
decision.
2
Bayesian classication with normal distributions
When the covariance matrices for two classes are the same and diagonal i.e.
i
=
j
=
2
I
then the discrimination functions g
ij
(x) are given by
g
ij
(x) = w
T
(x x
0
) = (
i

j
)
T
(x x
0
) , (2)
since the vector w is w =
i

j
in this case. Note that the point x
0
is on the decision
hyperplane i.e. satises g
ij
(x) = 0 since g
ij
(x
0
) = w
T
(x
0
x
0
) = 0. Let x be another point
on the decision hyperplane, then x x
0
is a vector in the decision hyperplane. Since x is a
point on the decision hyperplane it also must satisfy g
ij
(x) = 0 from the functional form for
g
ij
() and the denition of w is this means that
w
T
(x x
0
) = (
i

j
)
T
(x x
0
) = 0 .
This is the statement that the line connecting
i
and
j
is orthogonal to the decision hy-
perplane. In the same way, when the covariance matrices of each class are not diagonal but
are nevertheless the
i
=
j
= the same logic that we used above states that the decision
hyperplane is again orthogonal to the vector w which in this case is
1
(
i

j
).
The magnitude of P(
i
) relative to P(
j
) inuences how close the decision hyperplane is
to the respective class means
i
or
j
, in the sense that the class with the larger a priori
probability will have a larger region of R
l
assigned to it for classication. For example, if
P(
i
) < P(
j
) then ln
_
P(
i
)
P(
j
)
_
< 0 so the point x
0
which in the case
i
=
j
= is given
by
x
0
=
1
2
(
i
+
j
) ln
_
P(
i
)
P(
j
)
_

i

j
[[
i

j
[[
2

1
, (3)
we can write as
x
0
=
1
2
(
i
+
j
) + (
i

j
) ,
with the value of > 0. Since
i

j
is a vector from
j
to
i
the expression for x
0
above
starts at the midpoint
1
2
(
i
+
j
) and moves closer to
i
. Meaning that the amount of R
l
assigned to class
j
is larger than the amount assigned to class
i
. This is expected since
the prior probability of class
j
is larger than that of
i
.
Notes on Example 2.2
To see the nal lengths of the principal axes we start with the transformed equation of
constant Mahalanobis distance of d
m
=

2.952 or
(x

11
)
2

1
+
(x

12
)
2

2
= (

2.952)
2
= 2.952 .
Since we want the principal axis about (0, 0) we have

11
=

12
= 0 and
1
and
2
are the
eigenvalues given by solving [ I[ = 0. In this case, we get
1
= 1 (in direction v
1
) and

2
= 2 (in direction v
2
). Then the above becomes in standard form for a conic section
(x

1
)
2
2.952
1
+
(x

2
)
2
2.952
2
= 1 .
3
From this expression we can read o the lengths of the principle axis
2
_
2.952
1
= 2

2.952 = 3.43627
2
_
2.952
2
= 2
_
2.952(2) = 4.85962 .
Maximum A Posteriori (MAP) Estimation: Example 2.4
We will derive the MAP estimate of the population mean when given N samples x
k
distributed as p(x[) and a normal prior on i.e. N(
0
,
2

I). Then the estimate of the


population mean given the sample X x
k

N
k=1
is proportional to
p([X) p()p(X[) = p()
N

k=1
p(x
k
[) .
Note that we have written p() on the outside of the product terms since it should only
appear once and not N times as might be inferred by had we written the product as

N
k=1
p()p(x
k
[). To nd the value of that maximized this we take begin by taking
the natural log of the expression above, taking the derivative and setting the resulting
expression equal to zero. We nd the natural log of the above given by
ln(p()) +
N

k=1
ln(p(x
k
[)) =
1
2
[[
0
[[
2

1
2
N

k=1
(x
k
)
T

1
(x
k
) .
Then taking the derivative with respect to , setting the result equal to zero, and calling
that solution gives

(
0
) +
1

2
N

k=1
(x
k
) = 0 ,
were we have assumed that the density p(x[) is N(, ) with =
2
I. When we solve for
in the above we get
=
1

0
+
1

N
k=1
x
k
N

2
+
1

0
+

2

N
k=1
x
k
1 +

2

2
N
(4)
Maximum Entropy Estimation
As another method to determine distribution parameters we seek to maximize the entropy
H or
H =
_
X
p(x) ln(p(x))dx. (5)
This is equivalent to minimizing its negative or
_
X
p(x) ln(p(x))dx. To incorporate the con-
straint that the density must integrate to one, we form the entropy Lagrangian
H
L
=
_
x
2
x
1
p(x) ln(p(x))dx
__
x
2
x
1
p(x)dx 1
_
,
4
where we have assumed that our density is non-zero only over [x
1
, x
2
]. The negative of the
above is equivalent to
H
L
=
_
x
2
x
1
p(x)(ln(p(x)) )dx .
Taking the p(x) derivative and setting it equal to zero
(H
L
)
p
=
_
x
2
x
1
[(ln(p) ) + p
_
1
p
_
]dx
=
_
x
2
x
1
[ln(p) + 1]dx = 0 .
Solving for the integral of ln(p(x)) we get
_
x
2
x
1
ln(p(x))dx = ( 1)(x
2
x
1
) .
Take the x
2
derivative of this expression and we nd x
ln(p(x
2
)) = 1 p(x
2
) = e
1
, .
To nd the value of we put this expression into our constraint of
_
x
2
x
1
p(x)dx = 1 to get
e
1
(x
2
x
1
) = 1 ,
or 1 = ln
_
1
x
2
x
1
_
, thus
p(x) = exp
_
ln
_
1
x
2
x
1
__
=
1
x
2
x
1
,
a uniform distribution.
Problem Solutions
Problem 2.1 (the Bayes rule minimized the probability of error)
Following the hint in the book, the probability of correct classication P
c
is given by
P
c
=
M

i=1
P(x 1
i
,
i
) ,
since in order to be correct when x 1
i
the sample that generated x must come from the
class
i
. Now this joint probability is given by
P(x 1
i
,
i
) = P(x 1
i
[
i
)P(
i
)
=
__
R
i
p(x[
i
)dx
_
P(
i
) .
5
So the expression for P
c
then becomes
P
c
=
M

i=1
__
R
i
p(x[
i
)dx
_
P(
i
)
=
M

i=1
__
R
i
p(x[
i
)P(
i
)dx
_
. (6)
Since this is a sum of M dierent terms to maximize P
c
we will dene 1
i
to be the region
of x where
p(x[
i
)P(
i
) > p(x[
j
)P(
j
) j ,= i . (7)
If we do this, then since in 1
i
from Equation 7 the expression
_
R
i
p(x[
i
)P(
i
)dx will be as
large as possible. As Equation 6 is the sum of such terms we will have also maximized P
c
.
Now dividing both sides of Equation 7 and using Bayes rule we have
P(
i
[x) > P(
j
[x) j ,= i ,
as the multi-class decision boundary, what we were to show.
Problem 2.2 (nding the decision boundary)
Using the books notation where
ki
is the loss associated with us deciding an object is from
class i when it in fact is from class k we need to compare the expressions given by Equation 1.
Since this is a two class problem M = 2 and we need to compare
l
1
=
11
p(x[
1
)P(
1
) +
21
p(x[
2
)P(
2
)
l
2
=
12
p(x[
1
)P(
1
) +
22
p(x[
2
)P(
2
) .
Under zero-one loss these become
l
1
=
21
p(x[
2
)P(
2
)
l
2
=
12
p(x[
1
)P(
1
) .
When l
1
< l
2
we will classify x as from class
1
and from class
2
otherwise. The decision
boundary will be the point x
0
where l
1
= l
2
. This later equation (if we solve for the likelihood
ratio) is
p(x[
1
)
p(x[
2
)
=

21
P(
2
)

12
P(
1
)
. (8)
If we assume that p(x[
1
) A(0,
2
) and p(x[
2
) A(1,
2
) then
p(x[
1
)
p(x[
2
)
=
e

1
2
x
2

2
e

1
2
(x1)
2

2
= exp
_

1
2
1

2
(2x 1)
_
.
Setting this equal to

21
P(
2
)

12
P(
1
)
and solving for x gives
x =
1
2

2
ln
_

21
P(
2
)

12
P(
1
)
_
,
as we were to show.
6
Problem 2.3 (an expression for the average risk)
We are told to dene the errors
1,2
as the class conditional error or

1
= P(x 1
2
[
1
) =
_
R
2
p(x[
1
)dx

2
= P(x 1
1
[
2
) =
_
R
1
p(x[
2
)dx.
Using these denitions we can manipulate the average risk as
r = P(
1
)
_

11
_
R
1
p(x[
1
)dx +
12
_
R
2
p(x[
1
)dx
_
= P(
2
)
_

21
_
R
1
p(x[
2
)dx +
22
_
R
2
p(x[
2
)dx
_
= P(
1
)
_

11
_
1
_
R
2
p(x[
1
)dx
_
+
12
_
R
2
p(x[
1
)dx
_
= P(
2
)
_

21
_
R
1
p(x[
2
)dx +
22
_
1
_
R
1
p(x[
2
)dx
__
=
11
P(
1
)
11

1
P(
1
) +
12

1
P(
1
) +
12

2
P(
2
) +
22
P(
1
)
22

2
P(
2
)
=
11
P(
1
) +
22
P(
2
) + (
12

11
)
1
P(
1
) + (
12

22
)
2
P(
2
) ,
resulting in the desired expression.
Problem 2.4 (bounding the probability of error)
We desire to show that
P
e
1
1
M
.
To do this recall that since

M
i=1
P(
i
[x) = 1 at least one P(
i
[x) must be larger than
1
M
otherwise the sum

M
i=1
P(
i
[x) would have to be less than one. Now let P(
i
[x) be the
Bayes classication decision. That is
P(
i
[x) = max
i
P(
i
[x) .
From the above discussion P(
i
[x)
1
M
. From this we see that
P
e
= 1 max
i
P(
i
[x) 1
1
M
=
M 1
M
,
the desired expression.
7
Problem 2.5 (classication with Gaussians of the same mean)
Since this is a two-class problem we can use the results from the book. We compute l
12
the
likelihood ratio
l
12
=
p(x[
1
)
p(x[
2
)
=

2
2

2
1
exp
_

x
2
2
_
1

2
1

2
2
__
. (9)
and compare this to the threshold t dened by
t
P(
2
)
P(
1
)
_

21

22

12

11
_
.
Then if l
12
> t, then we classify x as a member of
1
. In the same way if l
12
< t then we
classify x as a member of
2
. The decision point x
0
where we switch classication is given
by l
12
(x
0
) = t or
exp
_

x
2
0
2
_

2
2

2
1

2
1

2
2
__
=

2
1

2
2
t .
Solving for x
0
we get
x
0
=
2
2
1

2
2
(
2
2

2
1
)
ln
_

2
1
P(
2
)

2
2
P(
1
)
_

21

22

12

11
__
.
For specic values of the parameters in this problem:
2
i
, P(
i
), and
ij
the two values for
x
0
above can be evaluated. These two values x
0
dier only in their sign and have the same
magnitude. For these given values of x
0
we see that if [x[ [x
0
[ one class is selected as
the classication decision while if [x[ > [x
0
[ the other class is selected. The class selected
depends on the relative magnitude of the parameters
2
i
, P(
i
), and
ij
and seems dicult
to determine a priori. To determine the class once we are given a xed specication of these
numbers we can evaluate l
12
in Equation 9 for a specic value of x such that [x[ [x
0
[ (say
x = 0) to determine if l
12
< t or not. If so the region of xs given by [x[ [x
0
[ will be
classied as members of class
1
, while the region of xs where [x[ > [x
0
[ would be classied
as members of
2
.
Problem 2.6 (the Neyman-Pearson classication criterion)
Warning: I was not able to solve this problem. Below are a few notes I made while
attempting it. If anyone sees a way to proceed please contact me.
For this problem we want to x the value of the error probability for class one at a particular
value say
1
= and then we want to minimize the probability of error we make when
classifying the other class. Now recall the denitions of the error probability
i

1
=
_
R
2
p(x[
1
)P(
1
)dx,
and

2
=
_
R
1
p(x[
2
)P(
2
)dx.
8
We want to nd a region 1
1
(equivalently a region 1
2
) such that
2
is minimized under the
constraint that
1
= . We can do this using the method of Lagrange multipliers. To use
this method rst form the Lagrangian q dened as
q = (
1
) +
2
.
To determine the classication decision region boundary x
0
that minimizes this Lagrangian
let 1
1
= (, x
0
) and 1
2
= (x
0
, +) to get for q
q =
_
P(
1
)
_
+
x
0
p(x[
1
)dx
_
+ P(
2
)
_
x
0

p(x[
2
)dx.
To minimized q with respect to x
0
requires taking

x
0
of the above expression and setting
this derivative equal to zero. This gives
q
x
0
= P(
1
)p(x
0
[
1
) + P(
2
)p(x
0
[
2
) = 0 .
Solving for in the above expression we see that it is given by
=
P(
2
)p(x
0
[
2
)
P(
1
)p(x
0
[
1
)
=
P(
2
[x
0
)
P(
1
[x
0
)
.
Problem 2.9 (deriving an expression for P
B
)
If P(
1
) = P(
2
) =
1
2
, then the zero-one likelihood ratio given by Equation 8 when
12
=

21
= 1, becomes
p(x[
1
)
p(x[
2
)
= 1 .
Taking logarithms of both sides of this expression gives
ln(p(x[
1
)) ln(p(x[
2
)) = 0 .
If we dene this scalar dierence as u we see that when both class condition densities are
multi-dimensional normal with the same covariance (but with dierent means
i
) that u
becomes
u ln
_
1
(2)
d/2
[[
1/2
exp
_

1
2
(x
1
)
T

1
(x
1
)
__
ln
_
1
(2)
d/2
[[
1/2
exp
_

1
2
(x
2
)
T

1
(x
2
)
__
=
1
2
(x
1
)
T

1
(x
1
) +
1
2
(x
2
)
T

1
(x
2
)
=
1
2
_
x
T

1
x 2
T
1

1
x +
T
1

1
x
T

1
x + 2
T
2

1
x
T
2

= (
1

2
)
T

1
x
1
2

1
+
1
2

T
2

2
.
9
Now if x is a sample from class
1
then from the class density assumptions and the above
expression (it is linear in x) we see that the variable u will be a Gaussian random variable
with a mean m
1
given by
m
1
= (
1

2
)
1

1
2

T
1

1
+
1
2

T
2

2
=
1
2

T
1

1
+
1
2

T
2

2
=
1
2
(
1

2
)
T

1
(
1

2
) , (10)
and a variance given by
(
1

2
)
T

1
(
1

2
) = (
1

2
)
T

1
(
1

2
) . (11)
In the same way, if x is from class
2
then u will be Gaussian with a mean m
2
given by
m
2
= (
1

2
)
1

1
2

T
1

1
+
1
2

T
2

2
=
T
1

1
2

1
2

T
2

2
=
1
2
(
1

2
)
T

1
(
1

2
) = m
1
, (12)
and the same variance as in the case when x is from
1
and given by Equation 11. Note that
in terms of the Mahalanobis distance d
m
between the means
i
dened as
d
2
m
(
1

2
)
T

1
(
1

2
) ,
we have m
1
=
1
2
d
2
m
= m
2
. Also note that the variance of p(u[
i
) given in Equation 11
in terms of the Mahalanobis distance is d
2
m
and so the common standard deviation would
be d
m
. Thus an expression for the Bayesian error probability, P
B
, for this classication
problem, can be computed based on the one-dimensional random variable u rather than the
multidimensional random variable x. Since u is a scalar expression for which we know its
probability density we can compute the probability of error for a classication procedure on
x by using us density. As just computed the densities p(u[
1
) and p(u[
2
) are Gaussian with
symmetric means (m
1
= m
2
) and equal variances so the the optimal Bayes classication
threshold value (where classication decisions change) is 0. This makes it easy to calculate
P
B
the optimal Bayes error estimate using
P
B
=
_
0

p(u[
1
)P(
1
)du +
_

0
p(u[
2
)P(
2
)du .
Since P(
1
) = P(
1
) =
1
2
, and the integrals of the conditional densities are equal (by
symmetry) we can evaluate just one. Specically, from the discussion above we have
p(u[
1
) =
1

2d
m
exp
_

1
2
_
u
1
2
d
2
m
d
m
__
,
and we nd
P
B
=
1

2
1
d
m
_
0

1
2

u
1
2
d
2
m
dm

du .
10
Let z =
u
1
2
d
2
m
dm
so dz =
1
dm
du and P
B
becomes
P
B
=
1

2
d
m
d
m
_

1
2
dm

z
2
2
dz =
1

2
_
+
1
2
dm
e

z
2
2
dz , (13)
the result we were to show. Using the cumulative distribution function for the standard
normal, denoted here in the notation of the Matlab function, normcdf, dened as
normcdf(x; , ) =
1

2
_
x

1
2
(t)
2

2
dt , (14)
we can write the above expression for P
B
as
P
B
= 1 normcdf
_
1
2
d
m
; 0, 1
_
, (15)
which is easier to implement in Matlab.
Problem 2.10-11 (Mahalanobis distances and classication)
Taking the logarithm of the likelihood ratio l
12
gives a decision rule to state x
1
(and
x
2
otherwise) if
ln(p(x[
1
)) ln(p(x[
2
)) > ln() . (16)
If our conditional densities, p(x[
i
), are given by a multidimensional normal densities then
they have functional forms given by
p(x[
i
) = A(x;
i
,
i
)
1
(2)
d/2
[
i
[
1/2
exp
_

1
2
(x
i
)
t

1
i
(x
i
)
_
. (17)
Taking the logarithm of this expression as required by Equation 16 we nd
ln(p(x[
i
)) =
1
2
(x
i
)
t

1
i
(x
i
)
d
2
ln(2)
1
2
ln([
i
[)
=
1
2
d
m
(
i
, x[
i
)
2

d
2
ln(2)
1
2
ln([
i
[) ,
where we have introduced the Mahalanobis distance d
m
in the above. Our decision rule given
by 16 in the case when p(x[
i
) is a multidimensional Gaussian is thus given by

1
2
d
m
(
1
, x[
1
)
2

1
2
ln([
1
[) +
1
2
d
m
(
2
, x[
2
)
2
+
1
2
ln([
2
[) > ln() .
or
d
m
(
1
, x[
1
)
2
d
m
(
2
, x[
2
)
2
+ ln
_
[
1
[
[
2
[
_
< 2 ln() . (18)
We will now consider some specializations of these expressions for various possible values of

i
. If our decision boundaries are given by Equation 18, but with equal covariances, then we
have that ln
_
|
1
|
|
2
|
_
= 0 and for decision purposes the left-hand-side of Equation 18 becomes
d
m
(
1
, x[
1
)
2
d
m
(
2
, x[
2
)
2
=
_
x
T

1
x 2x
T

1
+
T
1

1
_

_
x
T

1
x 2x
T

2
+
T
2

2
_
= 2x
T

1
(
1

2
) +
T
1

2
.
11
Using this in Equation 18 we get
(
1

2
)
T

1
x > ln() +
1
2
[[
1
[[
2

1
1
2
[[
2
[[
2

1 , (19)
for the decision boundary. I believe the book is missing the square on the Mahalanobis norm
of
i
.
Problem 2.12 (an example classier design)
Part (a): The optimal two class classier that minimizes the probability of error is given
by classifying a point x depending on the value of the likelihood ratio
l
12
=
p(x[
1
)
p(x[
2
)
.
When the class conditional probability densities, p(x[
i
), are multivariate Gaussian with
each feature dimension having the same variance
2
1
=
2
2
=
2
the above likelihood ratio l
12
becomes
l
12
= exp
1
2
2
((x
1
)
T
(x
1
) (x
2
)
T
(x
2
)) .
The value of l
12
is compared to an expression involving the priori probabilities P(
i
), and
loss expressions,
ki
, where

ki
is the loss associated with classifying an object from the true class k as an object
from class i.
The classication decision is then made according to
x
1
if l
12
=
p(x[
1
)
p(x[
2
)
>
P(
2
)
P(
1
)
_

21

22

12

11
_
, (20)
and x
2
otherwise. To minimize the error probability requires we take
ki
= 1
ki
where
ki
is the Kronecker delta. In this case, and when the priori probabilities are equal the
constant on the right-hand-side of Equation 20 evaluates to 1. Thus our classication rules
is to select class 1 if l
12
> 1 and otherwise select class 2. This rule is equivalent to select
x
1
if p(x[
1
) > p(x[
2
). Using the above expression the decision rule l
12
> 1 simplies
as follows
(x
1
)
T
(x
1
) (x
2
)
T
(x
2
) < 0 or
2(
1

2
)
T
x <
T
2

T
1

1
or
(
1

2
)
T
x >

T
1

T
2

2
2
.
This is equivalent to Equation 19 when we take = 1 and equal features covariances.
12
Part (b): In this case, from the given loss matrix, , we see that
11
= 0,
12
= 1,
21
= 0.5,

22
= 0 and the right-hand-side of Equation 20 becomes
1
2
. Then the requirement on the
likelihood ratio is then l
12
>
1
2
, which when we take the logarithm of both sides becomes

1
2
2
[(x
1
)
T
(x
1
) (x
2
)
T
(x
2
)] > ln(2) ,
which simplies in exactly the same was as before to
(
1

2
)
T
x >

T
1

T
2

2
2
+
2
ln(2) .
Experiments at generating and classifying 10000 random feature vectors from each class
using the previous expressions and then estimating the classication error probability can
be found in the Matlab script chap 2 prob 12.m. For Part (a) we can also use the results
of Problem 2.9 on Page 9 namely Equation 15 to exactly compute the error probability P
B
and compare it to our empirically computed error probability. When we run that script we
get the following results
empirical P_e= 0.215950; analytic Bayes P_e= 0.214598
showing that the empirical results are quite close to the theoretical. For Part (b) we can
compute the empirical loss associated with using this classier in the following way. Let
L
12
be the number of samples from the rst class that are misclassied as belonging to the
second class, L
21
be the number of samples from the second class that are misclassied as
belonging to the rst class, and N be the total number of samples we classied. Then an
empirical estimate of the expected loss r given by
r =
L
12
+ 0.5L
21
N
.
Problem 2.13 (more classier design)
Note that since for this problem since the functional form of the class conditional densities,
p(x[
i
), have changed, to construct the decision rule in terms of x as we did for Problem 2.12,
we would need to again simplify the likelihood ratio expression Equation 20. If all we care
about is the classication of a point x we can skip these algebraic transformations and simply
compute l
12
=
p(x|
1
)
p(x|
2
)
, directly and then compare this to the simplied right-hand-sides of
Equation 20, which for Part (a) is 1 and for Part (b) is
1
2
. Again for Part (a) we can exactly
compute the Bayes error rate using Equation 15. This procedure is implemented in Matlab
script chap 2 prob 13.m. When we run that script we get
empirical P_e= 0.374650; analytic Bayes P_e= 0.373949
again showing that the empirical results are quite close to the theoretical.
13
Problem 2.14 (orthogonality of the decision hyperplane)
We want to show that the decision hyperplane at the point x
0
is tangent to the constant
Mahalanobis distance hyperellipsoid d
m
(x,
i
) = c
i
. If we can show that the vector v dened
by
v
d
m
(x,
i
)
x

x=x
0
.
is orthogonal to all vectors in the decision hyperplane, then since v is normal to the surfaces
d
m
(x,
i
) = c
i
, we will have a tangent decision hyperplane. The Mahalanobis distance
between
i
and a point x is given by
d
m
(
i
, x) =
_
(x
i
)
T

1
(x
i
)
_
1/2
.
The gradient of d
m
(
i
, x) considered as a function of x is given by
d
m
(
i
, x)
x
=
1
2
_
(x
i
)
T

1
(x
i
)
_
1/2
x
_
(x
i
)
T

1
(x
i
)
_
=
1
2
(d
2
m
)
1/2
_
2
1
(x
i
)
_
=
1
d
m
(
i
, x)

1
(x
i
) .
Consider this expression evaluated at x = x
0
, we would have to evaluate x
0

i
. From the
expression for x
0
this is
x
0

i
=
1
2
(
i
+
j
) ln
_
P(
i
)
P(
j
)
_

i

j
[[
i

j
[[

1
,
which is a vector proportional to
i

j
. Thus we see that for a point x on the decision
hyperplane we have that
v
T
(x x
0
) =
1
d
m
(
i
, x
0
)
_

1
(x
0

i
)
_
T
(x x
0
)

1
(
i

j
)
_
T
(x x
0
) = 0 ,
since for the case of multidimensional Gaussians with equal non-diagonal covariance matrices,
, the points x on the decision hyperplanes are given by
g
ij
(x) =
_

1
(
i

j
)
_
T
(x x
0
) = 0 .
The decision hyperplane is also tangent to the surfaces d
m
(x,
j
) = c
j
. Since to show that
we would then need to evaluate
1
dm(
j
,x)

1
(x
j
) at x = x
0
and we would again nd that
x
0

j
is again proportional to
i

j
.
Problem 2.15 (bounding the probability of error)
We are told to assume that
p(x[
1
) A(,
2
)
p(x[
2
) |(a, b) =
_
1
ba
a < x < b
0 otherwise
14
The minimum probability of error criterion is to classify a sample with feature x as a member
of the class
1
if
p(x[
1
)
p(x[
2
)
>
P(
2
)
P(
1
)
,
and classify x as from the class
2
otherwise. Since p(x[
2
) is zero for some values of x we
should write this expression as
p(x[
1
) >
P(
2
)
P(
1
)
p(x[
2
) .
Note that from the above if x / [a, b] since p(x[
2
) = 0 the above expression will be true
and we would classify that point as from class
1
. It remains to determine how we would
classify any points x [a, b] as. Since p(x[
2
) is a uniform distribution the above inequality
is given by
p(x[
1
) >
P(
2
)
P(
1
)
1
b a
. (21)
Given that the density p(x[
1
) is a Gaussian we can nd any values x
0
such that the above
inequality is an equality. That is x
0
must satisfy
1

2
e

1
2
(x
0
)
2

2
=
P(
2
)
P(
1
)
1
b a
.
When we solve for x
0
we nd
x
0
=

_
2 ln
_

2
b a
P(
2
)
P(
1
)
_
. (22)
There are at most two real solutions for x
0
in the above expression which we denote by
x

0
and x
+
0
, where x

0
< x
+
0
. Depending on the dierent possible values of x

0
and x
+
0
we
will evaluate the error probability P
e
. If neither x

0
and x
+
0
are real then the classication
decision regions in this case become
1
1
= (, a) (b, +)
1
2
= (a, b) .
Then P
e
is given by
P
e
= P(
1
)
_
R
2
p(x[
1
)dx + P(
2
)
_
R
1
p(x[
2
)dx
= P(
1
)
_
b
a
p(x[
1
)dx <
_
b
a
p(x[
1
)dx, (23)
since
_
R
1
p(x[
2
)dx = 0 for the 1
1
region.
Next consider the case where x

0
are both real. From the expression for x
0
given by Equa-
tion 22 this means that
ln
_

2
b a
P(
2
)
P(
1
)
_
> 0 ,
15
or
1

2
>
P(
2
)
P(
1
)
1
b a
.
What we notice about this last expression is that it is exactly Equation 21 evaluated at
x = . Since (x

0
, x
+
0
) this means that all points in the range (x

0
, x
+
0
) are classied as
belonging to the rst class. Thus we have shown that in the case when x

0
are both real we
have
1
1
= (, a) (b, +) (x

0
, x
+
0
)
1
2
= (a, b) (x

0
, x
+
0
) .
With these regions P
e
is given by
P
e
= P(
1
)
_
R
2
p(x[
1
)dx + P(
2
)
_
R
1
p(x[
2
)dx
= P(
1
)
_
(a,b)\(x

0
,x
+
0
)
p(x[
1
)dx + P(
2
)
_
(a,b)(x

0
,x
+
0
)
p(x[
2
)dx.
Now for any x between x

0
and x
+
0
we have argued using Equation 21 that P(
1
)p(x[
1
) >
P(
2
)p(x[
2
) and thus we can bound the second term above as
P(
2
)
_
(a,b)(x

0
,x
+
0
)
p(x[
2
)dx P(
1
)
_
(a,b)(x

0
,x
+
0
)
p(x[
1
)dx.
Thus the above expression for P
e
is bounded as
P
e
P(
1
)
_
(a,b)\(x

0
,x
+
0
)
p(x[
1
)dx + P(
1
)
_
(a,b)(x

0
,x
+
0
)
p(x[
1
)dx
= P(
1
)
_
b
a
p(x[
1
)dx <
_
b
a
p(x[
1
)dx.
This last expression is exactly like the bound presented for P
e
in Equation 23. The next step
is to simplify the expression
_
b
a
p(x[
1
)dx. Since p(x[
1
) is A(,
2
) to evaluate this integral
we make the change of variable from x to z dened as z =
x

to get
_
b
a
p(x[
1
)dx =
_ b

2
e

1
2
z
2
dz
=
_ b

2
e

1
2
z
2
dz
_ a

2
e

1
2
z
2
dz
= G
_
b

_
G
_
a

_
,
the expression we were to show.
16
Problem 2.16 (the mean of the expression
ln(p(x;))

)
We compute this directly
E
_
ln(p(x; ))

_
= E
_
1
p(x; )
p(x; )

_
=
_ _
1
p(x; )
p(x; )

_
p(x; )dx =
_
p(x; )

dx
=

_
p(x; )dx =

1 = 0 ,
as claimed.
Problem 2.17 (the probability of ipping heads)
We have a likelihood (probability) for the N ips given by
P(X; q) =
N

i=1
q
x
i
(1 q)
1x
i
.
The loglikelihood of this expression is then
L(q) ln(P(X; q)) =
N

i=1
(x
i
ln(q) + (1 x
i
) ln(1 q)) .
To nd the ML estimate for q, we will maximize ln(P(X; q)) as a function of q. To do this
we compute
dL
dq
=
N

i=1
_
x
i
q

1 x
i
1 q
_
= 0 .
When we solve for q in the above we nd
q =
1
N
N

i=1
x
i
.
Problem 2.18 (the Cramer-Rao bound)
When we consider the ML estimate of the mean of a Gaussian multidimensional random
variable with known covariance matrix we are lead to consider the loglikelihood L() given
by
L() =
N
2
ln((2)
l
[[)
1
2
N

k=1
(x
k
)
T

1
(x
k
) , (24)
17
with l = 1 and =
2
we have the loglikelihood, L(), given by
L() =
N
2
ln(2
2
)
1
2
N

k=1
(x
k
)
2

2
.
To discuss the Cramer-Rao lower bound we begin with the assumption that we have a density
for our samples x that is parametrized via the elements of a vector such that x p(x; ).
We then consider any unbiased estimator of these density parameters, , denoted as

. If
the estimator is unbiased, the Cramer-Rao lower bound then gives us a lower bound on the
variance of this estimator. The specic lower bound on the variance of

is given by forming
the loglikelihood
L() ln
_
N

k=1
p(x
i
; )
_
,
and then taking the expectation over partial derivatives of this expression. Namely, construct
the Fisher Matrix which has i, jth element given by
J
ij
E
_

2
L()

j
_
.
Then the variance of the

i
must be larger than the value of J
1
ii
. As an equation this
statement is that
E[(

i
)
2
] J
1
ii
.
If we happen to nd an estimator

i
where the above inequality is satised as an equality
then our estimator is said to be ecient.
From the above discussion we see that we need to evaluate derivatives of L with respect
to the parameters of the density. We nd the rst two derivatives of this expression with
respect to are given by
L

=
1

2
N

k=1
(x
k
)

2
L

2
=
1

2
N

k=1
1 =
N

2
.
Thus we get
E
_

2
L

2
_
=
N

2
=
1

2
N
=
1
var(
ML
)
.
Since we have shown that E
_

2
L

2
_
=
1
ML
the ML estimator for the mean
ML
is ecient.
Now consider the case where the unknown parameter of our density is the variance
2
then
we have
L

2
=
N
2
1

2
+
1
2
N

k=1
(x
k
)
2
(
2
)
2

2
L
(
2
)
2
=
N
2
1
(
2
)
2

N

k=1
(x
k
)
2
(
2
)
3
.
18
Recall that E[(x
k
)
2
] =
2
since x
k
N(,
2
) and we can evaluate the expectation of
the second derivative of L with respect to
2
as
E
_

2
L
(
2
)
2
_
=
N
2
1
(
2
)
2

N

k=1

2
(
2
)
3
=
N
2
1
(
2
)
2
.
Thus
E
_

2
L
(
2
)
2
_
=
N
2
1
(
2
)
2
=
1
(
2
)
2
N/2
.
To consider whether the ML estimator of the variance is ecient (i.e. satised the Cramer-
Rao lower bound) we need to determine if the above expression is equal to
1
var(

2
ML
)
.
Then from Problem 2.19 below the ML estimator of
2
in the scalar Gaussian case is given
by

2
ML
=
1
N
N

i=1
(x
i

ML
)
2
,
where
ML
is the ML estimate of the mean or
1
N

N
k=1
x
k
. Then it can be shown
1
that

2
ML
has a chi-squared distribution with N 1 degrees of freedom, in the sense that

2
ML


2
N

2
N1
Thus since the expectation and variance of a chi-squared distribution with N 1 degrees of
freedom is N 1 and 2(N 1) respectively we have that
E[

2
ML
] =

2
N
(N 1) =
N 1
N

2
var(

2
ML
) =

4
N
2
2(N 1) =
2(N 1)
N
2

4
.
From the given expression for var(

2
ML
) we see that
1
var(

2
ML
)
,= E
_

2
L
(
2
)
2
_
,
and thus the ML estimate of
2
is not ecient.
Problem 2.19 (ML with the multidimensional Gaussian)
We recall that the probability density function for the multidimensional Gaussian is given
by
p(x[, ) =
1
(2)
l/2
[[
1/2
exp
1
2
(x )
t

1
(x ) .
1
http:en.wikipedia.orgwikiNormal distribution
19
So the loglikelihood L when given N samples from the above distribution is given by
L = ln(
N

k=1
p(x
k
[, )) =
N

k=1
ln(p(x
k
[, )) .
The logarithm of the probability density function for a multidimensional Gaussian is given
by
ln(p(x
k
[, )) =
1
2
(x )
t

1
(x )
1
2
ln((2)
d
[[) ,
so that the above becomes
L =
1
2
N

k=1
(x
k
)
t

1
(x
k
)
N
2
ln((2)
d
[[) .
To evaluate the maximum likelihood estimates for and we would notionally take the
derivative with respect to these two parameters, set the resulting expression equal equal to
zero, and solve for the parameters. To do this requires some vector derivatives. Remem-
bering that

x
x
t
Mx = (M + M
t
)x,
we see that the derivative of L with respect to is given by
L

=
N

k=1

1
(x
k
) = 0 ,
since
1
is a symmetric matrix. On multiplying by the covariance matrix on both sides
of the above we have
N

k=1
x
k
N = 0 or =
1
N
N

k=1
x
k
.
So the maximum likelihood estimate of is just the sample mean as claimed. To evaluate the
maximum likelihood estimate for , we begin by instead computing the maximum likelihood
estimate for
1
. In terms of M
1
we have L given by
L(M) =
1
2
N

k=1
(x
k
)
t
M(x )
N
2
ln((2)
d
) +
N
2
ln([M[) .
To evaluate the derivative of the above it is helpful to recall two identities regarding matrix
derivatives. The rst involves the logarithm of the determinant and is
ln([M[)
M
= (M
1
)
t
= (M
t
)
1
= M
1
,
since M and M
1
are both symmetric. The second involves the matrix derivative of scalar
form x
t
Mx. We recall that

M
(a
t
Mb) = ab
t
.
Using these two identities we have that the M derivative of L is given by
L
M
=
1
2
N

k=1
(x
k
)(x
k
)
t
+
N
2
M
1
.
20
When we set this equal to zero and then solve for M
1
we get
M
1
=
1
N
N

k=1
(x
k
)(x
k
)
t
.
Since M
1
= and we evaluate at the maximum likelihood solution given above, the
previous expression is what we were to show.
Problem 2.20 (the ML estimate in an Erlang distribution)
The likelihood function for given the N measurements x
i
from the Erlang distribution is
P(X; ) =
N

i=1

2
x
i
e
x
i
u(x
i
) .
Since u(x
i
) = 1 for all i this factor is not explicitly needed. From this expression the
loglikelihood of X is given by
L() ln(P(X; )) =
N

i=1
(2 ln() + ln(x
i
) x
i
)
= 2 ln()N +
N

i=1
ln(x
i
)
N

i=1
x
i
.
To nd this maximum of this expression we take the derivative with respect to , set the
expression to zero, and solve for . We nd
dL
d
= 0 ,
means
2N

i=1
x
i
= 0 .
Which has a solution for given by
=
2N

N
i=1
x
i
,
as we were to show.
Problem 2.21 (the ML estimate occurs at a maximum)
When we consider the ML estimate of the mean of a Gaussian multidimensional random
variable with known covariance matrix we are lead to consider the loglikelihood L() given
21
by Equation 24. We have shown that the rst derivative of L() with respect to is given
by
L()

=
1
N

k=1
(x
k
) =
1
N

k=1
x
k
N
1
.
The second derivative of L() with respect to is then

2
L()

2
= N
1
.
Since the matrix is positive denite, we have that
1
is positive denite, and so N
1
is negative denite. That the matrix second derivative is negative denite is the condition
for the solution to
L()

= 0 to be a maximum of the objective function L().


Problem 2.22 (p(x[X) is normal with a given mean and covariance)
We assume that once we know the mean the sample x is drawn from p(x[) A(,
2
)
and that the true mean is random itself and given by a random draw from another normal
distribution p() A(
0
,
2
0
). Then using Bayes rule we can compute what the a posteriori
distribution of is after having observed the data set X as
p([X) =
p(X[)p()
p(X)
.
As a function of the expression p(X) is a constant. Assuming independence of the data
samples x
i
in X we conclude
p(X[) =
N

k=1
p(x
k
[) .
Thus combining all of these expressions we see that
p([X) = p()
N

k=1
p(x
k
[)
=
_
1

2
0
exp
_

1
2
(
0
)
2

2
0
__
N

k=1
_
1

2
exp
_

1
2
(x
k
)
2

2
__
=

exp
_

1
2
_
N

k=1
_

2

2x
k

2
+
x
2
k

2
_
+

2
2
0
+
2
0

2
0
__
=

exp
_

1
2
_

2
N

2

2

2
N

k=1
x
k
+
1

2
N

k=1
x
2
k
+

2

2
0
2

2
0
+

2
0

2
0
__
=

exp
_

1
2
_
_
N

2
+
1

2
0
_

2
2
_
1

2
N

k=1
x
k
+

0

2
0
_

__
. (25)
Note that we have written p() on the outside of the product terms since it should only
appear once and not N times as might be inferred by had we written the product as
22

N
k=1
p()p(x
k
[). From Equation 25 we see that the density p([X) is Gaussian, due to
the quadratic expression for in the argument of the exponential To nd the values of the
mean and variance of this Gaussian dene
2
N
to be such that
1

2
N
=
N

2
+
1

2
0

2
N
=
1
N

2
+
1

2
0
=

2

2
0
N
2
0
+
2
, (26)
Now dening x as
1
N

N
k=1
x
k
and take
N
as the value that makes the ratio
N
/
2
N
equal
to the coecient of in the argument of the exponential above or

2
N
=
N x

2
+

0

2
0
,
or solving for
N
we get

N
=
_

2

2
0
N
2
0
+
2
__
N x

2
+

0

2
0
_
=
N x
2
0
+
0

2
N
2
0
+
2
=
_
N
2
0
N
2
0
+
2
_
x +

2
N
2
0
+
2

0
.
Once we have dened these variables we see that p([X) is given by
p([X) =

exp
_

1
2
_

2
N

2
N

2
N
__
=

exp
_

1
2
_

2
2
N
+
2
N

2
N
__
=

exp
_

1
2
(
N
)
2

2
N
_
,
showing that p([X) is a Gaussian with mean
N
and variance
2
N
. Next we are asked to
compute p(x[X) where using the above expression for p([X) we nd
p(x[X) =
_
p(x, [X)d
=
_
p(x[, X)p([X)d =
_
p(x[)p([X)d
=
_

_
1

2
e

1
2
(x)
2

2
_
_
1

2
N
e

1
2
(x
N
)
2

2
N
_
d
=
1
2
N
_

exp
_

1
2
_
x
2
2x +
2

2
+

2
2
N
+
2
N

2
N
__
d.
Grouping terms in the argument of the exponent gives the expression

1
2
__
1

2
N
+
1

2
_

2
2
_
x

2
+

N

2
N
_
+
_
x
2

2
+

2
N

2
N
__
.
In prob 2 22 integration.nb we integrate the above to get
p(x[X) =
1
2
N
_
_

2
1
_
1

2
+
1

2
N
e

1
2
(x
N
)
2

2
+
2
N
_
_
=
1

2
_

2
+
2
N
e

1
2
(x
N
)
2

2
+
2
N
,
23
or a Gaussian distribution with mean
N
and variance
2
+
2
N
.
Problem 2.23 (the MAP estimate of for a Rayleigh distribution)
The likelihood of observing all N measurements x
i
from a normal A(,
2
), where is from
a Rayleigh distribution probability density function is given by
l() =
_
N

i=1
p(x
i
[,
2
)
_
p() ,
where p() is the Rayleigh density p() =
exp(
2
/(2
2

))

. Then the loglikelihood becomes


L() = ln(l()) = ln(p()) +
N

i=1
ln(p(x
i
[,
2
))
= ln()

2
2
2

ln(
2

) +
N

i=1
_
ln(
1

2
)
(x
i
)
2
2
2
_
= ln()

2
2
2

ln(
2

) + N ln(
1

2
)
1
2
2
N

i=1
(x
i
)
2
.
Now to maximize L() take the derivative with respect to , set the result equal to zero and
solve for . We nd
dL
d
=
1

+
1

2
N

i=1
(x
i
) = 0 .
or
_
1

+
N

2
_

_
1

2
_
_
1
N
N

i=1
x
i
_
1 = 0 .
Dening the coecient of
2
to be R and the coecient of to be Z we have using the
quadratic equation that the ML solution for is given by
=
Z

Z
2
+ 4R
2R
=
Z
2R
_
1
_
1 +
4R
Z
_
,
the desired result since we must take the positive sign in the above expression since > 0.
Problem 2.24 (ML with the lognormal distribution)
For the lognormal distribution the density is given by
p(x) =
1
x

2
exp
_

(ln(x) )
2
2
2
_
x > 0 , (27)
24
so the loglikelihood of observing N specic samples x
i
is given by
L() =
N

i=1
ln(p(x
i
))
=
N

i=1
_
ln(x
i

2) +
(ln(x
i
) )
2
2
2
_
.
Then
dL
d
= 0 is given by
dL
d
=
N

i=1
(ln(x
i
) )

2
= 0 .
Solving for we get
=
1
N
N

i=1
ln(x
i
) .
Problem 2.25 (maximum entropy estimation of p(x) with known mean and vari-
ance)
We want to maximize
_
p(x) ln(p(x))dx subject to the following constraints
_
p(x)dx = 1
_
xp(x)dx =
_
(x )
2
p(x)dx =
2
.
This is the same as minimizing the negative of the above entropy expression. Adding the
constraints to form the Lagrangian, our constrained minimization problem becomes
H
L
=
_
p(x) ln(p(x))dx
1
__
p(x)dx 1
_

2
__
xp(x)dx
_

3
__
(x )
2
p(x)dx
2
_
.
Taking the p derivative of this expression and setting the result equal to zero gives
H
L
p
=
_
ln(p(x))dx +
_
dx
1
_
dx

2
_
xdx
3
_
(x )
2
dx = 0 .
We next solve for the expression,
_
ln(p(x))dx, and then take the derivative of the resulting
expression to get
ln(p(x)) = (1
1

2
x
3
(x )
2
) .
25
Thus p(x) is given by
p(x) = e
(1
1

2
x
3
(x)
2
)
.
We now need to evaluate the Lagrangian multipliers
1
,
2
, and
3
. To do this we use the
three known constraints which we write in terms of the known functional form for our density
p(x) as
_
e
(1
1

2
x
3
(x)
2
)
dx = 1
_
xe
(1
1

2
x
3
(x)
2
)
dx =
_
(x )
2
e
(1
1

2
x
3
(x)
2
)
dx =
2
.
We next perform the integrations on the left-hand-side of the above expressions in the Math-
ematica le prob 2 25.nb. We then solve the resulting three equations for
1
,
2
, and
3
.
When we do that we nd

1
=
1
4
ln
_
e
4
4
2

4
_
= 1
1
2
ln(2
2
)

2
= 0

3
=
1
2
2
.
Thus with these values for the form of p(x) is
p(x) = e
(1
1

3
(x)
2
)
= e

1
2
ln(2
2
)
e

(x)
2
2
2
=
1

2
e

(x)
2
2
2
,
or a Gaussian distribution, A(,
2
), as claimed.
Problem 2.26 (the derivation the EM algorithm)
Continuing the discussion in the book on the EM algorithm we will present the derivation of
the algorithm in the case where the density of our samples x
k
is given by a multidimensional
Gaussian. That is we assume that
p(x
k
[j; ) = N(x
k
[
j
, C
j
) .
Then following the book, for the E-step of the EM algorithm we take the expectation over
the unobserved sample cluster labels which we denote as P(j
k
[x
k
; (t)) as
Q(; (t)) =
N

k=1
J

j
k
=1
P(j
k
[x
k
; (t)) ln(p(x
k
[j
k
, )P
j
k
)
=
N

k=1
J

j=1
P(j[x
k
; (t)) ln(p(x
k
[j, )P
j
) . (28)
26
From the assumed form for p(x
k
[j; ), its natural logarithm is given by
ln(p(x
k
[j; )) =
1
2
ln((2)
l
[C
j
[)
1
2
(x
k

j
)
T
C
1
j
(x
k

j
) .
With this expression and dropping constants that wont change the value of the subsequent
maximization, for Q(; (t)) we get the following expression
N

k=1
J

j=1
P(j[x
k
; (t))
_

1
2
ln([C
j
[)
1
2
(x
k

j
)
T
C
1
j
(x
k

j
) + ln(P
j
)
_
.
For the M-step we maximize over the parameters
j
, C
j
and P
j
the above expression, subject
to the constraint that

j
P
j
= 1. The classical way to solve this maximization is using the
method of Lagrange multipliers. In that method we would extend Q(; (t)), creating a new
objective function Q

(; (t)), to include a Lagrange multiplier (denoted by ) to enforce


the constraint that

j
P
j
= 1 as
Q

(; (t)) =
N

k=1
J

j=1
[P(j[x
k
; (t)) ln(N(x
k
[
j
, C
j
)) + P(j[x
j
; (t)) ln(P
j
)]

_
J

j=1
P
j
1
_
. (29)
We then proceed to maximize this expression by taking derivatives with respect to the
variables
j
, C
j
, and P
j
, setting the resulting expressions equal to zero, and solving the
resulting equations for them. We begin by taking

j
of Q

(; (t)). We nd

j
Q

(; (t)) =
N

k=1
P(j[x
k
; (t))
_
1
N(x
k
[
j
, C
j
)
__

j
N(x
k
[
j
, C
j
)
_
.
The derivative required in the above is given by

j
N(x
k
[
j
, C
j
) = N(x
k
[
j
, C
j
)

j
_

1
2
(x
k

j
)
T
C
1
j
(x
k

j
)
_
=
1
2
N(x
k
[
j
, C
j
)
_
C
1
j
+ C
T
j
_
(x
k

j
)
= N(x
k
[
j
, C
j
)C
1
j
(x
k

j
) . (30)
Thus

j
Q

(; (t)) =
N

k=1
P(j[x
k
; (t))C
1
j
(x
k

j
) . (31)
Setting this expression equal to zero and solving for
j
we have

j
=

N
k=1
P(j[x
k
; (t))x
k

N
k=1
P(j[x
k
; (t))
. (32)
Next we take the derivative of Q

(; (t)) with respect to C


j
. Which we will evaluate using
the chain rule transforming the derivative with respect to C
j
into one with respect to C
1
j
.
We have

C
j
Q

(; (t)) =

C
j
1
Q

(; (t))
C
j
1
C
j
.
27
Thus if

C
j
1
Q

(; (t)) = 0, we have that



C
j
Q

(; (t)) = 0 also. From this we can look


for zeros of the derivative by looking for values of C
j
where the derivative of the inverse of
C
j
vanishes. Taking the derivative of Q

(; (t)) with respect to C


j
1
we nd

C
j
1
Q

(; (t)) =
N

k=1
P(j[x
k
; (t))

C
j
1
ln(N(x
k
[
j
, C
j
))
=
N

k=1
P(j[x
k
; (t))
_
1
N(x
k
[
j
, C
j
)
_

C
j
1
N(x
k
[
j
, C
j
) .
From which we see that as a sub problem we need to compute

C
j
1
N(x
k
[
j
, C
j
), which we
now do

C
j
1
N(x
k
[
j
, C
j
) =

C
j
1
_
1
(2)
l
[C
j
[
1/2
exp
_

1
2
(x
k

j
)
T
C
j
1
(x
k

j
)
__
=
1
(2)
l

C
j
1
_
1
[C
j
[
1/2
_
exp
_

1
2
(x
k

j
)
T
C
j
1
(x
k

j
)
_
+
1
(2)
l
1
[C
j
[
1/2

C
j
1
exp
_

1
2
(x
k

j
)
T
C
j
1
(x
k

j
)
_
,
using the product rule. To evaluate the rst derivative in the above we note that

C
j
1
_
1
[C
j
[
1/2
_
=

C
j
1
[C
j
1
[
1/2
=
1
2
[C
j
1
[
1/2

C
j
1
[C
j
1
[ ,
but using the following matrix derivative of a determinant identity

X
[AXB[ = [AXB[(X
1
)
T
= [AXB[(X
T
)
1
, (33)
with A = B = I we have

X
[X[ = [X[(X
1
)
T
and the derivative

C
j
1
_
1
|C
j
|
1/2
_
becomes

C
j
1
_
1
[C
j
[
1/2
_
=
1
2
[C
j
1
[
1/2
[C
j
1
[C
j
T
=
1
2
1
[C
j
[
1/2
C
j
.
Next using the matrix derivative of an inner product is given by

X
(a
T
Xb) = ab
T
, (34)
we have the derivative of the inner product expression

C
j
1
_

1
2
(x
k

j
)
T
C
j
1
(x
k

j
)
_
=
1
2
(x
k

j
)(x
k

j
)
T
.
28
Putting everything together we nd that

C
j
1
N(x
k
[
j
, C
j
) =
1
2
1
(2)
l
1
[C
j
[
1/2
exp
_

1
2
(x
k

j
)
T
C
j
1
(x
k

j
)
_
C
j

1
2
N(x
k
[
j
, C
j
)(x
k

j
)
T
(x
k

j
)
=
1
2
N(x
k
[
j
, C
j
)
_
C
j
(x
k

j
)(x
k

j
)
T
_
. (35)
So combining these subproblems we nally nd

C
j
1
ln(N(x
k
[
j
, C
j
)) =
1
2
_
C
j
(x
k

j
)(x
k

j
)
T
_
. (36)
Using this in the expression for

C
j
1
Q

(; (t)) = 0, we nd the equation


N

k=1
P(j[x
k
; (t))C
j

N

k=1
P(j[x
k
; (t))(x
k

j
)(x
k

j
)
T
= 0 .
Which when we solve for C
j
we nd
C
j
=

N
k=1
P(j[x
k
; (t))(x
k

j
)(x
k

j
)
T

N
k=1
P(j[x
k
; (t))
. (37)
Warning: The above has
j
meaning the old value of
j
rather than
j
(t + 1) the newly
computed value via Equation 32. Im a bit unclear hear as to whether or not this matters,
is a typo, or something else. If anyone has any information on this please contact me.
Chapter 14 of this book also discusses the expectation maximization algorithm and has an
equivalent formulation to the one above. In situations like this if we replace
j
with
j
(t +1)
we get faster convergence.
To complete a full maximization of Q

(; (t)) with we still need to determine P


j
the priori
probabilities of the k-th cluster. Setting
Q

(;(t))
P
j
= 0 gives
N

k=1
P(j[x
k
; (t))
P
j
= 0 ,
or
P
j
=
N

k=1
P(j[x
k
; (t)) .
Summing this equation over j for j = 1 to J since

J
j=1
P
j
= 1 we have
=
J

j=1
N

j=1
P(j[x
k
; (t)) .
This can be simplied by observing that
=
J

j=1
N

k=1
P(j[x
k
; (t)) =
N

k=1
J

j=1
P(j[x
k
; (t)) =
N

k=1
1 = N .
29
Where we have used the fact that P(j[x
k
; (t)) is a probability that the sample x
k
is from
cluster j. Since there are 1, 2, . . . , J clusters summing this probability gives one. Thus
P
j
=
1
N
N

k=1
P(j[x
k
; (t)) . (38)
Combining this expression with Equations 32 and 37 gives the EM algorithm.
Problem 2.27 (consistency of the counting density)
We are told that k is distributed as a binomial random variable with parameters (P, N).
This means that the probability we observe the value of k samples in our interval of length
h after N trials is given by
p(k) =
_
N
k
_
P
k
(1 P)
Nk
for 0 k N .
We desire to estimate the probability of success, P, from the measurement k via the ratio
k
N
.
Lets compute the expectation and variance of this estimate of P. The expectation is given
by
E
_
k
N
[P
_
=
1
N
E[k[P] .
Now since k is drawn from a binomial random variable with parameters (N, P), the expec-
tation of k is PN, from which we see that the above equals P (showing that our estimator
of P is unbiased). To study the conditional variance of our error (dened as e =

P P)
consider

2
e
(P) = E[(e E[e])
2
[P]
= E[
_
1
N
k P
_
2
[P] =
1
N
2
E[(k NP)
2
[P]
=
1
N
2
(NP(1 P)) =
P(1 P)
N
. (39)
In the above we have used the result that the variance of a binomial random variable with
parameters (N, P) is NP(1P). Thus we have shown that the estimator
k
N
is asymptotically
consistent.
Problem 2.28 (experiments with the EM algorithm)
See the MATLAB le chap 2 prob 28.m for an implementation of this problem. When that
code is run we get the following output
mu_true = 1.000000; 3.000000; 2.000000;
30
mu_j = 1.016347; 2.993095; 2.040666;
s2_true = 0.100000; 0.100000; 0.200000;
sigma2_j= 0.096464; 0.106047; 0.256857;
p_true = 0.250000; 0.500000; 0.250000;
P_j = 0.239808; 0.499241; 0.260951;
Note that when we run the EM algorithm, and it converges to the true solution, the actual
ordering of the elements in the estimated vectors holding the estimated values of ,
2
,
and P
j
does not have to match the ordering of the truth. Thus in the above output we
explicitly permute the order of the estimated results to make the estimates line up with the
true values.
Problem 2.30 (nearest neighbors classication)
See the MATLAB le chap 2 prob 30.m for an implementation of this problem. When that
code is run and we classify the test samples using the nearest neighbor classier and for
various numbers of nearest neighbors we get the following probability of error output
P_e 1NN= 0.360000;
P_e 2NN= 0.320000;
P_e 3NN= 0.300000;
P_e 4NN= 0.320000;
P_e 5NN= 0.310000;
P_e 6NN= 0.330000;
P_e 7NN= 0.310000;
P_e 8NN= 0.300000;
P_e 9NN= 0.260000;
P_e 10NN= 0.320000;
P_e 11NN= 0.310000;
P_B= 0.214598
It can be shown that
P
3NN
P
B
+ 3P
2
B
, (40)
and thus since P
B
0.21 we see that P
3NN
0.35275 using the above formula. This value
is in the same ballpark as the empirical value obtained above.
31
1 0.5 0 0.5 1 1.5 2 2.5 3
0
0.2
0.4
0.6
0.8
1
1.2
1.4


truth
N=32; h=0.05
N=32; h=0.2
1 0.5 0 0.5 1 1.5 2 2.5 3
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7


truth
N=256; h=0.05
N=256; h=0.2
1 0.5 0 0.5 1 1.5 2 2.5 3
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7


truth
N=5000; h=0.05
N=5000; h=0.2
Figure 1: Left: Parzen window probability density estimation with N = 32 points. Center:
Parzen window probability density estimation with N = 256 points. Right: Parzen window
probability density estimation with N = 5000 points.
Problem 2.31 (Parzen window density estimation)
Parzen window density estimation with A(0, 1) for a kernel function, , means that we take
(x) =
1

2
e

x
2
2
and then estimate our density p(x) for l dimensional features vectors using
p(x) =
1
h
l
_
1
N
N

i=1

_
x
i
x
h
_
_
. (41)
In this problem l, the dimension of the feature vectors, is 1. See the MATLAB le chap 2 prob 31.m
for an implementation of this problem. When that code is run we get the plots shown in
Figure 1. Each plot is the density estimate based on N points where N is 32, 256, or 5000
and for h given by 0.05 and 0.2.
Problem 2.32 (k nearest neighbor density estimation)
For k-nearest neighbor density estimation we approximate the true density p(x) using sam-
ples via
p(x) =
k
NV (x)
, (42)
where in this expression k and N are xed and V (x) is the volume of a sphere around
the point x such that it contains the k nearest neighbors. For 1-dimensional densities this
volume is a length. Thus the procedure we implement when given a point x where we
want to evaluate the empirical density is to
1. Find the k nearest neighbors around the point x.
32
1 0.5 0 0.5 1 1.5 2 2.5 3
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9


truth
k=32
k=64
k=256
Figure 2: k nearest neighbor density estimation with k = 32, 64, and 256 points.
2. Compute V (x) as the length between the largest and smallest points in the above set.
See the MATLAB le chap 2 prob 32.m for an implementation of this problem. When that
code is run we get the plots shown in Figure 2. Note that these density estimates seems very
noisy and this noise decreases as we take more and more neighbors.
33
Linear Classiers
Notes on the text
Notes on Linear Discriminant Functions: the derivation of d
In two-dimensions, our weight vector and feature vectors have two components so w
T
=
(w
1
, w
2
) and our discriminant function g(x) is given by
g(x) = g(x
1
, x
2
) = w
1
x
1
+ w
2
x
2
+ w
0
.
Then g(x) = 0 is a line that will intersect the x
1
axis at
x
2
= 0 w
1
x
1
+ w
0
= 0 or x
1
=
w
0
w
1
,
and the x
2
axis at
x
1
= 0 w
2
x
2
+ w
0
= 0 or x
2
=
w
0
w
2
.
Plotting a line that goes though the points (0,
w
0
w
2
) and (
w
0
w
1
, 0) and assuming w
0
< 0 gives
Figure 3.1 presented in the book. We now want to derive the expressions for d and z given
in this section. To do that lets denote P be the point on the decision line that is closest to
the origin and then d be the distance from the origin to this point P. Since P is the closest
point to (0, 0) the vector from (0, 0) to P must be orthogonal to the decision line i.e. parallel
to the vector w
T
= (w
1
, w
2
). Thus we seek to determine the value of d such that the point
that is d away from (0, 0) and in the direction of of w i.e.
d w = d
_
w
1
_
w
2
1
+ w
2
2
,
w
2
_
w
2
1
+ w
2
2
_
,
is on the discriminant line g(x
1
, x
2
) = 0. When we put in the above two components for this
point into g(x
1
, x
2
) = 0 we get that
dw
2
1
_
w
2
1
+ w
2
2
+
dw
2
2
_
w
2
1
+ w
2
2
+ w
0
= 0 .
When we solve for d in the above expression we get
d =
w
0
_
w
2
1
+ w
2
2
.
Since we are assuming that w
0
< 0 we see that d can also be written as
d =
[w
0
[
_
w
2
1
+ w
2
2
. (43)
We can also obtain this formula using similar triangles. If we note that the big triangle
with verticess (0, 0),
_

w
0
w
1
, 0
_
,
_

w
0
w
2
, 0
_
is similar to the small triangle with verticess P,
34
_

w
0
w
1
, 0
_
, and (0, 0) in that they are both right triangles and have a common acute angle
(with vertex at
_

w
0
w
1
, 0
_
). The ratio of the hypotenuse to leg of the triangle opposite the
common acute angle must be equal in both triangle or

w
0
w
1
d
=
_
_
0 +
w
0
w
1
_
2
+
_
0 +
w
0
w
2
_
2

w
0
w
2
.
When we solve this expression for d we get
d =
w
2
0
w
1
w
2
1
_
_
w
0
w
1
_
2
+
_
w
0
w
2
_
2
=
[w
0
[
_
w
2
1
+ w
2
2
,
the same expression as before.
Notes on Linear Discriminant Functions: the derivation of z
We now seek to derive the expression for z, the distance from any point not on the decision
surface to the decision surface. Let x be a point not on the decision hyperplane and then
dene z to be the distance from x to the closest point on the decision line. In the earlier part
of these notes we derived the expression for z when the point not on the decision line was
the point (0, 0). Using this it might be easier to compute the value of z if we rst translate
the decision line so that it passes thought the origin. To do that we subtract d w from every
point in the R
2
plane, where
d =
[w
0
[
_
w
2
1
+ w
2
2
and w =
_
w
1
_
w
2
1
+ w
2
2
,
w
2
_
w
1
1
+ w
2
2
_
.
Then the new coordinates, x, are then given by
x = x d w.
In the translated space where our decision surface passes though the origin the points x can
be decomposed into a component in the direction of w and in a direction perpendicular to
w which we denote w

. The vector w

has components that are related to tho of w as


w

=
_

w
2
_
w
2
1
+ w
2
2
,
w
1
_
w
1
1
+ w
2
2
_
.
Then given these two vectors we can decompose x as
x = ( w
T
x) w + ( w
T

x) w

.
Then the distance from a point x

to the line w
T
x = 0 or z will be the absolute value of
the coecient of the vector w above and (assuming it is positive meaning that x

is to the
right of the decision line) we nd
z = w
T
x

.
35
In terms of the original variables we have z given by
z = w
T
(x

d w) = w
T
x

d
=
w
1
x

1
+ w
2
x

2
_
w
2
1
+ w
2
2

[w
0
[
_
w
2
1
+ w
2
2
.
If w
0
< 0 then [w
0
[ = w
0
and the above becomes
z =
w
1
x

1
+ w
2
x

2
+ w
0
_
w
2
1
+ w
2
2
=
g(x)
_
w
2
1
+ w
2
2
.
Which is the expression we wanted to show.
Notes on the Perceptron Algorithm
If x
1
and x is misclassied by the perceptron algorithm then w
T
x < 0 so if we take

x
= 1 then the product
x
(w
T
x) > 0. If x
2
and is misclassied then the product
w
T
x > 0 so if we take
x
= +1 then
x
(w
T
x) > 0. In all cases, where a sample x is
misclassied, each term in the perceptron cost function
J(w) =

xY

x
w
T
x, (44)
is positive.
Notes on the Proof of the Perceptron Algorithm Convergence
When we begin with the gradient decent algorithm applied to the perceptron cost function
J(w) given by Equation 44. This algorithm is
w(t + 1) = w(t)
t

xY

x
x,
where Y is the set samples misclassied by the current weight vector w(t). Since the set Y
depends on the current weight vector w(t) we could indicate this with the notation Y (t) if
desired. We would like to now show that this algorithm converges to a vector that is parallel
to the optimal vector w

. A vector parallel to w

is any vector of the form w

and this is
what we subtract from w(t + 1) above to get
w(t + 1) w

= w(t) w

xY

x
x.
Then squaring both sides of the above we get
[[w(t + 1) w

[[
2
= [[w(t) w

[[
2
+
2
t
[[

xY

x
x[[
2
2
t

xY

x
(w(t) w

)
T
x.
36
Since the vector w(t) is not optimal it will misclassify some sample points. Thus the negative
of the perceptron cost function J(w) or

xY

x
w(t)
T
x is a negative number. This gives
the upper bound on [[w(t + 1) w

[[
2
of
[[w(t + 1) w

[[
2
[[w(t) w

[[
2
+
2
t
[[

xY

x
x[[
2
+ 2
t

xY

x
w
T
x.
Now since the expression only [[

xY

x
x[[
2
depends on the training data and not on the
algorithm used to compute w(t) we can introduce
2
such that

2
max
Y

[[

xY

x
x[[
2
,
thus
2
is largest possible value for the given sum. At this point we have
[[w(t + 1) w

[[
2
[[w(t) w

[[
2
+
2
t

2
+ 2
t

xY

x
w
T
x.
Since w

is a solution vector from how x is classied and the denition of


x
as discussed on
Page 36 we know that

xY

x
w
T
x < 0, since each term in the sum is negative. As with
the introduction of
2
the above sum is over training points so we can introduce as
max
Y

xY

x
w
T
x < 0 .
For any xed set Y we then have

xY

x
w
T
x < < 0 ,
by the denition of . Now since < 0 we can write = [[ and thus have

xY

x
w
T
x < = [[ ,
Using this result we thus are able to bound [[w(t + 1) w

[[
2
as
[[w(t + 1) w

[[
2
[[w(t) w

[[
2
+
2
t

2
2
t
[[ . (45)
Up to this point we have been studying the distance between w(t) and an arbitrary vector
w

that is parallel to w

. Lets now consider how the distance between w(t) and w

behaves
when =

2
2||
. Using that value in the above expression we nd that

2
t

2
2
t
[[ =
2
t

2
=
2
(
2
t

t
) ,
and the bound above become
[[w(t + 1) w

[[
2
[[w(t) w

[[
2
+
2
(
2
t

t
) .
37
1.5 1 0.5 0 0.5 1 1.5 2
1
0.5
0
0.5
1
1.5
2
2.5
pocket algorithm computed decision line


class 1
class 2
Figure 3: The decision surface produced when running the script pocket algorithm.m. Note
that this data is not linearly separable.
Writing out these expressions for t = 0, 1, 2, . . . gives
[[w(1) w

[[
2
[[w(0) w

[[
2
+
2
(
2
0

0
)
[[w(2) w

[[
2
[[w(1) w

[[
2
+
2
(
2
1

1
)
[[w(0) w

[[
2
+
2
(
2
0

0
) +
2
(
2
1

1
)
= [[w(0) w

[[
2
+
2
_
1

k=0

2
k

1

k=0

k
_
[[w(3) w

[[
2
[[w(2) w

[[
2
+
2
(
2
2

2
)
[[w(0) w

[[
2
+
2
_
1

k=0

2
k

1

k=0

k
_
+
2
(
2
2

2
)
[[w(0) w

[[
2
+
2
_
2

k=0

2
k

2

k=0

k
_
.
.
.
[[w(t + 1) w

[[
2
[[w(0) w

[[
2
+
2
_
t

k=0

2
k

t

k=0

k
_
. (46)
Notes on the Pocket algorithm
See the MATLAB script pocket algorithm.m for code that implements the Pocket Algo-
rithm. An example decision surface when this script is run is given in Figure 3.
38
3 2 1 0 1 2 3
3
2
1
0
1
2
3
Kesler construction computed decision line
Figure 4: The three decision lines produced when running the script dup example 3 2.m.
Duplication of Example 3.2 (Keslers construction)
See the MATLAB script dup example 3 2.m for code that duplicates the numerical results
from this example. When this code is run it produces a plot like that shown in Figure 4.
The previous command also veries that w
T
j
x
i
> w
T
k
x
i
, when x
i

j
by computing these
inner products. We nd
class= 1; w1^T x= 11.4449; w2^T x= -4.5025; w3^T x= -2.6150
class= 1; w1^T x= 21.7109; w2^T x= -7.8885; w3^T x= -6.2647
class= 1; w1^T x= 16.1638; w2^T x= -2.3232; w3^T x= -8.0956
class= 2; w1^T x= 0.3508; w2^T x= 6.6281; w3^T x= -6.2770
class= 2; w1^T x= -5.1963; w2^T x= 12.1934; w3^T x= -8.1079
class= 2; w1^T x= -0.4773; w2^T x= 14.3727; w3^T x= -13.5885
class= 3; w1^T x= 2.0070; w2^T x= -8.8611; w3^T x= 8.3461
class= 3; w1^T x= 7.5540; w2^T x= -14.4264; w3^T x= 10.1771
class= 3; w1^T x= -2.7120; w2^T x= -11.0404; w3^T x= 13.8267
verifying that indeed we are correctly classifying all of the training data.
Notes on Mean Square Error Estimation
Consider the objective function J(w) given by
J(w) = E[[y x
T
w[
2
] ,
where the expectation in the above is taken with respect to the joint density (X, Y ). To
evaluate this we will use the idea of iterated expectation where
E[X] = E[E[X[Y ]] .
39
Since the Y variable is discrete Y = 1 and once Y is chosen the x density is conditional
on the value of y we have that J(w) is given by
J(w) = E[[y x
T
w[
2
]
= E
_
[y x
T
w[
2
[Y = 1

P(Y = 1) + E
_
[y x
T
w[
2
[Y = +1

P(Y = +1)
= E
_
[ 1 x
T
w[
2
[Y = 1

P(
1
) + E
_
[1 x
T
w[
2
[Y = +1

P(
2
)
= P(
1
)
_
(1 + x
T
w)
2
p(x[
1
)dx + P(
2
)
_
(1 x
T
w)
2
p(x[
2
)dx. (47)
Notes on the Multiclass Generalization
The text states lets dene y = [y
1
, . . . , y
M
] for a given vector x but does not explicitly say
how to dene it. If we assume that the sample x
j
then the vector y should be all zeros
except for a single one in the jth position. This procedure of encoding the class label as a
position in a vector is known as position encoding.
Duplication of Example 3.3
See the MATLAB script dup example 3 3.m for code that duplicates the numerical results
from this example.
Notes on support vector machines in the linearly separable case
The book discusses the motivation for the support vector machine optimization problem in
the case when the points are linearly separable. This problem is to compute the parameters,
w and w
0
of the decision hyperplane w
T
x + w
0
= 0 such that
minimize J(w)
1
2
[[w[[
2
(48)
subject to y
i
(w
T
x
i
+ w
0
) 1 for i = 1, 2, , N . (49)
This is a minimization problem with inequality constraints. The necessary conditions for its
minimum are given by the Karush-Kuhn-Tucker (KKT) conditions. To introduce these we
need to form the Lagrangian / given by
/(w, w
0
, ) =
1
2
w
T
w
N

i=1

i
[y
i
(w
T
x
i
+ w
0
) 1] . (50)
Then the KKT conditions for the above problem are:

L
w
= 0 and
L
w
0
= 0.
40

i
0 for i = 1, 2, , N

i
(y
i
(w
T
x
i
+ w
0
) 1) = 0 for i = 1, 2, , N.
We now need to use these conditions to nd the optimum. One way to do this that might
work for small problems is to assume some of the constraints are active i.e.
y
i
(w
T
x
i
+ w
0
) 1 = 0 ,
for some set of is. This is equivalent to xing/determining the support vectors. Then we
solve the resulting equations for the remaining Lagrange multipliers
i
and verify that they
are in fact non-negative.
We can also solve this optimization problem if we recognize that J(w) is a strictly convex
function and apply the Wolfe Dual representation to this problem. This states that the
above minimization problem is equivalent to the following maximization problem
maximize /(w, w
0
, ) (51)
subject to
/
w
= 0 and
/
w
0
= 0 (52)
and
i
0 for i = 1, 2, , N . (53)
To use this representation we take the form for /(w, w
0
, ) given above and nd that
L
w
= 0
gives
/
w
= w
N

i=1

i
y
i
x
i
= 0 , (54)
while
L
w
0
= 0 is
/
w
0
=
N

i=1

i
y
i
= 0 . (55)
Putting these two constraints given by Equation 54 and 55 into Equation 50 we nd
/ =
1
2
_
N

i=1

i
y
i
x
i
_
T
_
N

i=1

i
y
i
x
i
_

i=1

i
_
y
i
N

j=1

j
y
j
x
T
j
x
i
+ y
i
w
0
1
_
=
1
2
N

i=1
N

j=1

j
y
i
y
j
x
T
i
x
j

N

i=1
N

j=1

j
y
i
y
j
x
T
j
x
i
w
0
N

i=1

i
y
i
+
N

i=1

i
=
1
2
N

i=1
N

j=1

j
y
i
y
j
x
T
i
x
j
+
N

i=1

i
, (56)
for /. We want to maximize the above expression under the two constraints on
i
that

N
i=1

i
y
i
= 0 (Equation 55) with
i
0 (Equation 53). This can be done using quadratic
programming and is an easier problem because the complicated inequality constraints from
Equation 49 have now been replaced with equality constraints via Equation 55. Once we
have computed
i
with a quadratic programming algorithm we then compute w using w =

N
i=1

i
y
i
x
i
. The computation of w
0
is done by averaging the complementary slackness
conditions or

i
[y
i
(w
T
x
i
+ w
0
) 1] = 0 for i = 1, 2, N .
41
Notes on support vector machines in the non-separable case
When the data points are non-separable the optimization problem in the separable case
changes to compute the parameters, w and w
0
of the decision hyperplane w
T
x + w
0
= 0
such that
minimize J(w, w
0
, )
1
2
[[w[[
2
+ C
N

i=1

i
(57)
subject to y
i
(w
T
x
i
+ w
0
) 1
i
for i = 1, 2, , N (58)
and
i
0 for i = 1, 2, , N . (59)
This is again a minimization problem with inequality constraints. We form the Lagrangian
/ given by
/(w, w
0
, ; , ) =
1
2
w
T
w+ C
N

i=1

i=1

i=1

i
[y
i
(w
T
x
i
+ w
0
) 1 +
i
] .
The the necessary KKT conditions for this Lagrangian are that
L
w
= 0 or
/
w
= w
N

i=1

i
y
i
x
i
= 0 , (60)
while
L
w
0
= 0 is
/
w
0
=
N

i=1

i
y
i
= 0 , (61)
while
L

i
= 0 is
/

i
= C
i

i
= 0 , (62)
for i = 1, 2, , N. Plus the conditions that the Lagrange multipliers are non-negative

i
0,
i
0 for i = 1, 2, , N and the complementary slackness conditions:

i
(y
i
(w
T
w
i
+ w
0
) 1
i
) = 0

i
= 0 for i = 1, 2, , N .
To solve this we can again apply the Wolfe dual representation which states that the above
minimization problem is equivalent to the maximization problem
maximize /(w, w
0
, ; , ) (63)
subject to
/
w
= 0 ,
/
w
0
= 0 and
/

= 0 or
w =
N

i=1

i
y
i
x
i
,
N

i=1

i
y
i
= 0 and C
i

i
= 0 ,
and
i
0 and
i
0 for i = 1, 2, , N . (64)
42
Using these constraints into the denition of / we nd
/ =
1
2
_
N

i=1

i
y
i
x
i
_
T
_
N

i=1

i
y
i
x
i
_
+ C
N

i=1

i=1
(C
i
)
i

i=1

i
y
i
_
N

j=1

j
y
j
x
T
j
_
x
i
w
0
N

i=1

i
y
i
+
N

i=1

i=1

i
=
1
2
N

i=1
N

j=1

j
y
i
y
j
x
T
i
x
j
+
N

i=1

i
, (65)
which is another quadratic programming problem to be maximized over the vectors of La-
grangian multipliers
i
and
i
. Since the elements
i
dont appear in the Wolfe dual objective
function above the maximization takes place over the variable
i
alone just as in the separa-
ble case above. What changes however is to recognize that the constraints C
i

i
= 0,
or
i
= C
i
means that
i
0 implies C
i
0 or the
i
constraint of
i
C.
Problem Solutions
Problem 3.1 (the perceptron cost function is continuous)
That the perceptron objective function
J(w) =

xY

x
w
T
x,
where Y is the set of points misclassied by the weight vector w, is continuous as a function
of w can be argued as follows. If changing w does not change the set Y of misclassied
samples then we can write J(w) as
J(w) =

xY

x
x
T
w =
_

xY

x
x
_
T
w =
T
w,
or the product of a xed vector, dened here to be and the weight vector w. This is a
continuous function. If changing w causes a point x go in or out of the misclassied set, Y ,
then around the value of w that causes this change J(w) will change by
x
(w
T
x). The point
to note is that for a point x to go from correctly classied to incorrectly classied means that
w
T
x must pass thought zero, since for one sign w
T
x will classify the point correctly while
for the other sign it will not. The fact that this additional term
x
(w
T
x) is continuous as
a function of w imply that the full objective function J(w) is continuous.
Problem 3.2 (if
k
= the perceptron converges)
From the notes on Page 36, namely Equation 45 when
k
does not depend on k we get
[[w(t + 1) w

[[
2
[[w(t) w

[[
2
+
2

2
2[[ . (66)
43
Lets observe how the distance between w(t) and w

changes when =

2
||
(note this is a
factor of two larger than the convergence result studied on Page 36). For this value of we
nd that
[[w(t + 1) w

[[
2
[[w(t) w

[[
2
+
2
(
2
2) .
Iterating this as before gives
[[w(t) w

[[
2
[[w(0) w

[[
2
+
2
(
2
2)t .
Thus if
2
2 < 0 then as t increases in magnitude eventually the right-hand-side of the
above becomes negative or
[[w(0) w

[[
2
+
2
(
2
2)t < 0 . (67)
The inequality
2
2 < 0 requires that ( 2) < 0 or that 0 < < 2. The step k
0
where
this above inequality Equation 67 rst happens and we are guaranteed convergence when
t k
0

[[w(0) w

[[
2

2
(2 )
. (68)
Problem 3.3 (the reward and punishment form of the perceptron)
The form of the reward and punishment form of the perceptron is to start with an initial guess
w(0) at the separating hyperplane vector w

and some ordering of the input data vectors,


and then iterate
w(t + 1) = w(t) + x
(t)
if x
(t)

1
and w
T
(t)x
(t)
0
w(t + 1) = w(t) x
(t)
if x
(t)

2
and w
T
(t)x
(t)
0
w(t + 1) = w(t) otherwise , (69)
where x
(t)
is the data sample to consider on the tth step. Now consider how this algorithm
might approach a multiple of the optimal vector or w

. Since only the rst two equations


above are relevant by subtracting w

from both sides and squaring we get


[[w(t + 1) w

[[
2
= [[w(t) w

[[
2
+
2
[[x
(t)
[[
2
+ 2x
T
(t)
(w(t) w

)
if x
(t)

1
and w
T
(t)x
(t)
0
[[w(t + 1) w

[[
2
= [[w(t) w

[[
2

2
[[x
(t)
[[
2
2x
T
(t)
(w(t) w

)
if x
(t)

2
and w
T
(t)x
(t)
0 .
Let
2
max [[x
(t)
[[
2
, then the equation above become inequalities
[[w(t + 1) w

[[
2
[[w(t) w

[[
2
+
2

2
+ 2x
T
(t)
(w(t) w

)
if x
(t)

1
and w
T
(t)x
(t)
0
[[w(t + 1) w

[[
2
[[w(t) w

[[
2

2
2x
T
(t)
(w(t) w

)
if x
(t)

2
and w
T
(t)x
(t)
0 .
44
In the rst equation, since w

is a true solution, and x


(t)

1
we have that both terms
2x
T
(t)
w(t) and 2x
T
(t)
w

,
are negative. In the second equation, again since w

is a true solution, and x


(t)

2
both
terms
2x
T
(t)
w(t) and 2x
T
(t)
w

,
are negative. Since the terms with w(t) depend on the past iterates (and the starting
conditions of the algorithm) we will drop 2x
T
(t)
w(t) from the rst and 2x
T
(t)
w(t) from the
second. That means that we now have
[[w(t + 1) w

[[
2
[[w(t) w

[[
2
+
2

2
2x
T
(t)
w

if x
(t)

1
and w
T
(t)x
(t)
0
[[w(t + 1) w

[[
2
[[w(t) w

[[
2

2
+ 2x
T
(t)
w

if x
(t)

2
and w
T
(t)x
(t)
0 .
From the above discussion we know x
T
(t)
w

and x
T
(t)
w

are negative so lets take the largest


possible values for x
T
(t)
w

and x
T
(t)
w

via

1
= max
x
1
(x
T
(t)
w

) < 0

2
= max
x
2
(x
T
(t)
w

) < 0
= max(
1
,
2
) < 0 .
Then with the parameter both update lines collapse to
[[w(t + 1) w

[[
2
[[w(t) w

[[
2
+
2

2
+ 2 .
Since < 0 we can write it as = [[ and we get
[[w(t + 1) w

[[
2
[[w(t) w

[[
2
+
2

2
2[[ .
This is the same as Equation 66 and the same arguments as above show that w(t) w

as t proving the convergence of the reward and punishment form of the perceptron
algorithm. In fact the arguments above show that we converge in a nite number of steps
i.e. when t k
0
where k
0
is given by Equation 68.
Problem 3.4 (iterating the perceptron algorithm by hand)
This problem is worked in the MATLAB chap 3 prob 4.m, and when it is run produces
the plot shown in Figure 5. While the reward and punishment form of the perceptron is
processing the weight w(t) iterates through the following points
w_i=[ 0.0, 0.0, 0.0]
w_i=[ 0.0, 0.0, 1.0]
w_i=[ -1.0, 0.0, 0.0]
w_i=[ -1.0, 0.0, 1.0]
w_i=[ -2.0, 0.0, 0.0]
w_i=[ -2.0, 0.0, 1.0]
45
1 0.5 0 0.5 1 1.5 2
1
0.5
0
0.5
1
1.5
2
rewardpunishment perceptron computed decision line


class 1
class 2
Figure 5: The decision line produced when running the script chap 3 prob 4.m.
The classication rule is then
w
T
x > 0 x
1
,
and x
2
otherwise. For the nal decision line where w =
_
2 0 1

this corresponds
to a classication rule where
x
1
<
1
2
x
1
.
Problem 3.5 (implementing the perceptron)
This problem is worked in the MATLAB chap 3 prob 5.m. When this script is run we get
the result shown in Figure 6 (left).
Problem 3.6 (implementing the LMS algorithm)
This problem is worked in the MATLAB chap 3 prob 6.m. When this script is run we get
the result shown in Figure 6 (center).
Problem 3.7 (Keslers construction)
Consider applying the reward and punishment form of the perceptron to the data set obtained
by using Keslers construction. In that case we order the Keslers expanded data samples
x
(t)
and present them one at a time to the following algorithm
w(t + 1) = w(t) + x
(t)
if x
(t)
is misclassied by w(t) i.e. w
T
(t) x
(t)
0
w(t + 1) = w(t) otherwise .
46
1.5 1 0.5 0 0.5 1 1.5 2
2
1.5
1
0.5
0
0.5
1
1.5
2
2.5
3
perceptron computed decision line


class 1
class 2
1.5 1 0.5 0 0.5 1 1.5 2
1
0.5
0
0.5
1
1.5
2
2.5
3
LMS computed decision line


class 1
class 2
1.5 1 0.5 0 0.5 1 1.5 2
1
0.5
0
0.5
1
1.5
2
2.5
sum of square error computed decision line


class 1
class 2
Figure 6: Data from two two-dimensional normals with mean vectors
1
= [1, 1]
T
,
2
=
[0, 0]
T
, and
2
1
=
2
2
= 0.2. Left: The decision region produced by the perceptron algorithm.
Center: The decision region produced by the LMS algorithm. Right: The decision region
produced by the sum of square error criterion. Visually, all three algorithms produce similar
results.
Since we are only trying to enforce w
T
(t) x
(t)
> 0 and x
(t)
is the Keslers extended vector
where the unexpanded vector x
(t)
is an element of
i
. Since w(t) in Keslers construction is
dened as w = [w
T
1
, w
T
2
, , w
T
M
]
T
and since x
(t)
has a +x
(t)
at the block spot i and a x
(t)
at the block spot j and zeros elsewhere the equation
w(t + 1) = w(t) + x
(t)
,
will be executed/triggered if w
T
(t) x
(t)
0 or when
w
T
i
x
(t)
w
T
j
x
(j)
0 ,
or
w
T
i
x
(t)
w
T
j
w
(t)
,
and will update the block components of w(t) as
w
i
(t + 1) = w
i
(t) + x
(t)
w
j
(t + 1) = w
j
(t) x
(t)
w
k
(t + 1) = w
k
(t) k ,= i, j ,
as we were to show.
47
Problem 3.8 (the sum of square error optimal weight tends to MSE)
Recall that the objective functions for sum of square errors (SSE) and the mean square error
(MSE) criteria are
J
SSE
(w) =
N

i=1
(y
i
x
T
i
w)
2
J
MSE
(w) = E[(y x
T
w)
2
] ,
respectively. Since the objective function J
SSE
(w) is a multiple of a sample based estimate
of the expectation we expect that as long as the sample estimate converge to the population
values we expect the SSE weight should converge to the MSE weight. Since we can write the
solution vector w under the SSE criterion (by taking the derivative of the above expression
with respect to w) as
N

i=1
x
i
(y
i
x
T
i
w) = 0 ,
by dividing by N we get that this is equivalent to
1
N
N

i=1
x
i
y
i

_
1
N
N

i=1
x
i
x
T
i
_
w = 0 .
which as we take the limit N and assuming sample convergence to the population
values becomes
E[xy] E[xx
T
] w = 0 ,
which is the equation that the MSE solution w
MSE
must satisfy.
Problem 3.9 (the sum of square error classier)
This problem is worked in the MATLAB chap 3 prob 9.m. When this script is run we get
the result shown in Figure 6 (right).
Problem 3.10 (the multiclass sum of square error criterion)
If we have a M classes problem then the sum of error squares estimation would be formalized
by introducing the vector y
i
= [y
1
, y
2
, . . . , y
M
]
T
, where y
j
would take the value one, if the ith
sample, x
i
, was a member of class
j
and would be zero otherwise. Then we introduce M
vector weights w
j
in the matrix W dened as W = [w
1
, w
2
, . . . , w
M
]. Thus the jth column
of W is the vector weights w
j
. To specify these weights we seek to minimize the square error
48
over all of our training samples or
J(W) =
N

i=1
[[y
i
W
T
x
i
[[
2
=
N

i=1
M

j=1
(y
ij
w
j
T
x
i
)
2
=
M

j=1
_
N

i=1
(y
ij
w
j
T
x
i
)
2
_
.
Since this is the sum of M terms we can minimize the entire expression by picking w
j
for
each j = 1, 2, . . . , M to minimize the inner summation. Thus we are doing M parallel one
dimensional problems. The jth problem nd the value of w
j
by associating to the target, y
i
,
a value of one if x
i

j
and zero otherwise.
Problem 3.11 (jointly Gaussian random variables)
For this problem we are told that the joint distribution of the pair (X, Y ) is given by
p
X,Y
(x, y) =
1
2
x

1
2
exp
_

1
2(1 )
_
_
x
x

x
_
2
+
_
y
y

y
_
2

2(x
x
)(y
y
)

y
__
.
From the expression for P
X,Y
(x, y) it can be shown [10], that the conditional distribution
pX[Y is given by
pX[Y = A
_

x
+

y
(y
y
),
2
x
(1
2
)
_
.
The book asks for the distribution of PY [X which can be obtained from the above by
exchanging x and y in the expression above.
Problem 3.12 (sum of error square criterion is the same as ML)
If we have M classes, the statement that the classier outputs vary around the corresponding
desired response values d
i
k
, according to a Gaussian distribution with a known variance,
means that we would expect that g(x
i
; w
k
) A(d
i
k
,
2
) for k = 1, 2, M. In that case if
we group all of the M response for a given sample x
i
into a target vector like
y
i

_

_
d
i
1
d
i
2
.
.
.
d
i
M
_

_
.
49
The distribution of y
i
is a multivariate Gaussian with a mean given by y
i
, and a covariance
matrix given by
2
I. Thus the distribution of y
i
is given by
_

_
g(x
i
; w
1
)
g(x
i
; w
2
)
.
.
.
g(x
i
; w
M
)
_

_
A(y
i
,
2
I) .
Thus we expect from how y
i
is dened that
_

_
g(x
i
; w
1
)
g(x
i
; w
2
)
.
.
.
g(x
i
; w
M
)
_

_
d
i
1
d
i
2
.
.
.
d
i
M
_

_
N(0,
2
I) .
Thus the loglikelihood L of N samples x
i
would then be given by
L(x
i
) = ln
_
_
_
_
_
N

i=1
1
(2)
l

2l
exp
_

1
2
2
_

_
g(x
i
; w
1
) d
i
1
g(x
i
; w
2
) d
i
2
.
.
.
g(x
i
; w
M
) d
i
M
_

_
T
_

_
g(x
i
; w
1
) d
i
1
g(x
i
; w
2
) d
i
2
.
.
.
g(x
i
; w
M
) d
i
M
_

_
_

_
_
_
_
_
_
= ln
_
N

i=1
1
(2)
l

2l
exp
_

1
2
2
_
M

k=1
(g(x
i
; w
k
) d
k
i
)
2
___
= ln
_
1
(2)
lN

2lN
exp
_

1
2
2
N

i=1
M

k=1
(g(x
i
; w
k
) d
k
i
)
2
__
.
Since we will want to maximize the loglikelihood as a function of the vectors w
k
we can drop
all things that dont depend on w and minimize the negative of what remains. We then need
to minimize as a function of w
k
for k = 1, 2, , M the following expression
L

(x
i
) =
N

i=1
M

k=1
(g(x
i
; w
k
) d
k
i
)
2
.
This is exactly the sum of squares error criterion in the multiclass case.
Problem 3.13 (approximating P(
1
[x) P(
2
[x) in a MSE sense)
The MSE training procedure (in the two class case) computes the decision surface f(x; w)
weights w via
w = argmin
w
E
_
(f(x; w) y)
2

= argmin
w
_

j=1
(f(x; w) y)
2
P(x,
j
)dx.
50
Using p(x,
j
) = P(
j
[x)p(x) and if we code each classes response as y = +1 when x
1
and y = 1 when x
2
then the argument inside the integration in the above minimization
becomes
(f(x; w) 1)
2
P(
1
[x) + (f(x; w) + 1)
2
P(
2
[x)
= (f(x; w)
2
2f(x; w) + 1)P(
1
[x) + (f(x; w)
2
+ 2f(x; w) + 1)P(
2
[x)
= f(x; w)
2
2f(x; w)[P(
1
[x) P(
2
[x)] + 1
= f(x; w)
2
2f(x; w)[P(
1
[x) P(
2
[x)]
+ [P(
1
[x) P(
2
[x)]
2
[P(
1
[x) P(
2
[x)]
2
+ 1
= [f(x; w) (P(
1
[x) P(
2
[x))]
2
[P(
1
[x) P(
2
[x)]
2
+ 1 ,
where we have used the fact that P(
1
[x) +P(
2
[x) = 1. Note that the last two terms above
namely [P(
1
[x) P(
2
[x)]
2
+1 do not depend on the the vector w and thus dont change
the results of the minimization. Thus we are left with
w = argmin
w
_

(f(x; w) P(
1
[x) P(
2
[x))
2
p(x)dx
= argmin
w
E
_
(f(x; w) P(
1
[x) P(
2
[x))
2

.
Thus we are picking w to have f(x; w) approximate the decision boundary P(
1
[x)P(
2
[x)
optimally in the mean square error sense.
Problem 3.14 (how the Bayesian and MSE classier dier)
The Bayesian classier in the equal class covariance case is given by Equation 19. Thus we
need to compute the MSE hyperplane we rst extend each feature vector by adding the value
of 1 to get new vectors v dened by
v = [x
T
, 1]
T
.
The vector v is now of dimension l + 1. Then in this augmented space the optimal MSE
linear classier is given by computing w
T
v. Then if w
T
v > 0 we declare v
1
and otherwise
declare v
2
.
w = R
1
v
E[vy] . (70)
where w is the augmented vector
_
w
w
0
_
so that it includes an intercept w
0
and
R
x
= E[vv
T
] =
_

_
E[v
1
v
1
] E[v
1
v
l+1
]
E[v
2
v
1
] E[v
2
v
l+1
]
.
.
.
.
.
.
E[v
l+1
v
1
] E[v
l+1
v
l+1
]
_

_
. (71)
We can now evaluate several of these expectations. We have that vv
T
in terms of the original
x is given by
vv
T
=
_
x
1
_
_
x
T
1

=
_
xx
T
x
x
T
1
_
.
51
Taking the expectation of this gives
_
R E[x]
E[x]
T
1
_
.
Next we compute the expectation of vy =
_
x
1
_
y or E[vy] =
_
E[xy]
E[y]
_
. Since the response
is y = +1 when x
1
and y = 1 when x
2
we can compute
E[y] = 1P(
1
) 1P(
2
) = 0 ,
when P(
1
) = P(
2
) =
1
2
. Next we nd E[xy] under the same condition as
E[xy] = E[x[y = +1]P(
1
) E[x[y = 1]P(
2
)
=
1
P(
1
)
2
P(
2
) =
1

2
.
For completeness (and to be used later) we now compute E[x] and nd
E[x] = E[x[x
1
]P(
1
) + E[x[x
2
]P(
2
) =
1
2
(
1
+
2
) .
From these expressions we see that we need to solve R
v
w = E[vy] or
_
R E[x]
E[x]
T
1
_ _
w
w
0
_
=
_
1
2
(
1

2
)
0
_
,
for w. From the second of these equations we can solve for w
0
as
E[x]
T
w + w
0
= 0 w
0
= E[x]
T
w, (72)
which we can put in the rst of the equations above to get
(R E[x]E[x]
T
)w =
1
2
(
1

2
) .
To further evaluate this note that by expanding the quadratic and distributing the expecta-
tion we can show that
E[(x E[x])(x E[x])
T
]
= R E[x]E[x]
T
(73)
Thus from Equation 73 we see that w is given by
w =
1
2

1
(
1

2
) .
When we put that expression into Equation 72 and use what we have computed for E[x] we
get
w
0
=
1
4
(
1
+
2
)
T

1
(
1

2
) .
Thus the MSE decision line is to classify a point x as a member of
1
if x
T
w + w
0
> 0 or
1
2
x
T

1
(
1

2
)
1
4
(
1
+
2
)
T

1
(
1

2
) > 0 ,
52
4 3 2 1 0 1 2 3 4
4
3
2
1
0
1
2
3
4


g
1
(x)=0
+

g
2
(x)=0
+
g
3
(x)=0
+
(+,+,)
(+,,)
(+,,+)
(,+,)
(,,)
(,,+)
(,+,+)
class 1
class 2
class 3
Figure 7: The decision surface produced when running the script chap 3 prob 15.m.
or
_
x
1
2
(
1
+
2
)
_
T

1
(
1

2
) > 0 .
or writing it like Equation 19 we have
(
1

2
)
T

1
x >
1
2
(
1

2
) .
Note that this equation is only dierent from Equation 19 with regard to the right-hand-side
threshold.
Problem 3.15 (the design of M hyperplanes)
An example like one requested is produced via running the MATLAB script chap 3 prob 15.m.
When this script is run we get the result shown in Figure 7. Note that no data exists in
the region where the three discriminant functions are negative which is denoted (, , ).
Also regions with discriminant signs like (+, +, ) exist where more than one discriminant
function is positive.
Problem 3.16 (using the KKT conditions)
To use the Karush-Kuhn-Tucker (KKT) conditions for the given data points in Example 3.4
we assume that the points are linearly separable and use the problem formulation given in
53
on Page 40. Thus we start from the formulation
minimize J(w) =
1
2
[[w[[
2
subject to
y
i
(w
T
x
i
+ w
0
) 1 for i = 1, 2, , N .
The specic Lagrangian for this problem is
/(w, w
0
, ) =
1
2
w
T
w
N

i=1

i
(y
i
(w
T
x
i
+ w
0
) 1)
=
1
2
(w
2
1
+ w
2
2
)

1
(w
1
+ w
2
+ w
0
1)
2
(w
1
w
2
+ w
0
1)

3
(w
1
w
2
w
0
1)
4
(w
1
+ w
2
w
0
1) ,
since y
i
= +1 when x
i

1
and y
i
= 1 when x
i

2
. The necessary Karush-Kuhn-Tucker
conditions are then given by
/
w
1
= 0 w
1

4
= 0 (74)
/
w
2
= 0 w
2

1
+
2
+
3

4
= 0 (75)
/
w
0
= 0
1

2
+
3
+
4
= 0 . (76)
The complementary slackness conditions for the four points are given by

1
(w
1
+ w
2
+ w
0
1) = 0

2
(w
1
w
2
+ w
0
1) = 0

3
((w
1
+ w
2
+ w
0
) 1) = 0

4
((w
1
w
2
+ w
0
) 1) = 0 ,
with
1
,
2
,
3
,
4
0. If we want to consider searching only for lines that pass thought the
origin we take w
0
= 0 and the equations above simplify to
w
1
=
1
+
2
+
3
+
4
w
2
=
1

3
+
4

2
+
3
+
4
= 0

1
(w
1
+ w
2
1) = 0

2
(w
1
w
2
1) = 0

3
(w
1
w
2
1) = 0

4
(w
1
+ w
2
1) = 0 .
Put the expressions just derived for w
1
and w
2
into the complementary slackness conditions
and by changing the ordering of the equations we get

1
(2
1
+ 2
4
1) = 0

4
(2
1
+ 2
4
1) = 0

2
(2
2
+ 2
3
1) = 0

3
(2
2
+ 2
3
1) = 0

2
+
3
+
4
= 0 . (77)
54
These equations have multiple solutions, but the rst two will hold true if 2
1
+2
4
1 = 0
and the second two will be true if 2
2
+2
3
1 = 0. Lets specify that these constraints are
active. That is we will assume that
2
1
+ 2
4
1 = 0
1
=
1
2

4
2
2
+ 2
3
1 = 0
2
=
1
2

3
. (78)
If we put these two expressions into Equation 77 we get

1
2
+
4

1
2
+
3
+
3
+
4
= 0 ,
or
2
4
+ 2
3
1 = 0 ,
which again has multiple solutions. If we pick
4
0 arbitrary then solving for
3
we have

3
=
1
2

4
. Using Equation 78 for
2
in terms of
3
we have

2
=
1
2

_
1
2

4
_
=
4
.
Thus we have shown all values of
i
can be written in terms of
4
as
_

4
_

_
=
_

_
1
2

4

4
1
2

4

4
_

_
.
Using this our weight vector w is
w =
4

i=1

i
y
i
x
i
=
_
1
2

4
_
(+1)
_
1
1
_
+
4
(+1)
_
1
1
_
+
_
1
2

4
_
(1)
_
1
1
_
+
4
(1)
_
1
1
_
=
_
1
0
_
,
the same solution quoted in the text.
55
Nonlinear Classiers
Notes on the text
Notes on the XOR Problem
x
1
x
2

1
2
y
1
1
Figure 8: The perceptron that implements the OR gate.
The perceptron that implements the OR gate is shown in Figure 8. From the given diagram
we see that this perceptron gives an output value of 1 when
x
1
+ x
2

1
2
> 0 .
This expression is false for the point (0, 0) and is true for the points (1, 0), (0, 1), and (1, 1).
Algorithms based on exact classication of the training set
We documents some notes on Mezas tiling algorithm for building a two-class neural network
that exactly classies the given input data points. In this algorithm we will be growing a
network that depends on the training data rather than starting with a xed network and then
determining the parameters of the xed network. The book does a very nice job explaining
the general procedure and these are just some notes I wrote up going into more detail on the
simple example given. The example points and decision lines for this section are duplicated
in Figure 9. For this procedure we begin by rst dividing the initial data set into two regions
using one of the linear algorithms discussed in the previous chapter. For example, the pocket
algorithm or a SVM like algorithm could be used to dene the initial splitting of the data.
This is denoted as the decision line #1 in Figure 9. After this line is specied, we determine
that the training points are not classied with 100% certainty. We dene the set X
+
to be
the set of points on the plus side of line #1. In this set there is one misclassied vector B
1
.
We dene the set X

as the set of points on the minus side of line #1. The set X

has the
misclassied vector A
1
. For any set X

that has misclassied vectors we then recursively


apply the previous algorithm to these sets. In the example above, we would divide the set X
+
56
3 2 1 0 1 2 3
3
2
1
0
1
2
3
x
1
x
2


1

+
2
+

3 +

A
1
B
1
class +1 (A)
class 1 (B)
Figure 9: The sample data points and decision regions used to explain the Mezas tiling
procedure for generating a network that correctly classies the given input points.
again using an algorithm that produces a separating hyperplane (like the pocket algorithm)
and produce the decision line #2 in Figure 9. For the set X

we do the same thing and


produce the separating hyperplane denoted by the decision line #3 in Figure 9. The sets on
the plus and minus side of X
+
are then denoted as X
++
and X
+
. The same sets for the
set X

are denoted as X
+
and X

. If any of these four new sets has misclassied vectors


it will be further reduced using a separating hyperplane. This procedure is guaranteed to
nish since each separating hyperplane we introduce is processing a smaller and smaller set
of data. Each of these separating hyperplanes is pictorially represented as a node in the
input layer horizontally located next to the master unit (or the node representing the rst
data split). As each hyperplane introduced is used to split misclassied data into groups
with correct classication, no two data points, in dierent classes, can end up mapped to
the same point after the rst layer. Mezas algorithm next operates recursively on the set of
points computed from the rst layer or X
1
where X
1
is given by
X
1
= y : y = f
1
(x), for x X ,
and f
1
is the mapping implemented in the rst layer. Meza has shown that this recursive
procedure converges, while the book argues that since no two data points are mapped to the
same vertex of a hypercube correct classication may be possible with at most three layers.
Notes on backpropagation algorithm: the antisymmetric logistic
For the logistic function, f(x), given by
f(x) =
2
1 + exp(ax)
1 . (79)
57
We can show that this is equivalent to a hyperbolic tangent function with
f(x) =
2
1 + exp(ax)

1 + exp(ax)
1 + exp(ax)
=
1 exp(ax)
1 + exp(ax)
=
e
ax
2
e

ax
2
e
ax
2
+ e

ax
2
=
sinh(
ax
2
)
cosh(
ax
2
)
= tanh
_
ax
2
_
.
Notes on backpropagation algorithm: the gradients
This section are some simple notes that I took as I worked through the derivation of the
backpropagation algorithm. Much of the discussion is of the same general form as presented
in the book, but these notes helped me understand this material so I wrote them up so that
they might help others.
We will assume that we have a L layer network where L is given to us and xed and we want
to learn the values of the parameters that will give us the smallest mean square error (MSE)
over all of the training samples. The input layer is denoted as the layer 0 and the output
layer is denoted as layer L. The notation k
r
, for r = 0, 1, 2, L, will denote the number of
nodes in the rth layer so for example, we will have k
0
nodes in the rst and input layer, and
k
L
nodes in the Lth or output layer. To denote the weights that will go into the summation
at the j node in the rth layer from the nodes in the r 1th layer we will use the notation
w
r
j
=
_
w
r
j0
, w
r
j1
, , w
r
jk
r1

T
. (80)
Where r = 1, 2, , L. The value of w
r
0j
is the constant bias input used by the jth node
in the rth layer. We will update these vectors w
r
j
iteratively to minimize the MSE using a
gradient decent scheme. Thus we will use the weight update equation
w
r
j
(new) = w
r
j
(old) + w
r
j
, (81)
where
w
r
j
=
J
w
r
j
, (82)
and J is the cost function we seek to minimize. For the application here the cost function
J we will use will be a sum of individual errors over all of the sample points in the training
set of
J
N

i=1
c(i) . (83)
Here c(i) is the sample error we assign to the approximate output of the Lth output layer
denoted y
m
(i). We let e
m
(i) denote the error in the mth component of the output our
network makes when attempting to classify the sample x(i) or
e
m
(i) y
m
(i) y
m
(i) for m = 1, 2, , k
L
. (84)
Using this denition the sample error c(i) is dened as just the mean square error of the
networks mth component output due to the ith sample or y
m
(i) against the true expected
58
result or
c(i)
1
2
k
L

m=1
e
m
(i)
2
=
1
2
k
L

m=1
(y
m
(i) y
m
(i))
2
. (85)
At this point we are almost ready to derive the backpropagation algorithm but we will
need a few more denitions. In general, a neural network works by multiplying internal
node outputs by weights, summing these products, and then passing this sum through the
nonlinear activation function f(). We can imagine that for every input-output pairing (x
i
, y
i
)
for i = 1, 2, , N we have a value for all of the variables just introduced. Thus our notation
needs to depend on the sample index i. We do this by including this index on a variable, say
X, using functional notation as in X(i). To represent the other variables we will let y
r1
k
(i)
represent the output the kth neuron in the r 1th layer (for r = 2, 3, , L, L + 1). In this
notation, when r = 2 then we have y
1
k
(i) which is the output of the rst hidden layer and
when r = L + 1 we have y
L
k
(i) which is the output from the last (or output) layer. Since
there are k
r1
nodes in the r 1 layer we have k = 1, 2, , k
r1
. As introduced above, the
scalar w
r
jk
is the weight leading into the jth neuron of the rth layer from the kthe neuron
in the r 1 layer. Since the rth layer has k
r
nodes we have j = 1, 2, , k
r
. Note that
we assume that after sucient training the weights will converge and there is no i index in
their notational specication. As the input to the activation function for node j in layer r
we need to multiply these weights with the neuron outputs from layer r 1 and sum. We
denote this result v
r
j
(i). Thus we have now dened
v
r
j
(i) =
k
r1

k=1
w
r
jk
y
r1
k
(i) + w
r
j0
=
k
r1

k=0
w
r
jk
y
r1
k
(i) , (86)
where we take y
r1
0
1 to make the incorporation of a constant bias weight w
r
j0
transparent.
With these denitions we are now ready to derive the backpropagation algorithm for learning
neural network weights w
r
j
. Since we assume an initial random assignment of the neural
network weights we can assume that we know values for all of the variables introduced thus
far for every sample. We seek to use derivative information to change these initial values for
w
r
j
into weights that make the global cost function J smaller. The backpropagation procedure
starts with the weights that feed into the last L layer, namely w
L
j
, and works backwards
updating the weights between each hidden layer until it reaches the weights at the rst
hidden layer w
1
j
. Once all of the weights are updated we pass every sample (x
i
, y
i
) thought
the modied network (in the forward direction) and are ready to do another backpropagation
pass.
To use the gradient decent algorithm we will need the derivatives of the sample error function
c(i) with respect to w
r
j
, the weights that go into the j neuron in the rth layer. Converting
this derivative using the chain rule into the derivative with respect to the output v
r
j
(i) we
have
c(i)
w
r
j
=
c(i)
v
r
j
(i)
v
r
j
(i)
w
r
j
. (87)
Because of the linear nature in which v
r
j
(i) and w
r
j
are related via Equation 86 this second
59
derivative is easily computed
v
r
j
(i)
w
r
j
=
_

_
v
r
j
(i)
w
r
j0
v
r
j
(i)
w
r
j1
.
.
.
v
r
j
(i)
w
r
jk
r1
_

_
=
_

_
y
r1
0
(i)
y
r1
1
(i)
.
.
.
y
r1
kr1
(i)
_

_
=
_

_
1
y
r1
1
(i)
.
.
.
y
r1
kr1
(i)
_

_
y
r1
(i) . (88)
In the above notation y
r1
(i) is the vector of all outputs from neurons in the r 1st layer of
the network. Notice that this value is the same for all nodes j in the rth layer. Lets dene
the remaining derivative above or
E(i)
v
r
j
(i)
as

r
j
(i)
c(i)
v
r
j
(i)
, (89)
for every j in the rth layer or j = 1, 2, k
r
. Using these results we have w
r
j
given by.
w
r
j
=
J
w
r
j
=
N

i=1
c(i)
w
r
j
=
N

i=1

r
j
(i)y
r1
(i) . (90)
It is these
r
j
(i) we will develop a recursive relationship for and the above expression will
enable us to compute the derivatives needed. Recall that we dene c(i) the error in the
ith sample output as in Equation 85 here expressed in terms of v
L
m
(i) as
c(i)
1
2
kr

m=1
(y
m
(i) y
m
(i))
2
=
1
2
kr

m=1
(y
m
(i) f(v
L
m
(i)))
2
. (91)
The output layer: In this case r = L and we are at the last layer (the output layer) and
we want to evaluate
L
j
(i) =
E(i)
v
L
j
(i)
when c(i) is given by Equation 91. From that expression
we see that the v
L
j
derivative selects only the jth element from the sum and we get
c(i)
v
L
j
(i)
=
1
2
(2)(y
j
(i) f(v
L
j
(i)))f

(v
L
j
(i))
= e
j
(i)f

(v
L
j
(i)) . (92)
where we have dened the error e
j
(i) as in Equation 84.
The hidden layers: In this case r < L and the inuence of v
r1
j
on c(i) comes indirectly
through its inuence on v
r
j
. Thus using the chain rule to introduce this variable we have
c(i)
v
r1
j
(i)
=
kr

k=1
c(i)
v
r
k
(i)
v
r
k
(i)
v
r1
j
(i)
. (93)
On using the denition of
r
j
(i) given by Equation 89 in both side of this expression we have

r1
j
(i) =
kr

k=1

r
k
(i)
v
r
k
(i)
v
r1
j
(i)
. (94)
60
We stop here to note that this is a expression for the previous layers
r1
j
showing how to
compute it given values of the current layers
r
j
. To fully evaluate that we need to compute
v
r
k
(i)
v
r1
j
(i)
. Using Equation 86 we nd
v
r
k
(i)
v
r1
j
(i)
=

v
r1
j
(i)
_
k
r1

m=0
w
r
km
y
r1
m
(i)
_
=

v
r1
j
(i)
_
k
r1

m=0
w
r
km
f(v
r1
m
(i))
_
.
This derivative again selects the m = jth term in the above sum and we nd
v
r
k
(i)
v
r1
j
(i)
= w
r
kj
f

(v
r1
j
(i)) . (95)
Thus the recursive propagation of
r
j
(i) the then given by using Equation 94 with the above
derivative where we nd

r1
j
(i) =
kr

k=1

r
k
(i)w
r
kj
f

(v
r1
j
(i)) = f

(v
r1
j
(i))
kr

k=1

r
k
(i)w
r
kj
(96)
= e
r1
j
f

(v
r1
j
(i)) , (97)
with e
r1
j
dened by
e
r1
j
=
kr

k=1

r
k
(i)w
r
kj
. (98)
When our activation function f(x) is the sigmoid function dened by
f(x) =
1
1 + e
ax
, (99)
we nd its derivative given by
f

(x) =
(a)
(1 + e
ax
)
2
e
ax
= f(x)(a)
e
ax
1 + e
ax
= af(x)
_
1 + e
ax
1
1 + e
ax
_
= af(x)(1 f(x)) . (100)
With all of these pieces we are ready to specify the backpropagation algorithm.
The backpropagation algorithm
Initialization: We randomly initialize all weights in our network w
r
km
for all layers
r = 1, 2, L and for all internal nodes where the index k selects a node from the layer
r 1 thus k = 1, 2, k
r1
and the index m selects a node from the layer r and thus
m = 1, 2, k
r
.
Forward propagation: Once the weights are assigned values for each sample (x
i
, y
i
)
for i = 1, 2, N we can evaluate using forward propagation the variables v
r
j
(i) using
Equation 86 and then y
r
j
(i) via f(v
r
j
(i)). We can also evaluate the individual errors
c(i) using Equation 85 and the total error J using Equation 83
61
Then starting at the last layer where r = L for each sample i = 1, 2, N and for each
neuron j = 1, 2, k
L
rst compute
L
j
using Equation 92. Then working backwards
compute
r1
j
using Equation 97 and 98. Since we know
L
j
we can do this for r =
L, L 1, , 2 and for each neuron in layer r 1 so j = 1, 2, k
r1
.
Once we have
r
j
computed we can now update the weights w
r
j
using Equation 81
and 82 with the explicit for form w
r
j
given by Equation 90. Once we have updated
our weight vectors we are ready to apply the same procedure again, i.e. issuing a
forward propagation followed by a backwards propagation sweep.
Notes on variations on the backpropagation algorithm
Consider the backpropagation weight update equation with the momentum factor w
r
j
(t1)
given by
w
r
j
(t) = w
r
j
(t 1) g(t) . (101)
By writing out this recurrence relationship for t = T, T 1, T 2, as
w
r
j
(T) = w
r
j
(T 1) g(T)
=
_
w
r
j
(T 2) g(T 1)

g(T)
=
2
w
r
j
(T 2) [g(T 1) +g(T)]
=
2
_
w
r
j
(T 3) g(T 2)

[g(T 1) +g(T)]
=
3
w
r
j
(T 3)
_

2
g(T 2) + g(T 1) +g(T)

.
.
.
=
T
w
r
j
(0)
T1

t=0

t
g(T t) . (102)
As we require < 1 then
T
w
r
j
(0) 0 as T +. If we assume that our gradient vector
is a constant across time or g(T t) g then we see that w
r
j
(T) can be approximated as
w
r
j
(T)
_
1 + +
2
+
3
+

g =
_
1
1
_
g .
Problem Solutions
Problem 4.1 (a simple multilayer perceptron)
The given points for this problem are plotted in the Figure 10 and is generated with the
MATLAB script chap 4 prob 1.m.. From that gure we see that these points are a scattering
of points around the XOR pattern, which we know are not linearly separable, these points
are also not be linearly separable. We can however separate the two classes in the same way
62
1 0.5 0 0.5 1 1.5 2
1
0.5
0
0.5
1
1.5
2
x
1
x
2


g
1
(x
1
,x
2
)=0
+

g
2
(x
1
,x
2
)=0
+

(y
1
,y
2
)=(1,1)
(y
1
,y
2
)=(0,1)
(y
1
,y
2
)=(0,0)
class 1
class 2
Figure 10: The data points from Problem 4.1 and the two linear discriminant functions
g
1
(x
1
, x
2
) = 0 and g
2
(x
1
, x
2
) = 0, that when combined, separate the two classes.
we did for the XOR pattern. If we introduce two discriminate lines g
1
(x
1
, x
2
) and g
2
(x
1
, x
2
)
given by
g
1
(x
1
, x
2
) = x
1
+ x
2
1.65 = 0 and g
2
(x
1
, x
2
) = x
1
+ x
2
0.65 = 0 .
Next we introduce threshold variables, y
i
, that are mappings of the values taken by g
i
when
evaluated at a particular pair (x
1
, x
2
). For example, y
i
= 0 if g
i
< 0 and y
i
= 1 if g
i
0.
Then we see that the entire (x
1
, x
2
) space has been mapped to one of three (y
1
, y
2
) points:
(0, 0), (0, 1), and (1, 1) depending on where the point (x
1
, x
2
) falls relative to the two lines
g
1
= 0 and g
2
= 0. Under the (y
1
, y
2
) mapping just discussed, only the point (0, 1) is
associated with the second class, while the other two points, (0, 0) and (1, 1), are associated
with the rst class. Given the output (y
1
, y
2
) our task is now to design a linear hyperplane
that will separate the point (0, 1) from the two points (0, 0) and (1, 1). A line that does this
is
y
2
y
1

1
2
= 0 .
Problem 4.2 (using a neural net to classify the XOR problem)
See the R script chap 4 prob 2.R where this problem is worked. When that script is run it
produces the plots shown in Figure 12. In that gure we see that after very few iterations the
neural network is able to classify the training data almost perfectly. The error on the testing
data set decreases initially and then increases as the net overts and learns information that
is not generalizable. The degree to which this is over tting takes place does not really
appear to be that great however.
63
x
1
x
2
y
1
y
2
1.65
0.65
1
1
1
1
+1
1
0.5
Figure 11: The network suggested by Problem 4.1.
1.0 0.5 0.0 0.5 1.0 1.5 2.0

1
.0

0
.5
0
.0
0
.5
1
.0
1
.5
x_1
x
_
2
2 4 6 8 10
0
.0
0
.1
0
.2
0
.3
0
.4
0
.5
1:max_iterations
e
r
r
o
r
_
c
u
r
v
e
_
tr
a
in
in
g
training error rate
testing error rate
Figure 12: Left: Classication of the XOR problem. Right: The training and testing error
rates as a function of iteration number.
Problem 4.3 (multilayer perceptron based on cube vertexes)
Part (a): The given decision regions for this problem are drawn in Figure 13, which is
generated with the MATLAB script chap 4 prob 3.m. The vertex to which each region is
mapped is specied using the notation (, , ), where a minus is mapped to 0 and a plus
is mapped to a 1. From the discussion in the book a two layer neural network can classify
unions of polyhedrons but not unions of unions. Thus if consider class
1
to be composed
of the points in the regions (, , ), (+, , ), (, +, ), and (+, +, ). While the class

2
is composed of points taken from the other polyhedrons. Then the
1
polyhedrons map
to the four points on the (y
1
, y
2
, y
3
) hypercube (0, 0, 0), (1, 0, 0), (0, 1, 0), and (1, 1, 0), while
the other polyhedrons map to the upper four points of this hypercube. These two sets of
points in the mapped (y
1
, y
2
, y
3
) space can be separated easily with the hyperplane y
3
=
1
2
.
Thus we can implement the desired classier in this case using the two-layer neural network
64
2 1.5 1 0.5 0 0.5 1 1.5 2
2
1.5
1
0.5
0
0.5
1
1.5
2
x
1
+ x
2
= 0
x
2
= 1/4
x
1
x
2
= 0
(,,)
(,+,) (+,+,) (+,+,+)
(+,,)
(+,,+)
(,,+)
x
1
x
2
Figure 13: The given decision regions specied for Problem 4.3.
shown in Figure 14.
x
1
x
2
y
1
y
2
y
3
0
0.25
0
1
1
0
1
1
1
0
0
1
0.5
Figure 14: The two layer network for Problem 4.3.
Part (b): To require a three node network it is sucient to have the mapped classes in
the (y
1
, y
2
, y
3
) space mapped to the XOR problem on the unit hypercube. Thus if we pick
the points in the polyhedrons (, , ) and (+, +, +) to be members of class
1
and the
points in the other polyhedrons to be from class
2
we will require a three layer network to
perform classication. In that case we can use an additional layer (the second hidden layer)
to further perform the classication. The resulting neural network is given in Figure 15. In
that gure we have denoted the output of the two neurons in the second hidden layer as
z
1
and z
2
. To determine the weights to put on the neurons that feed from the rst hidden
layer into the second hidden layer in Figure 15 since in the (y
1
, y
2
, y
3
) space this is the XOR
problem and we can solve it in the same way that we did in the earlier part of this chapter.
That is we will create two planes, one that cuts o the vertex (0, 0, 0) from the other
65
x
1
x
2
y
1
y
2
y
3
z
1
z
2
0
1/4
0
1
5/2
1
1
0
1
1
1
1
1
1
1
1
1
1
0
1/2
Figure 15: The three layer network for Problem 4.3.
vertexes of the hypercube and the second plane that cuts o the node (1, 1, 1) from the
other vertexes of the hypercube. The points in between these two planes will belong to one
class and the points outside of these two planes will belong to the other class. For the rst
plane and the one that cuts o the vertex (0, 0, 0) of the many possible one plane that does
this is the one that passes through the three points
(1/2, 0, 0) , (0, 1/2, 0) , (0, 0, 1/2) .
While for the second plane and the one that cuts o the vertex (1, 1, 1) of the many possible
planes that do this one plane that works is the one that passes through the three points
(1, 1, 1/2) , (1/2, 1, 1) , (1, 1/2, 1) .
We thus need to be able obtain the equation for a plane in three space that passes through
three points. This is discussed in [9] where it is shown that the equation of a plane
c
1
x + c
2
y + c
3
z + c
4
= 0 ,
that must pass thought the three points (x
1
, y
1
, z
1
), (x
2
, y
2
, z
2
), and (x
3
, y
3
, z
3
) is given by
evaluating

x y z 1
x
1
y
1
z
1
1
x
2
y
2
z
2
1
x
3
y
3
z
3
1

= 0 .
As an example of this, for the rst plane we need to evaluate

x y z 1
1/2 0 0 1
1/2 0 0 1
1/2 0 0 1

= 0 ,
or
x

0 0 1
1/2 0 1
0 1/2 1

1
2

y z 1
1/2 0 1
0 1/2 1

= 0 ,
66
or nally
x + y + z 1 = 0 .
The same procedure for the second plane gives
x + y + z
5
2
= 0 .
Thus with the above planes we have computed the weights feeding into the second hidden
layer. To nish the problem we recognized that with the rst plane, only the single point
(y
1
, y
2
, y
3
) = (0, 0, 0) is mapped to the value of 0 while all other points are mapped to 1. With
the second plane, only the single point (y
1
, y
2
, y
3
) = (1, 1, 1) is mapped to the value of 1 while
all other points are mapped to 0. Thus when we threshold on the sign of the values of the
two discriminant mappings above we see map the points (0, 0, 0) (0, 0), (1, 1, 1) (0, 1),
and all other (y
1
, y
2
, y
3
) points are mapped to (1, 0). To nish our classication we need to
nd a hyperplane that splits the two points (0, 0) and (0, 1) from (1, 0). Such a discriminant
surface is z
1
=
1
2
, where we assume the second hidden layer maps the points (y
1
, y
2
, y
3
) to
the point (z
1
, z
2
). This nal discrimination surface is also represented in Figure 15.
Problem 4.4 (separating the points x
1
and x
2
with a hyperplane)
First recall that the dierence vector x
1
x
2
is a vector from the vector x
2
and pointing to
the vector x
1
, since if we add the vector x
2
to this dierence vector we get x
1
i.e.
x
2
+ (x
1
x
2
) = x
1
.
The midpoint between the two points x
1
and x
2
is the vector
1
2
(x
1
+x
2
). Thus this problem
asks to nd the plane with a normal vector proportional to x
1
x
2
and passing through the
point x
0

1
2
(x
1
+ x
2
). This means that if we take x to be a vector in the hyperplane then
the vector x x
0
must be orthogonal to x
1
x
2
or have a zero dot product
(x
1
x
2
)
T
(x x
0
) = 0 .
Using the denition for x
0
we have this expression is equal to
(x
1
x
2
)
T
x
1
2
(x
1
x
2
)
T
(x
1
+ x
2
) = 0 ,
or
(x
1
x
2
)
T
x
1
2
(x
T
1
x
1
x
T
2
x
2
) = (x
1
x
2
)
T
x
1
2
[[x
1
[[
2
+
1
2
[[x
2
[[
2
= 0 .
It remains to show that x
1
is on the positive side of the hyperplane. To show this consider
the above expression evaluated at x = x
1
. We nd
(x
1
x
2
)
T
x
1
2
[[x
1
[[
2
+
1
2
[[x
2
[[
2
= [[x
1
[[
2
x
T
2
x
1

1
2
[[x
1
[[
2
+
1
2
[[x
2
[[
2
=
1
2
[[x
1
[[
2
x
T
2
x
1
+
1
2
[[x
2
[[
2
=
1
2
([[x
1
[[
2
2x
T
2
x
1
+[[x
2
[[
2
)
=
1
2
(x
1
x
2
)
T
(x
1
x
2
) =
1
2
[[x
1
x
2
[[
2
,
which is positive showing that x
1
is on the positive side of the above hyperplane.
67
Problem 4.6 (backpropagation with cross-entropy)
The cross entropy 4.33 is
J =
N

i=1
k
L

k=1
y
k
(i) ln
_
y
k
(i)
y
k
(i)
_
.
Thus we see that c(i) in this case is given by
c(i) =
k
L

k=1
y
k
(i) ln
_
y
k
(i)
y
k
(i)
_
.
Thus we can evaluate
L
j
(i) as

L
j
(i)
c(i)
v
L
j
(i)
=

v
L
j
(i)
_

k
L

k=1
y
k
(i) ln
_
f(v
L
k
)
y
k
(i)
_
_
.
This derivative will select the k = jth element out of the sum and gives

L
j
(i) = y
j
(i)

v
L
j
(i)
_
ln
_
f(v
L
j
)
y
k
(i)
__
= y
j
(i)
f

(v
L
j
)
f(v
L
j
)
.
If the activation function f() is the sigmoid function Equation 99 then its derivative is given
in Equation 100 where we have f

(v
L
j
) = af(v
L
j
)(1 f(v
L
j
)) and the above becomes

L
j
(i) = ay
j
(i)(1 f(y
L
j
)) = ay
j
(i)(1 y
j
(i)) .
Problem 4.7 (backpropagation with softmax)
The softmax activation function has its output y
k
given by
y
k

exp(v
L
k
)

exp(v
L
k

)
. (103)
Note that this expression depends on v
L
j
in both the numerator and the denominator. Using
the result from the previous exercise we nd

L
j
(i)
c(i)
v
L
j
(i)
=

v
L
j
(i)
_

k
L

k=1
y
k
(i) ln
_
y
k
y
k
(i)
_
_
=

v
L
j
(i)
_
y
j
(i) ln
_
y
j
y
j
(i)
__


v
L
j
(i)
_
k
L

k=1;k=j
y
k
(i) ln
_
y
k
y
k
(i)
_
_
=
y
j
(i)
y
j
y
j
v
L
j
(i)

k
L

k=1;k=j
y
k
(i)
y
k
y
k
v
L
j
(i)
.
68
To evaluate this we rst consider the rst term or
y
j
v
L
j
(i)
where we nd
y
j
v
L
j
(i)
=

v
L
j
(i)
_
exp(v
L
j
)

exp(v
L
k

)
_
=
exp(v
L
j
)

exp(v
L
k

)

exp(v
L
j
) exp(v
L
j
)
(

exp(v
L
k

))
2
= y
j
y
2
j
.
While for the second term we get (note that j ,= k)
y
k
v
L
j
(i)
=

v
L
j
_
exp(v
L
k
)

exp(v
L
k

)
_
=
exp(v
L
k
) exp(v
L
j
)
(

exp(v
L
k

))
2
= y
k
y
j
.
Thus we nd

L
j
=
y
j
(i)
y
j
( y
j
y
2
j
)
k
L

k=1;k=j
y
k
(i)
y
k
( y
k
y
j
)
= y
j
(i)(1 y
j
) + y
j
k
L

k=1;k=j
y
k
(i) .
Since y
k
(i) and y
k
(i) are probabilities of class membership we have
k
L

k=1
y
k
(i) = 1 ,
and thus

k
L
k=1;k=j
y
k
(i) = 1 y
j
(i). Using this we nd for
L
j
(i) that

L
j
(i) = y
j
(i) + y
j
(i) y
j
+ y
j
(1 y
j
) = y
j
y
j
(i) ,
the expression we were to show.
Problem 4.9 (the maximum number of polyhedral regions)
The books equation 4.37 is
M =
l

m=0
_
k
m
_
with
_
k
m
_
= 0 if m > k . (104)
where M is the maximum number of polyhedral regions possible for a neural network with
one hidden layer containing k neurons and an input feature dimension of l. Assuming that
l k then
M =
l

m=0
_
k
m
_
=
k

m=0
_
k
m
_
= 2
k
,
where we have used the fact that
_
k
m
_
= 0 to drop all terms in the sum when m =
k + 1, k + 2, , l if there are any. That the sum of the binomial coecients sums to 2
k
follows from expanding (1 + 1)
k
using the binomial theorem.
69
Problem 4.12 (an approximation of

2
J
w
r
kj
w
r

)
For J given by
J =
1
2
N

i=1
k
L

m=1
( y
m
(i) y
m
(i))
2
.
We will evaluate the second derivatives of this expression. First we take the w
r
kj
derivative
of J directly and nd
J
w
r
kj
=
N

i=1
k
L

m=1
( y
m
(i) y
m
(i))
y
m
(i)
w
r
kj
.
Next we take the w
r

j
derivative of this expression. We nd

2
J
w
r
kj
w
r

=
N

i=1
k
L

m=1
y
m
(i)
w
r

y
m
(i)
w
r
kj
+
N

i=1
k
L

m=1
( y
m
(i) y
m
(i))

2
y
m
(i)
w
r
kj
w
r

.
If we are near a minimum of the objective function we can assume that y
m
(i) y
m
(i) 0
and can thus approximate the above derivative as

2
J
w
r
kj
w
r

=
N

i=1
k
L

m=1
y
m
(i)
w
r
kj
y
m
(i)
w
r

,
showing that we can approximate the second derivative by products of the rst order ones.
Recall that the variable w
r
kj
represent the weight from neuron k in layer r 1 to the neuron
j in layer r. We would expect that the eect of changes in w
r
kj
on the output y
m
(i) would
be propagated though the variables v
r
j
(i). From the chain rule we have
y
m
(i)
w
r
kj
=
y
m
(i)
v
r
j
(i)
v
r
j
w
r
kj
.
Using Equation 88 we see that
v
r
j
w
r
kj
= y
r1
k
and thus we get
y
m
(i)
w
r
kj
=
y
m
(i)
v
r
j
(i)
y
r1
k
,
which if we dene
ym(i)
v
r
j
(i)

r
jm
is the expression we wanted to show.
Problem 4.13 (approximating the Hessian)
We will assume that the weight notation for this problem is the same as in the book where
by the expression w
r
jk
is the weight from the neuron k in the r 1st layer into the neuron j
in the r-th layer.
70
Using Equation 87 and Equation 88 from the chain rule we have (dropping the i
dependence)

2
c
(w
r
jk
)
2
=
v
r
j
w
r
jk

v
r
j
_
c
v
r
j
y
r1
k
_
.
Since the input y
r1
k
is independent of v
r
j
we get

2
c
(w
r
jk
)
2
= (y
r1
k
)
2

2
c
(v
r
j
)
2
. (105)
Using Equation 92 we get

2
c
(v
L
j
)
2
= f

(v
L
j
)e
j

_

v
L
j
(y
j
f(v
L
j
))
_
f

(v
L
j
)
= f

(v
L
j
)e
j
+ f

(v
L
j
)
2
.
Now to evaluate

2
E
(v
r1
j
)
2
we note that from Equation 96 and Equation 89 we have
c
v
r1
j
=
_
kr

k=1

r
k
w
r
kj
_
f

(v
r
j
) ,
Thus the v
r1
j
derivative of this is given by

2
c
(v
r1
j
)
2
= f

(v
r1
j
)
kr

k=1
w
r
kj

r
k
v
r1
j
+ f

(v
r1
j
)
_
kr

k=1

r
k
w
r
kj
_
.
Thus we need to evaluate

r
k
v
r1
j
. To do this we will use the denition of
r
k
given by
Equation 89, an expression like Equation 93 and subsequent developments following
that equation, namely

v
r1
j
_
c
v
r
k
_
=
kr

=1

v
r
k

_
c
v
r
k
_
v
r
k

v
r1
j
= f

(v
r1
j
)
kr

=1
w
r
k

2
c
v
r
k

v
r
k
.
Dropping all o-diagonal terms in the summation above we keep only the k

= k
element and nd

r
k
v
r1
j
= f

(v
r1
j
)w
r
kj

2
c
(v
r
k
)
2
.
Using this we nally get for

2
E
(v
r1
j
)
2
the following

2
c
(v
r1
j
)
2
= (f

(v
r1
j
))
2
kr

k=1
(w
r
kj
)
2

2
c
(v
r
k
)
2
+ f

(v
r1
j
)
_
kr

k=1

r
k
w
r
kj
_
.
Note that this expression is dierent than that given in the book in that the rst term
in the book has a summation with an argument of

2
E
(v
r
j
)
2
(note the j subscript) rather
than

2
E
(v
r
k
)
2
(with a k subscript). Since the rst of these two expressions is independent
of k it could be taken out of the summation making me think the book has a typo in
its equation. Please contact me if anyone sees any errors in this derivation.
71
Problem 4.15 (a dierent activation function)
When one changes the activation function in the backpropagation algorithm what changes is
the function we use to evaluate any expression with f() or f

(), for example in Equations 92


and 97. One of the nice things about the backpropagation algorithm is that calls to the
activation function f and its derivative f

can simply be viewed as algorithmic subroutines


that can be replaced and modied if needed. For the suggested hyperbolic tangent function
f(x) given by
f(x) = c tanh(bx) , (106)
we have its derivative given by
f

(x) = c b sech
2
(bx) .
From the identity cosh
2
(x) sinh
2
(x) = 1, by dividing by cosh
2
(x) we can conclude that
sech
2
(x) = 1 tanh
2
(x) and thus
f

(x) = cb(1 tanh


2
(bx))
= b
_
1
f(x)
2
c
_
. (107)
These two functions then need to be implemented to use this activation function.
Problem 4.16 (an iteration dependent learning parameter )
A Taylor expansion of
1
1+
t
t
0
or
1
1 +
t
t
0
1
t
t
0
+
t
2
t
2
0
+ .
Thus when t t
0
the fraction
1
1+
t
t
0
1 to leading order and thus
0
. On the other
hand when t t
0
we have that 1 +
t
t
0

t
t
0
and the fraction above is given by
1
1 +
t
t
0

1
t
t
0
=
t
0
t
.
Thus in this stage of the iterations (t) decreases inversely in proportion to t.
Problem 4.17 (using a neural net as a function approximation)
This problem is worked in the R script chap 4 prob 17.R. When that script is run it produces
a plot like that shown in Figure 16. The neural network with two hidden nodes was created
using the nnet command from the nnet package. We see that the neural network in this
case does a very good job approximating the true function.
72
0.1 0.2 0.3 0.4 0.5 0.6 0.7
0
.1
0
.2
0
.3
0
.4
x
y
training data
testing data
truth
Figure 16: The function to t and its neural network approximation for Problem 4.17.
Problem 4.19 (when N = 2(l + 1) the number of dichotomies is 2
N1
)
We have
O(N, l) = 2
l

i=0
_
N 1
i
_
, (108)
where N is the number of points embedded in a space of dimension l and O(N, l) is the
number of groupings that can be formed by hyperplanes in R
l
to separate the points into
two classes. If N = 2(l + 1) then
O(2(l + 1), l) = 2
l

i=0
_
2l + 1
i
_
.
Given the identity
_
2n + 1
n i + 1
_
=
_
2n + 1
n + i
_
, (109)
73
by taking i = n + 1, n, n 1, , 1 we get the following equivalences
_
2n + 1
0
_
=
_
2n + 1
2n + 1
_
_
2n + 1
1
_
=
_
2n + 1
2n
_
_
2n + 1
2
_
=
_
2n + 1
2n 1
_
.
.
.
_
2n + 1
n 1
_
=
_
2n + 1
n + 2
_
_
2n + 1
n
_
=
_
2n + 1
n + 1
_
Now write O(2(l + 1), l) as
l

i=0
_
2l + 1
i
_
+
l

i=0
_
2l + 1
i
_
,
or two sums of the same thing. Next note that using the above identities we can write the
second sum as
l

i=0
_
2l + 1
i
_
=
_
2l + 1
0
_
+
_
2l + 1
1
_
+ +
_
2l + 1
l 1
_
+
_
2l + 1
l
_
=
_
2l + 1
2l + 1
_
+
_
2l + 1
2l
_
+ +
_
2l + 1
l + 2
_
+
_
2l + 1
l + 1
_
=
2l+1

i=l+1
_
2l + 1
i
_
.
Thus using this expression we have that
O(2(l + 1), l) =
l

i=0
_
2l + 1
i
_
+
2l+1

i=l+1
_
2l + 1
i
_
=
2l+1

i=0
_
2l + 1
i
_
= 2
2l+1
.
Since 2l + 1 = N 1 we have that O(2(l + 1), l) = 2
N1
as we were to show.
Problem 4.22 (the kernel trick)
From the given mapping (x) we have that
y
T
i
y
j
= (x
i
)
T
(x
j
)
=
1
2
+ cos(x
i
) cos(x
j
) + cos(2x
i
) cos(2x
j
) + + cos(kx
i
) cos(kx
j
)
+ sin(x
i
) sin(x
j
) + sin(2x
i
) sin(2x
j
) + + sin(kx
i
) sin(kx
j
) .
74
Since cos() cos()+sin() sin() = cos() we can match cosigns with sines in the above
expression and simplify a bit to get
y
T
i
y
j
=
1
2
+ cos(x
i
x
j
) + cos(2(x
i
x
j
)) + + cos(k(x
i
x
j
)) .
To evaluate this sum we note that by writing the cosigns above in terms of their exponential
representation and using the geometric series we can show that
1 + 2 cos() + 2 cos(2) + 2 cos(3) + + 2 cos(n) =
sin
__
n +
1
2
_

_
sin
_
x
2
_ . (110)
Thus using this we can show that y
T
i
y
j
is given by
1
2
sin
__
k +
1
2
_
(x
i
x
j
)
_
sin
_
x
2
_ ,
as we were to show.
75
Feature Selection
Notes on the text
Notes on Data Normalization
First recall that for small y we have e
y
1 y +
1
2
y
2
+ , thus
x
ik
=
1
1 + e
y

1
1 + 1 y +
1
2
y
2
=
1
2
_
1
1
y
2
+
y
2
4
+
_
.
Next recall that for small v we have
1
1v
=

k=0
v
k
thus we get
1
1
y
2
+
y
2
4
+
1 +
_
y
2

y
2
4
+
_
+
_
y
2

y
2
4
+
_
2
+
= 1 +
y
2

y
2
4

y
2
4

y
3
4
+ = 1 +
y
2
.
which is a linear function of y as claimed.
Notes on the Unknown Variance Case
Consider the expectation
E[(x
i
+ x)
2
] = E[(x
i
)
2
+ 2(x
i
)( x) + ( x)
2
]
=
2
+ 2E[(x
i
)( x)] +

2
2
.
We can evaluate the inner expectation using
E[(x
i
)( x)] = E[(x
i
)
_
1
N
N

=1

1
N
N

=1
x
i

_
]
=
1
N
N

=1
E[(x
i
)(x
i
)] =
1
N
E[(x
i
)
2
] ,
since by independence E[(x
i
)(x
j
)] = 0 if i ,= j. Since E[(x
i
)
2
] =
2
we get
E[
2
] =
1
N 1
N

i=1
_

2
2
_

2
N
_
+

2
N
_
=
N
N 1
_
1
1
N
_

2
=
2
.
76
Notes on Example 5.3
See the R script chap 5 example 5 3.R for code that duplicates the results from this example.
Notes on the derivation of the divergence for Gaussian distributions
When the conditional densities are Gaussian we have
p(x[
i
) N(
i
,
i
)
p(x[
j
) N(
j
,
j
) .
Then to compute the divergence d
ij
given by
d
ij
=
_

(p(x[
i
) p(x[
j
)) ln
_
p(x[
i
)
p(x[
j
)
_
dx, (111)
we rst need to compute the log term ln
_
p(x|
i
)
p(x|
j
)
_
, where we nd
ln
_
p(x[
i
)
p(x[
j
)
_
=
1
2
_
(x
i
)
T

1
i
(x
i
) (x
j
)
T

1
j
(x
j
)

+
1
2
ln
_
[
j
[
[
i
[
_
.
When we expand the quadratics above we get
ln
_
p(x[
i
)
p(x[
j
)
_
=
1
2
_
x
T

1
i
x x
T

1
j
x 2
T
i

1
i
x + 2
T
j

1
j
x

1
2
_

T
i

1
i

i

T
j

1
j

j

+
1
2
ln
_
[
j
[
[
i
[
_
.
Only the rst four terms depend on x while the remaining terms are independent of x and
can be represented by a constant C. Because the densities p(x[) are normalized we note
that
_

(p(x[
i
) p(x[
j
))Cdx = C(1 1) = 0 ,
and these terms do not aect the divergence. Thus we only need to worry about how to
integrate the rst four terms. To do these lets rst consider the integral of these terms
against p(x[
i
) (integrating against p(x[
j
) will be similar). To do these integral we will use
Equation 294 from Appendix A to evaluate the integral of the terms like x
T

1
x, against
p(x[
i
). When we do that we nd the integral of the log ratio term expressed above is given
by (multiplied by 1/2)
2
_

ln
_
p(x[
i
)
p(x[
j
)
_
p(x[
i
)dx =
T
i

1
i

i
+ trace(
i

1
i
)
T
i

1
j

i
trace(
i

1
j
)
2
T
i

1
i

i
+ 2
T
j

1
j

i
=
T
i

1
i

i

T
i

1
j

i
+ 2
T
j

1
j

i
+ trace(I) trace(
i

1
j
) .
77
In the same way the integral of the log ratio term against p(x[
j
) is given by
2
_

ln
_
p(x[
i
)
p(x[
j
)
_
p(x[
j
)dx =
T
j

1
i

j
trace(
j

1
i
) +
T
j

1
j

j
+ trace(
j

1
j
)
+ 2
T
i

1
i

j
2
T
j

1
j

j
=
T
j

1
j

j

T
j

1
i

j
+ 2
T
i

1
i

j
+ trace(I) trace(
j

1
i
) .
If we take 1 of the rst and second expression and add them together we get two types of
terms. Terms involving the trace operation and terms that dont depend on the trace. The
trace terms add to give
trace terms = trace(I) + trace(
i

1
j
) trace(I) + trace(
j

1
i
)
= 2trace(I) + trace(
i

1
j
) + trace(
j

1
i
) .
The non-trace terms add together to give
non-trace terms =
T
i

1
i

i
+
T
i

1
j

i
2
T
j

1
j

i
+
T
j

1
j

j
+
T
j

1
i

j
2
T
i

1
i

j
=
T
i
(
1
i

i
+
1
j

i
2
1
j

j
2
1
i

j
) +
T
j
(
1
i

j
+
1
j

j
)
=
T
i
((
1
i
+
1
j
)
i
2(
1
i
+
1
j
)
j
) +
T
j
(
1
i
+
1
j
)
j
=
T
i
(
1
i
+
1
j
)(
i

j
)
T
i
(
1
i
+
1
j
)
j
+
T
j
(
1
i
+
1
j
)
j
=
T
i
(
1
i
+
1
j
)(
i

j
) (
T
i

T
j
)(
1
i
+
1
j
)
j
= (
i

j
)
T
(
1
i
+
1
j
)
i
(
i

j
)
T
(
1
i
+
1
j
)
j
= (
i

j
)(
1
i
+
1
j
)(
i

j
) .
In total when we divide by 2 and add together the trace and the non-trace expressions we
get
d
ij
=
1
2
(
i

j
)(
1
i
+
1
j
)(
i

j
) +
1
2
trace(
i

1
j
+
j

1
i
2I) , (112)
for the expression for the divergence between two Gaussians.
Notes on Example 5.4
From the expression for B derived in the book
B =
l
2
log
_

2
1
+
2
2
2
1

2
_
,
if we consider r =

2

1
and put in
2
= r
1
in to the above we get
B =
l
2
log
_
1 + r
2
2r
_
+,
as r 0. Thus
P
e

_
P(
1
)P(
2
)e
B
0 .
78
Notes on scatter matrices
Recall the denitions of the within-class scatter matrix, S
w
, given by
S
w
=
M

i=1
P
i
E[(x
i
)(x
i
)
T
[x
i
] , (113)
and the denition of the between-class scatter matrix, S
b
, given by
S
b
=
M

i=1
P
i
(
i

0
)(
i

0
)
T
, (114)
The variable
0
is the global mean vector or mean over all features independent of class.
We can show that this is equivalent to the expression given in the book as follows

0
=
1
N
N

i=1
x
i
=
1
N
M

i=1
n
i

j=1
x
j
=
1
N
M

i=1
n
i

i
=
M

i=1
P
i

i
, (115)
Where in the second sum above we mean to sum only over those features x that are members
of class i. Here M is the number of classes. Note that means either
i
(the class specic
means) and
0
(the global mean) are linear functions of the raw features x. Thus if we
consider a linear transformation of x such as
y = A
T
x,
then x means denoted by
x
transform into y means in the expected manner

y
= A
T

x
.
From the denitions of the x based scatter matrices S
wx
and S
bx
given above and how the x
based s change under a linear transformation we see that
S
yw
= A
T
S
xw
A and S
yb
= A
T
S
xb
A. (116)
We will use these two results when we pick the transformation A
T
so that the transformed
vectors y are optimal in some way.
If we consider a single feature (a scalar) in the two class case where was assume with equal
class probabilities we have for S
w
and S
b
the following expressions
S
w
=
1
2
(S
1
+ S
2
) =
1
2
(
2
1
+
2
2
)
S
b
=
1
2
((
1

0
)
2
+ (
2

0
)
2
) .
Since
0
=
1
2
(
1
+
2
) we nd the dierences needed in the expression for S
b
given by

0
=
1
2
(
1

2
) and
2

0
=
1
2
(
2

1
) ,
79
and we have S
b
= (
1

2
)
2
. Thus
J

2
=
[S
b
[
[S
w
[

(
1

2
)
2
(
2
1
+
2
2
)
.
This later expression is known as Fishers discriminant ration or FDR. The book give a
multidimensional generalization of
FDR
md
=
M

i=1
M

j=i
(
i

j
)
2

2
i
+
2
j
,
but I would think that one would want to incorporate the class priors as was done in the
multiclass generalization of the divergence via
FDR
md
=
M

i=1
M

j=i
(
i

j
)
2

2
i
+
2
j
P(
i
)P(
j
) .
Notes on sequential backwards selection (SBS)
Here we derive the number of times we evaluate the class separability metric when using
sequential backwards selection to nd a suboptimal collection of l features. We start with
the initial m features, and begin by evaluating the class separability measure J() using the
full m dimensional feature vector. This results in 1 evaluation of J. We then sequentially
remove each of the m features from the full feature set and evaluate J on using each reduced
vector. This requires m evaluations of J. We select the set of features of size m 1 that
gives the largest value of J. Using this selection of variables we continue this process by
sequentially removing each variable to obtain a set of m1 vectors each of dimension m2
and evaluate J on each. This requires m1 evaluations. Thus now we have performed
1 + m+ m1 ,
evaluations of J to select the vector of size m2. If we continue this pattern one more step
we will do
1 + m+ m1 + m2 ,
evaluations of J to select the optimal set of features of size m3. Generalizing this we need
1 + m+ m1 + m2 + + l + 1 ,
evaluations of J to select the optimal set of features of size l. This can be simplied as
1 +
m

k=l+1
k = 1 +
m

k=1
k
l

k=1
k
= 1 +
1
2
m(m + 1)
1
2
l(l + 1) .
A simple python implementation of this search procedure is given in backwards selection.py
and backwards selection run best subsets.py.
80
Notes on sequential forwards selection (SFS)
In the same way as in sequential backwards selection we start by performing m evaluations
of J to pick the best single feature. After this feature is selected we then need to evaluate
J, m 1 times to pick the set of two features that is best. After the best two features are
picked we need to evaluate J m2 time to pick the best set of three features. This process
continues until we have selected l features. Thus we have in total
m

k=m(l1)
k =
m

k=1
k
ml

k=1
=
1
2
m(m + 1)
1
2
(ml)(ml + 1)
= lm
1
2
l(l 1) ,
when we simplify. A simple python implementation of this search procedure is given in
forward selection.py and forward selection run best subsets.py.
Notes on optimal feature generation
For J
3
dened as trace(S
1
w
S
m
) when we perform a linear transformation of the raw input
feature vectors x as y = A
T
x, the scatter matrices transform as given by Equation 116 or
S
yw
= A
T
S
xw
A and S
ym
= A
T
S
xm
A the objective J
3
as a function of A becomes
J
3
(A) = trace((A
T
S
xw
A)
1
(A
T
S
xm
A)) . (117)
We would like to pick the value of A such that when we map the input features y under A
T
the value of J
3
(A) is maximal. Taking the derivative of the above and using the results on
Page 96 we get that the equation
J
3
(A)
A
= 0 imply (when we postmultiply by A
T
S
xw
A)
S
xw
A(A
T
S
xw
A)
1
(A
T
S
xb
A) = S
xb
A.
But because the transformed scatter matrices S
yw
and S
yb
are given by A
T
S
xw
A and A
T
S
xb
A
respectively by using these expressions and premultipling the above by S
1
xw
, we can write
the above expression as
AS
1
yw
S
yb
= S
1
xw
S
xb
A. (118)
Note that this expression has scatter matrices in terms of y on the left and x on the right.
When written in this form, this expression hides the A matrices in the denition of S
yw
and
S
yb
. Since we dont know A we cant directly compute the matrices S
yw
and S
yb
. Assuming
for the moment that we could compute these two matrices, since they are both symmetric
we can nd an invertible matrix B such that diagonalizes both S
yw
and S
yb
. This means
that there is an invertible linear transformation B such that
B
T
S
yw
B = I and B
T
S
yb
B = D,
81
where D is a diagonal matrix
2
. This means that in terms of B and D we can write S
1
yw
and
S
yb
as
S
1
yw
= (B
T
B
1
)
1
= BB
T
and S
yb
= B
T
DB
1
.
If we use these expressions after we postmultiply Equation 118 by B we nd
(S
1
xw
S
xb
)AB = AS
1
yw
S
yb
B = ABB
T
B
T
DB
1
B
= ABD.
If we let C AB we have
S
1
xw
S
xb
C = CD. (119)
This is an eigenvalue problem where columns of C are the eigenvectors of S
1
xw
S
xb
and D is
a diagonal matrix with the eigenvectors on the diagonal.
To complete this discussion we now need to decide which of the eigenvectors of S
1
xw
S
xb
we are
going to select as the columns of C. In an M class problem the rank of S
xb
is at most M1.
Thus the rank of the product matrix S
1
xw
S
xb
is at most M 1. Thus we can have at most
M 1 non-zero eigenvalues and thus there can be at most M 1 associated eigenvectors.
Question: These eigenvalues are positive, but I currently dont see an argument why that
needs to be so. If anyone knows of one please let me know.
Since we are asked to take the m original features from the vector x and optimally (with
respect to J
3
) linearly transform them into a smaller set l features the largest l can be is
M 1.
If l = M1 then we should take C to have columns represented by all of the non-zero
eigenvectors of S
1
xw
S
xb
. This will have the same maximal value for J
3
in that in the
original space of x J
3
has the value
J
3,x
= trace(S
1
xw
S
xb
) =
1
+
2
+ +
M1
,
since a matrix trace is equivalent to the sum of that matrices eigenvalues. While after
performing the C
T
transformation on x or y = C
T
x we have J
3
given by Equation 117
or
J
3, y
= trace((C
T
S
xw
C)
1
(C
T
S
xb
C)) .
To evaluate this expression recall that C is the matrix in Equation 119 or S
xb
C =
S
xw
CD. If we premultiply this by C
T
we get
C
T
S
xb
C = C
T
S
xw
CD,
so
(C
T
S
xw
C)
1
(C
T
S
xb
C) = D.
Thus
trace((C
T
S
xw
C)
1
(C
T
S
xb
C)) = trace(D) =
1
+
2
+ +
M1
,
the same as J
3,x
obtained earlier.
If l < M 1 then we take the l eigenvectors associated with the l largest eigenvalues
of S
1
xw
S
xb
.
2
Note that B is not necessarily orthogonal, all we know is that it is invertible.
82
Problem Solutions
Problem 5.1 (
(2N2)s
2
z

2
is a chi-squared random variable)
To solve this problem we will use several results from Appendix A.11 (chi-squared distribu-
tion). To begin recall that when given N draws, x
i

N
i=1
, from a Gaussian random variable
with variance
2
and sample mean x the expression
1

2
N

i=1
(x
i
x)
2
,
is given by a chi-squared distribution with N 1 degrees of freedom. Next recall that if

2
1
and
2
2
are independent random variables from chi-squared distributions with N
1
and N
2
degrees of freedom then

2
=
2
1
+
2
2
,
is a random variable from a chi-squared distribution with N
1
+N
2
degrees of freedom. Thus
when we consider the expression
(2N2)s
2
z

2
or
N

i=1
(x
i
x)
2

2
+
N

i=1
(y
i
y)
2

2
,
we have the sum of two independent chi-squared random variables each of degree N 1.
Thus this expression is another chi-squared random variable with 2N2 degrees of freedom.
Problem 5.2 (q has a t-distribution)
Using the same arguments as in problem 5.1 above we rst note that
(N
1
+ N
2
2)s
2
z

2
,
is given by a
2
random variable with N
1
+N
2
2 degrees of freedom. Next, if we consider
the random variable x y
1
+
2
we know that it is Gaussian with a zero mean and a
variance given by
Var[ x y
1
+
2
] = Var[(( x
1
) ( y
2
))]
= Var[ x
1
] 2Cov[( x
1
), ( y
2
)] + Var[ y
2
]
= Var[ x
1
] + Var[ y
2
] =

2
N
1
+

2
N
2
,
since we are assuming that Cov[( x
1
), ( y
2
)] = 0. Thus the random variable
x y
1
+
2

_
1
N
1
+
1
N
2
,
83
is a standard normal. Then using the results from Appendix A.12 (t-distribution) where it is
stated that the ratio of a standard normal random variable over a scaled
2
random variable
with n degrees of freedom is a t-distributed random variable of degree n we have, forming a
ratio of the required form, that
x y
1
+
2

_
1
N
1
+
1
N
2
_
(N
1
+ N
2
2)s
2
z

2
_
1
N
1
+ N
2
2
_
,
is a t distributed random variable with N
1
+N
2
2 degrees of freedom. The above expression
simplies to
x y
1
+
2
s
z
_
1
N
1
+
1
N
2
.
Which shows that the desired expression is a t distributed random variable with N
1
+N
2
2
degrees of freedom.
Problem 5.3 (A is orthonormal)
The given matrix A has components A(i, j) that can be represented as
A(1, j) =
1

n
1 j n
A(i, i) =
i 1
_
i(i 1)
i 2
A(i, j) =
1
_
i(i 1)
i 2 and 1 j i 1 .
Then the (p, q) element of the product AA
T
is given by
(AA
T
)(p, q) =
n

k=1
A(p, k)A
T
(k, q) =
n

k=1
A(p, k)A(q, k) .
We will evaluate this expression for all possible values of (p, q) and show that in all cases this
matrix product equals the identity matrix. Since the rst row above seems dierent than
the general case we start there. If p = 1 then we have
(AA
T
)(1, q) =
1

n
n

k=1
A(q, k) .
If we then take q = 1 we get
(AA
T
)(1, 1) =
1

n
n

k=1
A(1, k) =
1
n
n

k=1
1 = 1 .
84
If q > 1 then we get
(AA
T
)(1, q) =
1

n
n

k=1
A(q, k) =
1

n
_
A(q, q) +
q1

k=1
A(q, k)
_
=
1

n
_
q 1
_
q(q 1)

1
_
q(q 1)
q1

k=1
1
_
= 0 .
Now assume that p > 1. Then we have for (AA
T
)(p, q) the following
(AA
T
)(p, q) =
n

k=1
A(p, k)A(q, k) = A(p, p)A(q, p) +
p1

k=1
A(p, k)A(q, k)
=
p 1
_
p(p 1)
A(q, p)
1
_
p(p 1)
p1

k=1
A(q, k) . (120)
To evaluate this lets rst assume that q < p then A(q, k) = 0 if k > q and then Equation 120
gives
(AA
T
)(p, q) = 0
1
_
p(p 1)
q

k=1
A(q, k)
=
1
_
p(p 1)
_
A(q, q) +
q

k=1
A(q, k)
_
=
1
_
p(p 1)
_
q 1
_
q(q 1)

q1

k=1
1
_
q(q 1)
_
= 0 .
If q > p then Equation 120 gives
p 1
_
p(p 1)
_
1
_
q(q 1)
_

1
_
p(p 1)
p1

k=1
1
_
q(q 1)
= 0 .
Finally, if p = q then Equation 120 gives
(AA
T
)(p, p) =
p 1
_
p(p 1)
_
1
_
q(q 1)
_

1
_
p(p 1)
p1

k=1
1
_
q(q 1)
=
1
_
p(p 1)
_
q(q 1)
[(p 1)(q 1) + (p 1)]
=
(p 1)q
_
p(p 1)
_
q(q 1)
= 1 ,
when we convert all qs into ps. Thus we have shown that AA
T
= I and A is an orthogonal
matrix.
85
Problem 5.4 (linear combinations of Gaussian random variables)
Recall [2] that the characteristic function for multidimensional Gaussian random vector x
with mean and covariance is given by

X
(t) = E[e
it
T
X
] = exp
_
it
T

1
2
t
T
t
_
. (121)
If our random vector y is a linear combination of the elements of the vector x then y = Ax
and the characteristic function for y is given by

Y
(t) = E[e
it
T
Y
] = E[e
it
T
AX
] = E[e
i(A
T
t)
T
x
] =
X
(A
T
t)
= exp
_
it
T
A
1
2
t
T
AA
T
t
_
,
which is the same as the characteristic function of a multidimensional Gaussian random
vector that has a mean vector of A and covariance matrix of AA
T
as we were to show. If
x
i
are mutually independent with identical variances say
2
then is a multiple of the identity
matrix, say =
2
I. In that case AA
T
=
2
AA
T
. In that case if A is orthogonal the
covariance matrix for y
i
is
2
I and these transformed variables are also mutually independent.
Problem 5.5 (the ambiguity function)
We dene the ambiguity function as
A =
M

i=1
K

j=1
P(
j
)P(
i
[
j
) log
M
(P(
i
[
j
)) . (122)
If the distribution of features over each class is completely overlapping, then P(
j
[
i
) is
independent of
i
. That is P(
j
[
i
) = P(
j
). In this case, then using Bayes rule we have
P(
i
[
j
) =
P(
j
[
i
)P(
i
)
P(
j
)
= P(
i
) .
The ambiguity function in this case then becomes
A =
M

i=1
K

j=1
P(
j
)P(
i
) log
M
(P(
i
)) =
M

i=1
P(
i
) log
M
(P(
i
)) .
If we further assume that each class is equally likely then P(
i
) =
1
M
, so log
M
_
1
M
_
= 1
and we nd A becomes
A =
1
M
M

i=1
1 = 1 .
If the distribution of features are perfectly separated, then P(
i
[
j
) = 0 if class i does not
have any overlap with the region
j
, otherwise P(
i
[
j
) = 1, since in that case only class
86

i
is present. To evaluate A we break the inner sum of j into regions where class i has
feature overlap and does not have
A =
M

i=1
_

j: class i overlaps
j
+

j: class i does not overlap


j
_

_
In the rst sum, since P(
i
[
j
) = 1 each term is zero and the entire sum vanishes. In the
second sum, when P(
i
[
j
) = 0 by a limiting argument one can show that
P(
i
[
j
) log
M
(P(
i
[
j
)) = 0 ,
and thus the entire sum also vanishes. Thus we have shown that A = 0.
Problem 5.7 (the divergence increase for Gaussian densities)
To begin this problem, we are told that when we consider the generation of original feature
vectors x of dimension m, that the two classes i and j have the same covariance matrix
. If we then add an additional feature x
m+1
so that we desire to consider the covariances
of vectors dened as
_
x
x
m+1
_
, we will assume that these larger vectors also have equal
covariance matrices when considered from class i and j. In this case that covariance matrix
will be take of the form

=
_
r
r
T

2
_
.
When two classes have equal covariances the trace terms in the divergence d
ij
given by
Equation 112 vanish and d
ij
simplies to
d
ij
= (
i

j
)

1
(
i

j
) . (123)
Here
i
and
j
are the mean vectors for the larger vector with the scalar x
m+1
appended to
the original x, for example

i
=
_

i

i
_
,
where
i
is the mean of x
m+1
under class i. The same notation will be used for class j.
Thus to nd a recursive relationship for d
ij
we need a way of decomposing the inner product
dened above.
Since we are to assume that the covariance matrix,

, for the vector
_
x
x
m+1
_
is given in
block form as


_
r
r
T

2
_
.
Where is a m m matrix and r is a m 1 column vector. Thus to further simplify the
divergence we need to derive an expression for

1
. To compute this inverse we will multiply

on the left by a block matrix with some variable entries which we hope we can nd suitable
87
values for and thus derive the block inverse. As an example of this lets multiply

on the
left by the block matrix
_

1
0
b

d
_
, where b is a m1 dimensional vector and d is a scalar.
Currently, the values of these two variables are unknown. When we multiply by this matrix
we desire to nd b and d such that
_

1
0
b

d
_ _
r
r
T

2
_
=
_
I 0
0 1
_
. (124)
Equating the block multiplication result on the left to the components of the block matrix
on the right gives
b

+ dr
T
= 0 .
for the (2, 1) component. This later equation can be solved for b by taking transposes and
inverting as
b =
1
rd .
If we take d = 1 and b given by the solution above, the product on the left-hand-side given
by Equation 124 does not becomes the identity but is given by
_

1
0
r
T

1
1
_ _
r
r
T

2
_
=
_
I
1
r
0
2
r
T

1
r
_
. (125)
Note what we have just done is the forward solve step in Gaussian elimination. Taking
the inverse of both sides of this later equation we nd
_
r
r
T

2
_
1
_

1
0
r
T

1
1
_
1
=
_
I
1
r
0
2
r
T

1
r
_
1
.
or
_
r
r
T

2
_
1
=
_
I
1
r
0
2
r
T

1
r
_
1
_

1
0
r
T

1
1
_
.
Thus it remains to nd the inverse of the block matrix
_
I
1
r
0
2
r
T

1
r
_
. This inverse is
the well known backwards solve in Gaussian elimination. Note that this inverse is given
by
_
I
1
r
0
1

_
1
=
_
I
1
r
0
_
,
where we have made the denition of the scalar such that
1


2
r
T

1
r. Using this
result we have that
_
r
r
T

2
_
1
=
_
I
1
r
0
_ _

1
0
r
T

1
1
_
=
_

1
+
1
rr
T

1
r
r
T

_
. (126)
Using this expression one of the required product in the evaluation of Equation 123 is given
88
by
_
r
r
T

2
_
1
_

i

j
_
=
_

1
+
1
rr
T

1
r
r
T

_ _

i

j
_
=
_
(
1
+
1
rr
T

1
)(
i

j
)
1
r(
i

j
)
r
T

1
(
i

j
) + (
i

j
)
_
=
_
d +
1
rr
T
d
1
r(
i

j
)
r
T
d + (
i

j
)
_
.
Where since the product
1
(
i

j
) appears a great number of times we dened it to be
d, so d
1
(
i

j
). Computing the product needed to produce the full quadratic term
in d
ij
we get
_

T
i

T
j
,
i

j
_
_
d +
1
rr
T
d
1
r(
i

j
)
r
T
d + (
i

j
)
_
= (
i

j
)
T
d
+ (
i

j
)
T

1
rr
T
d
(
i

j
)
T

1
r(
i

j
)
(
i

j
)r
T
d
+ (
i

j
)
2
.
Taking the transpose of either term we see that the third and fourth scalar products in the
above expressions are equal. Combining these we get
(
i

j
)
T
d + d
T
rr
T
d + (
i

j
)
2
2d
T
r(
i

j
) .
Completing the square of the expression with respect to
i

j
we have this expression given
by

_
(
i

j
) d
T
r

2
(d
T
r)
2
+d
T
rr
T
d+(
i

j
)
T
d =
_
(
i

j
) d
T
r

2
+(
i

j
)
T
d .
Thus using this and the denition of d and we see that d
ij
is given by
d
ij
(x
1
, x
2
, , x
m
, x
m+1
) = (
i

j
)
T

1
(
i

j
) +
_

j
d
T
r

2
r
T

1
r
= d
ij
(x
1
, x
2
, , x
m
) +
_

j
(
i

j
)
T

1
r

2
r
T

1
r
.
If the new feature is uncorrelated with the original ones then we have the vector r equal zero
and the second expression follows from this one.
Problem 5.8 (the divergence sums for statistically independent features)
Consider the divergence d
ij
dened by
d
ij
=
_
x
(p(x[
i
) p(x[
j
)) ln
_
p(x[
i
)
p(x[
j
)
_
dx. (127)
89
Then if the features are statistically independent in each class we have
p(x[
i
) =
l

k=1
p(x
k
[
i
) .
Thus the logarithmic term above becomes
ln
_
p(x[
i
)
p(x[
j
)
_
dx = ln
_
l

k=1
p(x
k
[
i
)
p(x
k
[
j
)
_
=
l

k=1
ln
_
p(x
k
[
i
)
p(x
k
[
j
)
_
.
Then we get for d
ij
is
d
ij
=
l

k=1
_
x
(p(x[
i
) p(x[
j
)) ln
_
p(x
k
[
i
)
p(x
k
[
j
)
_
dx.
Since the logarithmic term only depends on x
k
(and not the other ks) we can integrate out
them by performing the
_
x
integration for all variables but x
k
. This then gives
d
ij
=
l

k=1
_
x
k
(p(x
k
[
i
) p(x
k
[
j
)) ln
_
p(x
k
[
i
)
p(x
k
[
j
)
_
dx
k
,
which is the sum of l scalar divergences each one over a dierent variable.
Problem 5.9 (deriving the Cherno bound)
The books equation 5.17 is given by
P
e
P(
1
)
s
P(
2
)
1s
_
p(x[
1
)
s
p(x[
2
)
1s
dx for 0 s 1 . (128)
When the densities p(x[
i
) for i = 1, 2 are d-dimensional multidimensional Gaussians then
p(x[
i
) =
1
(2)
d/2
[
i
[
1/2
exp
_

1
2
(x
i
)
T

1
i
(x
i
)
_
, (129)
so the product in the integrand in Equation 128 is given by
p(x[
1
)
s
p(x[
2
)
1s
=
1
(2)
ds
2
(2)
d(1s)
2
[
1
[
s
2
[
2
[
1s
2
exp
_

s
2
(x
1
)
T

1
1
(x
1
)
(1 s)
2
(x
2
)
T

1
2
(x
2
)
_
.
Expanding the terms in the exponential we nd (ignoring for now the factor
1
2
)
sx
T

1
1
x 2sx
T

1
1

1
+s
T
1

1
1

1
+ (1 s)x
T

1
2
x 2(1 s)x
T

1
2

2
+ (1 s)
2

1
2

2
.
90
Grouping the quadratic, linear, and constant terms we nd
x
T
(s
1
1
+ (1 s)
1
2
)x 2x
T
(s
1
1

1
+ (1 s)
1
2

2
) + s
T
1

1
1

1
+ (1 s)
T
2

1
2

2
.
Using this expression the product we are considering then becomes
p(x[
1
)
s
p(x[
2
)
1s
=
1
(2)
d
2
[
1
[
s
2
[
2
[
1s
2
exp
_

1
2
_
s
T
1

1
1

1
+ (1 s)
T
2

1
2

2
_
_
(130)
exp
_

1
2
_
x
T
(s
1
1
+ (1 s)
1
2
)x 2x
T
(s
1
1

1
+ (1 s)
1
2

2
)
_
_
.
Thus we want to integrate this expression over all possible x values. The trick to evaluating
an integral like this is to convert it into an integral that we know how to integrate. Since this
involves the integral of a Gaussian like kernel we might be able to evaluate this integral by
converting exactly it into the integral of a Gaussian. Then since it is known that the integral
over all space of a Gaussians is one we may have evaluated indirectly the integral we are
interested in. To begin this process we rst consider what the argument of the exponential
(without the 1/2) of a Gaussian with mean and covariance A would look like
(x )
T
A
1
(x ) = x
T
A
1
x 2x
T
A
1
+
T
A
1
. (131)
Using this expression to match the arguments of the quadratic and linear terms in the
exponent in Equation 130 would indicate that
A
1
= s
1
1
+ (1 s)
1
2
and
A
1
= s
1
1

1
+ (1 s)
1
2

2
.
Thus the Gaussian with a mean value and covariance A given by
A = (s
1
1
+ (1 s)
1
2
)
1
(132)
= A(s
1
1

1
+ (1 s)
1
2

2
)
= (s
1
1
+ (1 s)
1
2
)
1
(s
1
1

1
+ (1 s)
1
2

2
) , (133)
would evaluate to having exactly the same exponential terms (modulo the expression
T
A
1
).
The point of this is that with the denitions of A and we can write
x
T
(s
1
1
+ (1 s)
1
2
)x 2x
T
(s
1
1

1
+ (1 s)
1
2

2
) = (x )
T
A
1
(x )
T
A
1
,
so that the integral we are attempting to evaluate can be written as
_
p(x[
1
)
s
p(x[
2
)
1s
dx =
1
(2)
d
2
[
1
[
s
2
[
2
[
1s
2
exp
_

1
2
_
s
T
1

1
1

1
+ (1 s)
T
2

1
2

2
_
_
exp
_
1
2

T
A
1

_
exp
_

1
2
(x )
T
A
1
(x )
_
dx.
In eect what we are doing is completing the square of the argument in the exponential.
Since we know that multidimensional Gaussians integrate to one, this nal integral becomes
_
exp
_

1
2
(x )
T
A
1
(x )
_
dx = (2)
d/2
[A[
1/2
. (134)
91
In addition, the argument in the exponential in front of the (now evaluated) integral is given
by
s
T
1

1
1

1
+ (1 s)
T
2

1
2

2

T
A
1
. (135)
When we put in the denition of A and given by Equations 132 and 133 we have that

T
A
1
is equivalent to three (somewhat complicated) terms

T
A
1
= (s
T
1

1
1
+ (1 s)
T
2

1
2
)(s
1
1
+ (1 s)
1
2
)
1
(s
1
1

1
+ (1 s)
1
2

2
)
= s
2

T
1

1
1
(s
1
1
+ (1 s)
1
2
)
1

1
1

1
+ 2s(1 s)
T
1

1
1
(s
1
1
+ (1 s)
1
2
)
1

1
2

2
= (1 s)
2

T
2

1
2
(s
1
1
+ (1 s)
1
2
)
1

1
2

2
.
Given that we still have to add the terms s
T
1

1
1

1
+(1s)
T
2

1
2

2
to the negative of this
expression we now stop and look at what our end result should look like in hopes of helping
motivate the transformations to take next. Since we might want to try and factor this into
an expression like (
1

2
)
T
B(
1

2
) by expanding this we see that we should try to get
the expression above into a three term form that looks like

T
1
B
1
2
T
1
B
2
+
T
2
B
2
, (136)
for some matrix B. Thus lets add s
T
1

1
1

1
+ (1 s)
T
2

1
2

2
to the negative of
T
A
1

and write the result in the three term form suggested by Equation 136 above. We nd that
Equation 135 then becomes when factored in this way
s
T
1
_

1
1
s
1
1
(s
1
1
+ (1 s)
1
2
)
1

1
1

1
(137)
2s(1 s)
T
1
_

1
1
(s
1
1
+ (1 s)
1
2
)
1

1
2

2
(138)
+ (1 s)
T
2
_

1
2
(1 s)
1
2
(s
1
1
+ (1 s)
1
2
)
1

1
2

2
. (139)
We now use the inverse of inverse matrix sums lemma (IIMSL) given by
(A
1
+ B
1
)
1
= A(A+ B)
1
B = B(A+ B)
1
A, (140)
to write the matrix products in the middle term of the above expression as

1
1
(s
1
1
+ (1 s)
1
2
)
1

1
2
= ((1 s)
1
+ s
2
)
1
. (141)
Recognizing this matrix as one that looks familiar and that we would like to turn the others
into lets now hope that the others can be transformed into a form that looks like that. To
further see if this is possible, and to motivate the transformations done next, consider how
the desired expression would look like expanded as in Equation 136. We have without the
factor of
1
2
s(1 s) the following
(
1

2
)
T
((1 s)
1
+ s
2
)
1
(
1

2
) =
T
1
((1 s)
1
+ s
2
)
1

1
(142)
2
T
1
((1 s)
1
+ s
2
)
1

2
(143)
+
T
2
((1 s)
1
+ s
2
)
1

2
. (144)
Since as just shown the middle terms match as desired, looking at the terms Equation 137
and 142, to have the desired equality we want to show if we can prove
s
_

1
1
s
1
1
(s
1
1
+ (1 s)
1
2
)
1

1
1

= s(1 s)((1 s)
1
+ s
2
)
1
, (145)
92
and
(1 s)
_

1
2
(1 s)
1
2
(s
1
1
+ (1 s)
1
2
)
1

1
2

= s(1 s)((1 s)
1
+s
2
)
1
, (146)
the similar expression for the terms Equation 139 and 144. To show that in fact this matrix
dierence is correct we will use another matrix identity lemma. This time we will use the
Woodbury identity which can be written as
(A+ UCV )
1
= A
1
A
1
U(C
1
+ V A
1
U)
1
V A
1
. (147)
If we specialize this identity by taking C and V to both be identity matrices we obtain
(A+ U)
1
= A
1
A
1
U(I + A
1
U)
1
A
1
= A
1
A
1
(U
1
+ A
1
)
1
A
1
.
Using this last expression with A = s
1
1
and U = (1 s)
1
2
we can derive that
(s
1
1
+ (1 s)
1
2
)
1
=
1
s

1
s

1
_
1
1 s

2
+
1
s

1
_
1
1
s

1
=
1
s

(1 s)
s

1
((1 s)
1
+ s
2
)
1

1
.
Multiplying this last expression by s
1
1
on the left and
1
1
on the right to get
s
1
1
(s
1
1
+ (1 s)
1
2
)
1

1
1
=
1
1
(1 s)((1 s)
1
+ s
2
)
1
.
This last expression gives that

1
1
s
1
1
(s
1
1
+ (1 s)
1
2
)
1

1
1
= (1 s)((1 s)
1
+ s
2
)
1
,
which is equivalent to the desired Equation 145. Using exactly the same steps one can prove
Equation 146. In summary then we have shown that
_
p(x[
1
)
s
p(x[
2
)
1s
dx =
[A[
1/2
[
1
[
s
2
[
2
[
1s
2
exp
_

1
2
s(1 s)(
1

2
)
T
((1 s)
1
+ s
2
)
1
(
1

2
)
_
.
It remains to evaluate the coecient
|A|
1/2
|
1
|
s
2 |
2
|
1s
2
. Taking the determinant of both sides of
Equation 141 and solving for the expression A dened in Equation 132 we nd
[A[ =
[
1
[[
2
[
[(1 s)
1
+ s
2
[
. (148)
When we put this into what we have found for
_
p(x[
1
)
s
p(x[
2
)
1s
dx we obtain
_
p(x[
1
)
s
p(x[
2
)
1s
dx =
[
1
[
1s
2
[
2
[
s
2
[(1 s)
1
+ s
2
[
1
2
exp
_

1
2
s(1 s)(
1

2
)
T
((1 s)
1
+ s
2
)
1
(
1

2
)
_
.
93
If we dene the above expression equal to e
b(s)
we see that b(s) is given by
b(s) =
1
2
s(1 s)(
1

2
)
T
((1 s)
1
+ s
2
)
1
(
1

2
)
+
1
2
ln
_
[(1 s)
1
+ s
2
[
[
1
[
1s
[
2
[
s
_
. (149)
When this is combined with Equation 128 we have nally proved the Cherno inequality. If
we now consider the case when
1
=
2
= we have
b(s) =
s(1 s)
2
(
1

2
)
T

1
(
1

2
) .
Then as
1
2
(
1

2
)
T

1
(
1

2
) is a scalar multiplier of the function s(1s), its value does
not change the location of the extrema of b(s). To nd the extrema of b(s) we take the rst
derivative, set the result equal to zero and solve for s. We nd
b

(s) = 1 s s = 0 s =
1
2
.
the second derivative of the function b(s) is given by b

(s) = 2. Since this is negative s =


1
2
is a maximum of b(s) or a minimum of e
b(s)
.
Problem 5.10 (the mixture scatter matrix is the sum of S
w
and S
b
)
Consider evaluating the expectation in the denition of S
m
by conditioning on each class
S
m
= E[(x
0
)(x
0
)
T
] =
M

i=1
E[(x
0
)(x
0
)
T
[x
i
]P
i
.
where P
i
= P(x
i
). Then write x
0
= x
i
+
i

0
and expand the inner product
above as
(x
0
)(x
0
)
T
= (x
i
)(x
i
)
T
+ 2(x
i
)(
i

0
)
T
+ (
i

0
)(
i

0
)
T
.
Then taking the conditional expectation of the above expression with respect to
i
since
E[x
i
[x
i
] = 0 the middle term in above vanishes. The last term does not depend on
x and is therefore a constant with respect to the expectation and we get for S
m
S
m
=
M

i=1
P
i
E[(x
i
)(x
i
)
T
[x
i
] +
M

i=1
P
i
(
i

0
)(
i

0
)
T
,
which when we recall the denitions of S
w
and S
b
given by
S
w
=
M

i=1
P
i
E[(x
i
)(x
i
)
T
[x
i
] (150)
S
b
=
M

i=1
P
i
(
i

0
)(
i

0
)
T
, (151)
we recognize as expressing S
m
as S
m
= S
w
+ S
b
.
94
Problem 5.11 (bounds on the cross-correlation coecient)
When we take the vectors x and y as
x =
_

_
x
1i
x
2i
.
.
.
x
Ni
_

_
and y =
_

_
y
1i
y
2i
.
.
.
y
Ni
_

_
,
the Schwartzs inequality [x
T
y[ [[x[[[[y[[ show that [
ij
[ 1 where
ij
is dened by

ij
=

N
n=1
x
ni
y
nj
_

N
n=1
x
ni
2

N
n=1
y
nj
2
.
Problem 5.12 (the divergence of a two class problem)
The divergence between two Gaussians is given by Equation 112. If we assume that the
Gaussians have the same covariance then
1
=
2
= and the divergence becomes
d
12
= (
1

2
)
T

1
(
1

2
) = trace((
1

2
)
T

1
(
1

2
))
= trace(
1
(
1

2
)(
1

2
)
T
) .
When the classes are equiprobable P
1
= P
2
=
1
2
. Then the within class scatter matrix
Equation 113 becomes
S
w
=
1
2

1
+
1
2

2
= .
Now lets compute S
b
using Equation 114. We have
S
b
=
M

i=1
P
i
(
i

0
)(
i

0
)
T
=
1
2
_
(
1

0
)(
1

0
)
T
+ (
2

0
)(
2

0
)
T

.
Since
0
=

M
i=1
P
i

i
=
1
2
(
1
+
2
) when we compute the needed dierences to compute S
b
we calculate
S
b
=
1
2
_
1
4
(
1

2
)(
1

2
)
T
+
1
4
(
1

2
)(
1

2
)
T
_
=
1
4
(
1

2
)(
1

2
)
T
.
Thus if we consider the expression trace(S
1
w
S
b
) we see that it equals in this case
trace(S
1
w
S
b
) =
1
4
trace(
1
(
1

2
)(
1

2
)
T
) .
We see that this is proportional to the expression d
12
derived above.
95
Problem 5.13 (the number of combinations in backwards elimination)
See the notes on Page 80 where we derive this expression.
Problem 5.14 (the derivative of a trace)
We want to evaluate

A
trace(A
T
S
1
A)
1
(A
T
S
2
A)
The algebraic procedure for computing derivatives like

A
traceF(A) where F() is a matrix
function of a matrix argument is discussed in [3]. The basic procedure is the following. We
consider the matrix derivative as several scalar derivative (one derivative for each component
a
kl
of A). We pass the derivative of a
kl
though the trace operation and take the scalar
derivative of various matrix expressions i.e.
F(A)
a
kl
. Taking these derivatives is easier if we
introduce the matrix V (k, l) which is a matrix of all zeros except for a single one at the
location (k, l). This is a helpful matrix to have since

a
kl
A = V (k, l) .
Once we have computed the derivative of the argument of the trace F(A) with respect to
a
kl
we need to write it in the form
F(A)
a
kl
=

i
g
i
(A)V (k, l)h
i
(A) .
We can then take the trace of the above expression and use the permutability of matrices in
the argument of the trace to write
trace
_
F(A)
a
kl
_
= trace
_

i
g
i
(A)V (k, l)h
i
(A)
_
=

i
trace g
i
(A)V (k, l)h
i
(A)
=

i
trace h
i
(A)g
i
(A)V (k, l) . (152)
Finally we use the property of the trace to conclude that for any n n matrix M
MV (k, l) =
_

_
0
_

_
m
1k
m
2k
.
.
.
m
n1,k
m
nk
_

_
0
_

_
,
or a matrix with the kth column of M in the lth column. Since the only nonzero column is
the lth, to take the trace of this matrix, we need to nd what the element of the lth row in
96
that column is. From the above we see that this element is m
lk
. Thus we have just argued
that
trace MV (k, l) = M(l, k) .
When we reassemble all elements, from this result, to compute the full matrix derivative of
traceMA we see that

A
trace MA = M
T
.
Back to Equation 152 we can use the above to get the full matrix derivative

A
traceF(A) =

i
(h
i
(A)g
i
(A))
T
. (153)
For this problem we now implement this procedure.
To begin we evaluate the a
kl
derivative of (A
T
S
1
A)
1
(A
T
S
2
A). From the product rule we
have

a
kl
_
(A
T
S
1
A)
1
(A
T
S
2
A)

=
_

a
kl
(A
T
S
1
A)
1
_
(A
T
S
2
A) + (A
T
S
1
A)
1
_

a
kl
(A
T
S
2
A)
_
.
To evaluate the a
kl
derivative of (A
T
S
1
A)
1
recall that if F(A) = G
1
(A) then
F(A)
a
kl
= G
1
(A)
G(A)
a
kl
G
1
(A) . (154)
Thus we get
(A
T
S
1
A)
1
a
kl
= (A
T
S
1
A)
1
(A
T
S
1
A)
a
kl
(A
T
S
1
A)
1
.
Thus we need to evaluate the derivative of A
T
S
1
A (a similar needed derivative is of A
T
S
2
A).
We get
(A
T
S
1
A)
a
kl
= V
T
(k, l)S
1
A + A
T
S
1
V (k, l) .
Combining these results we get

a
kl
(A
T
S
1
A)
1
(A
T
S
2
A) = (A
T
S
1
A)
1
_
V
T
(k, l)S
1
A+ A
T
S
1
V (k, l)

(A
T
S
1
A)
1
(A
T
S
2
A)
+ (A
T
S
1
A)
1
_
V
T
(k, l)S
2
A + A
T
S
2
V (k, l)

.
Then for each term (there are four of them) once we take the trace we can write each one
as g
i
(A)V (k, l)h
i
(A) for functions g
i
() and h
i
() for i = 1, 2, 3, 4 by using
trace(A
T
) = trace(A) ,
if needed. We will need to use that identity for the rst and third terms. We get
g
1
(A) = (A
T
S
2
A)(A
T
S
1
A)
1
A
T
S
1
, and h
1
(A) = (A
T
S
1
A)
1
g
2
(A) = (A
T
S
1
A)
1
A
T
S
1
, and h
2
(A) = (A
T
S
1
A)
1
(A
T
S
2
A)
g
3
(A) = A
T
S
2
, and h
3
(A) = (A
T
S
1
A)
1
g
4
(A) = (A
T
S
1
A)
1
A
T
S
2
, and h
4
(A) = I .
97
Once we have done this we use Equation 153 (but without the transpose yet) to get
_

A
trace
_
(A
T
S
1
A)
1
(A
T
S
2
A)
_
_
T
= (A
T
S
1
A)
1
(A
T
S
2
A)(A
T
S
1
A)
1
A
T
S
1
(A
T
S
1
A)
1
(A
T
S
2
A)(A
T
S
1
A)
1
A
T
S
1
+ (A
T
S
1
A)
1
A
T
S
2
+ (A
T
S
1
A)
1
A
T
S
2
.
Thus taking the transpose of both sides we nally nd

A
trace
_
(A
T
S
1
A)
1
(A
T
S
2
A)
_
= 2S
1
A(A
T
S
1
A)
1
(A
T
S
2
A)(A
T
S
1
A)
1
+2S
2
A(A
T
S
1
A)
1
,
as we were to show.
Problem 5.17 (the eigenstructure for S
1
w
S
b
in a two class problem)
In a two class problem M = 2, P
1
+ P
2
= 1, and we have S
b
given by
S
b
=
M

i=1
P
i
(
i

0
)(
i

0
)
T
= P
1
(
1

0
)(
1

0
)
T
+ P
2
(
2

0
)(
2

0
)
T
.
Since
0
=

M
i=1
P
i

i
= P
1

1
+ P
2

2
we have that

0
=
1
P
1

1
P
2

2
= (1 P
1
)
1
P
2

2
= P
2
(
1

2
)

0
= P
1

1
+ (1 P
2
)
2
= P
1
(
2

1
) .
Using these we see that S
b
is given by
S
b
= P
1
P
2
2
(
1

2
)(
1

2
)
T
+ P
2
P
2
1
(
1

2
)(
1

2
)
T
= P
1
P
2
(
1

2
)(
1

2
)
T
.
Thus the matrix S
1
w
S
b
is
P
1
P
2
S
1
w
(
1

2
)(
1

2
)
T
.
Since the matrix (
1

2
)(
1

2
)
T
is rank one the matrix S
1
w
S
b
is rank one, and thus
we have one non-zero eigenvalue (and its corresponding eigenvector). Consider the vector
v
1
S
1
w
(
1

2
) and observe that
S
1
w
S
b
v
1
= P
1
P
2
S
1
w
(
1

2
)(
1

2
)
T
S
1
w
(
1

2
)
= (P
1
P
2
(
1

2
)
T
S
1
w
(
1

2
))S
1
w
(
1

2
)
=
1
v
1
,
where we take
1
= P
1
P
2
(
1

2
)
T
S
1
w
(
1

2
). Thus v
1
is an eigenvector of S
1
w
S
b
and
1
is its corresponding eigenvalue.
98
Problem 5.18 (orthogonality of the eigenvectors of S
1
1
S
2
)
Since S
1
and S
2
can be simultaneously diagonalized, there exists and invertible matrix B
such that
B
T
S
1
B = I and B
T
S
2
B = D,
where D is a diagonal matrix. Since B is invertible we can solve for S
1
and S
2
in terms of
B and D as
S
1
= B
T
B
1
and S
2
= B
T
DB
1
.
Using these consider the product
S
1
1
S
2
= (BB
T
)(B
T
DB
1
) = BDB
1
.
Let v
i
be an eigenvector of S
1
1
S
2
with eigenvalue
i
. Then by the denition of an eigenvector
we have
S
1
1
S
2
v
i
=
i
v
i
,
or from the expression for S
1
1
S
2
in terms of B and D
BDB
1
v
i
=
i
v
i
.
This gives two expressions for v
i
v
i
=
1

i
BDB
1
v
i
v
i
=
i
BD
1
B
1
v
i
.
Now consider v
T
i
S
1
v
j
, using the rst of these we will replace v
i
with
1

i
BDB
1
v
i
, S
1
with
B
T
B
1
, and using the second expression above v
j
with
j
BD
1
B
1
v
j
to get
v
T
i
S
1
v
j
=

j

i
v
T
i
B
T
DB
T
B
T
B
1
BD
1
B
1
v
j
=

j

i
v
T
i
B
T
B
1
v
j
=

j

i
v
T
i
S
1
v
j
.
Thus
_
1

j

i
_
v
T
i
S
1
v
j
= 0 .
So if i ,= j (where we assume that
i
,=
j
) then the last equation shows that v
i
S
1
v
j
= 0 as
we were to show.
99
Feature Generation I: Linear Transforms
Notes on the text
Notes on basis vectors and images
We dene a separable transformation of X to be one where the transform Y is given by
Y = U
H
XV . (155)
A separable transformation can be thought of as two successive transformations, one over
the columns of X and another over the rows of the matrix product U
H
X. To see this rst
dene the product U
H
X as Z and write U
H
as
_

_
u
H
0
u
H
1
.
.
.
u
H
N1
_

_
so that considered as a block
matrix product, the expression Z = U
H
X is the product of a N 1 block matrix times a
1 1 block matrix or
_

_
u
H
0
u
H
1
.
.
.
u
H
N1
_

_
X =
_

_
u
H
0
X
u
H
1
X
.
.
.
u
H
N1
X
_

_
.
This result has N rows where each one is of the form u
H
i
X or the inner product transform
of the N columns of X. Thus the transformation U
H
X is a transformation over the rows
of X. Now consider the product (U
H
X)V , which we can write as ZV = (V
H
Z
H
)
H
. Notice
that V
H
Z
H
is the same type of transformation as we just discussed i.e. inner product
transforms of the columns of Z
H
. Equivalently inner product transforms of the rows of
Z = U
H
X, proving the statement made above. Note that some of the calculations for
Example 6.1 are performed in the MATLAB script chap 6 example 6 1.m.
Notes on independent component analysis (ICA)
From the derivation in the book we have that at a stationary point
J(W)
W
W
T
= E[I (y)y
T
] = 0 . (156)
If we postmultiply by W and use W
T
W = I we get
J(W)
W
= E[I (y)y
T
]W = 0 .
The expression
J(W)
W
= E[I (y)y
T
]W is called the natural gradient.
100
Notes on the discrete Fourier transform
We dene the scalar W
N
as an Nth root of unity or
W
N
exp
_
j
2
N
_
, (157)
with j

1 and the matrix W


H
is given by
1

N
_

_
1 1 1 1 1 1
1 W
N
W
2
N
W
3
N
W
N2
N
W
N1
N
1 W
2
N
W
4
N
W
6
N
W
2(N2)
N
W
2(N1)
N
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
1 W
N2
N
W
2(N2)
N
W
3(N2)
N
W
(N2)(N2)
N
W
(N1)(N2)
N
1 W
N1
N
W
2(N1)
N
W
3(N1)
N
W
(N2)(N1)
N
W
(N1)(N1)
N
_

_
. (158)
From this we see that the (i, j)th component of W
H
is given by
(W
H
)(i, j) =
1

N
W
ij
N
. (159)
Using W
H
above and the fact that W

N
= W
1
N
the matrix W is given by
1

N
_

_
1 1 1 1 1 1
1 W
1
N
W
2
N
W
3
N
W
(N2)
N
W
(N1)
N
1 W
2
N
W
4
N
W
6
N
W
2(N2)
N
W
2(N1)
N
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
1 W
(N2)
N
W
2(N2)
N
W
3(N2)
N
W
(N2)(N2)
N
W
(N1)(N2)
N
1 W
(N1)
N
W
2(N1)
N
W
3(N1)
N
W
(N2)(N1)
N
W
(N1)(N1)
N
_

_
. (160)
From this we see that the (i, j)th component of W is given by
W(i, j) =
1

N
W
ij
N
. (161)
These expressions will be used in the problems and derivations below.
Notes on the two-dimensional Fourier transform
The two-dimensional discrete Fourier transform is dened as
Y (k, l) =
1
N
N1

m=0
N1

n=0
X(m, n)W
km
N
W
ln
N
. (162)
Recalling via Equation 159 that the (k, m) element of W
H
is
1

N
W
km
N
in terms of the elements
of W
H
this sum is
Y (k, l) =
N1

m=0
N1

n=0
X(m, n)(W
H
)(k, m)(W
H
)(l, n) .
101
Using Equation 176 to convert this double sum into a matrix product we have we have
Y = W
H
X(W
H
)
T
but since W
H
is symmetric we have
Y = W
H
XW
H
. (163)
Notes on the Haar transform
For the Haar transform, given the index n, we have 2
n
basis functions index by k where
k = 0, 1, 2, 2
n
1 and denoted by h
k
(z). Given a value of the index k in the range just
specied we can convert this index k uniquely into two other nonnegative integers p and q.
The integer p (for power) is the largest natural number such that 2
p
k and then q 1 is
the remainder. Thus let q 1 be given by
q 1 = k 2
p
.
Thus with these two denitions of p and q we have written the index k as
k = 2
p
+ q 1 . (164)
This denition works for p ,= 0, where if p = 0 then q = 0 or 1. For example, if we take
n = 3 then there are 8 basis functions k = 0, 1, 2, , 7 and we have the mapping described
above from k into (q, p) given by
k = 0 p = 0 and q = 0
k = 1 p = 0 and q = 1
k = 2 p = 1 and q = 2 2
1
+ 1 = 1
k = 3 p = 1 and q = 3 2
1
+ 1 = 2
k = 4 p = 2 and q = 4 2
2
+ 1 = 1
k = 5 p = 2 and q = 5 2
2
+ 1 = 2
k = 6 p = 2 and q = 6 2
2
+ 1 = 3
k = 7 p = 2 and q = 7 2
2
+ 1 = 4 .
The reason for introducing the indexes (p, q) is that it is easier to write the expression for
the basis functions h
k
(z) in terms of the numbers p and q. Given the above equivalence we
can convert sums over k (the number of basis functions) into a double sum over p and q as
2
n
1

k=0
h
k
(z) h
p=0,q=0
(z) + h
p=0,q=1
(z) +
n1

p=1
2
p

q=1
h
pq
(z) , (165)
since the range of p is 0 p n 1 and q is between 1 q 2
p
. Note that due to the
slightly dierent conditions that happen when k = 0 and k = 1 in Equation 164, we have
represented these terms on their own and outside of the general summation notation.
102
Notes on the two-band discrete time wavelet transform (DTWT)
Most of the notes in this section are verications of the expressions given in the book.
While there are no real comments with this section these notes provide more details in that
they explicitly express some of the intermediate expressions which make verication of the
proposed expressions easier. We begin with the two-band lter equations, when our two
lters have impulse response functions given by h
0
(k) and h
1
(k). In that case we have
y
0
(k) =

l
x(l) h
0
(n l)[
n=2k
(166)
y
1
(k) =

l
x(l) h
1
(n l)[
n=2k
. (167)
When k = 0 for y
0
(k) then n = 0 and the rst equation above gives
y
0
(0) =

l
x(l)h
0
(0 l)
= + x(3)h
0
(3) + x(2)h
0
(2) + x(1)h
0
(1)
+ x(0)h
0
(0)
+ x(1)h
0
(1) + x(2)h
0
(2) + x(3)h
0
(3) + .
When k = 1 for y
0
(k) then n = 2 and we get
y
0
(1) =

l
x(l)h
0
(2 l)
= + x(3)h
0
(5) + x(2)h
0
(4) + x(1)h
0
(3)
+ x(0)h
0
(2)
+ x(1)h
0
(1) + x(2)h
0
(0) + x(3)h
0
(2) + .
The same type of expressions will hold for y
1
(k) but with h
0
replace with h
1
. When we list
these equations in a matrix form we get
_

_
.
.
.
y
0
(2)
y
1
(2)
y
0
(1)
y
1
(1)
y
0
(0)
y
1
(0)
y
0
(1)
y
1
(1)
y
0
(2)
y
1
(2)
.
.
.
_

_
=
_

_
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
h
0
(2) h
0
(3) h
0
(4) h
0
(5) h
0
(6)
h
1
(2) h
1
(3) h
1
(4) h
1
(5) h
1
(6)
h
0
(0) h
0
(1) h
0
(2) h
0
(3) h
0
(4)
h
1
(0) h
1
(1) h
1
(2) h
1
(3) h
1
(4)
h
0
(2) h
0
(1) h
0
(0) h
0
(1) h
0
(2)
h
1
(2) h
1
(1) h
1
(0) h
1
(1) h
1
(2)
h
0
(4) h
0
(3) h
0
(2) h
0
(1) h
0
(0)
h
1
(4) h
1
(3) h
1
(2) h
1
(1) h
1
(0)
h
0
(6) h
0
(5) h
0
(4) h
0
(3) h
0
(2)
h
1
(6) h
1
(5) h
1
(4) h
1
(3) h
1
(2)
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
_

_
_

_
.
.
.
x(2)
x(1)
x(0)
x(+1)
x(+2)
.
.
.
_

_
.
I explicitly included more terms than in the book so that the pattern of the elements is as
clear as possible. In practice, while we can tolerate a non causal impulse lters (h
0
(k) and
103
h
1
(k) nonzero for negative k) but since we would like the matrix above to be of nite extent
we require that h
0
and h
1
have only a nite number of nonzero terms. As a matrix equation
we can write this as
y = T
i
x,
where T
i
is the mapping into the wavelet domain. Once we have constructed the two
outputs y
0
(k) and y
1
(k) we seek another pair of lters of a special form that act as an
inverse to the above mapping, in that they can synthesis the original signal, x, from the
output pair y
0
and y
1
. In sort of the same way we split x into y
0
and y
1
we will process y
0
and y
1
independently and then combined them to get x. The two functions that we combine
are
x
0
(n) =

k
y
0
(k)g
0
(n 2k) (168)
x
1
(n) =

k
y
1
(k)g
1
(n 2k) , (169)
and the combination of x
0
and x
1
gives x
x(n) = x
0
(n) + x
1
(n) =

k
y
0
(k)g
0
(n 2k) + y
1
(k)g
1
(n 2k) .
To derive the matrix representation of this mapping we again write out the above equation
for a couple of values of n to get a feel for the coecients that result. For n = 0 we have
x(0) = + y
0
(2)g
0
(4) + y
1
(2)g
1
(4) + y
0
(1)g
0
(2) + y
1
(1)g
1
(2)
+ y
0
(0)g
0
(0) + y
1
(0)g
1
(0)
+ y
0
(1)g
0
(2) + y
1
(1)g
1
(2) + y
0
(2)g
0
(4) + y
1
(2)g
1
(4) + .
For n = 1 we have
x(1) = + y
0
(2)g
0
(5) + y
1
(2)g
1
(5) + y
0
(1)g
0
(3) + y
1
(1)g
1
(3)
+ y
0
(0)g
0
(1) + y
1
(0)g
1
(1)
+ y
0
(1)g
0
(1) + y
1
(1)g
1
(1) + y
0
(2)g
0
(3) + y
1
(2)g
1
(3) + .
Thus as a matrix we have the mapping from y to x in terms of values of g
0
and g
1
in great
detail as
_

_
.
.
.
x(2)
x(1)
x(0)
x(+1)
x(+2)
.
.
.
_

_
=
_

_
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
g
0
(2) g
1
(2) g
0
(0) g
1
(0) g
0
(2) g
1
(2) g
0
(4) g
1
(4) g
0
(6) g
1
(6)
g
0
(3) g
1
(3) g
0
(1) g
1
(1) g
0
(1) g
1
(1) g
0
(3) g
1
(3) g
0
(5) g
1
(5)
g
0
(4) g
1
(4) g
0
(2) g
1
(2) g
0
(0) g
1
(0) g
0
(2) g
1
(2) g
0
(4) g
1
(4)
g
0
(5) g
1
(5) g
0
(3) g
1
(3) g
0
(1) g
1
(1) g
0
(1) g
1
(1) g
0
(3) g
1
(3)
g
0
(6) g
1
(6) g
0
(4) g
1
(4) g
0
(2) g
1
(2) g
0
(0) g
1
(0) g
0
(2) g
1
(2)
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
_

_
_

_
.
.
.
y
0
(2)
y
1
(2)
y
0
(1)
y
1
(1)
y
0
(0)
y
1
(0)
y
0
(1)
y
1
(1)
y
0
(2)
y
1
(2)
.
.
.
_

_
.
As a matrix equation we can write this as
x = T
o
y ,
104
where T
o
is the mapping out of the wavelet domain. For good reconstructive properties
i.e. to be able to take the inverse transform of the direct transform and get the original
signal back again we must have
T
i
T
o
= T
o
T
i
= I .
This creates the biorthogonality conditions that h
i
and g
i
must satisfy.
Problem Solutions
Problem 6.1 (some properties of the transformation Y = U
H
XV )
Part (a): Given X = UY V
H
, lets write the matrix U in block form as columns as
U =
_
u
0
u
1
u
N1

, the matrix V
H
in block form as rows
V
H
=
_

_
v
H
0
v
H
1
.
.
.
v
H
N1
_

_
,
and the matrix Y as the N N matrix with components Y (i, j). Then viewing the product
UY V
H
in block form as a 1 N matrix (the block matrix U) times a N N matrix (the
block matrix Y ) times a N 1 matrix (the block matrix V
H
) we get for X the product
_
u
0
u
1
u
N1

_
Y (0, 0) Y (0, 1) Y (0, N 1)
Y (1, 0) Y (1, 1) Y (1, N 1)
.
.
.
.
.
.
.
.
.
.
.
.
Y (N 1, 0) Y (N 1, 1) Y (N 1, N 1)
_

_
_

_
v
H
0
v
H
1
.
.
.
v
H
N1
_

_
.
Using block matrix multiplication we have that the product of the two right most matrices
is given by
_

_
Y (0, 0)v
H
0
+ Y (0, 1)v
H
1
+ + Y (0, N 1)v
H
N1
Y (1, 0)v
H
0
+ Y (1, 1)v
H
1
+ + Y (1, N 1)v
H
N1
.
.
.
Y (N 1, 0)v
H
0
+ Y (N 1, 1)v
H
1
+ + Y (N 1, N 1)v
H
N1
_

_
.
Or in summation notation
_

N1
j=0
Y (0, j)v
H
j

N1
j=0
Y (1, j)v
H
j
.
.
.

N1
j=0
Y (N 1, j)v
H
j
_

_
.
105
Thus then X equals
_
u
0
u
1
u
N1

times this result or


X =
N1

j=0
Y (0, j)u
0
v
H
j
+
N1

j=0
Y (1, j)u
1
v
H
j
+ +
N1

j=0
Y (N 1, j)u
N1
v
H
j
=
N1

i=0
N1

j=0
Y (i, j)u
i
v
H
j
,
as we were to show.
Part (b): To compute the value of /
ij
, X we rst recall the denition of the matrix inner
product , of
A, B
N1

m=0
N1

n=0
A

(m, n)B(m, n) , (170)


and the denition of /
ij
of /
ij
= u
i
v
H
j
. Then using the rank-one decomposition of X of
X =
N1

=0
N1

=0
Y (i

, j

)u
i
v
H
j
, (171)
Equation 170 then requires us to compute the (m, n)th component of the matrix /
ij
and of
u
i
v
H
j
since X(m, n) is obtained by summing such elements via Equation 171. Consider the
(m, n)th component of u
i
v
H
j
. Recall u
i
is the ith column of U and as v
H
j
is the jth row of
V
H
we see that v
j
is the jth column of V . Then the product u
i
v
H
j
looks like
u
i
v
H
j
=
_

_
U(0, i)
U(1, i)
.
.
.
U(N 1, i)
_

_
_
V (0, j)

V (1, j)

V (N 1, j)


=
_

_
U(0, i)V (0, j)

U(0, i)V (1, j)

U(0, i)V (N 1, j)

U(1, i)V (0, j)

U(1, i)V (1, j)

U(1, i)V (N 1, j)

.
.
.
.
.
.
.
.
.
U(N 1, i)V (0, j)

U(N 1, i)V (1, j)

U(N 1, i)V (N 1, j)

_
.
Thus the (m, n) element of the matrix u
i
v
H
j
is
U(m, i)V (n, j)

, (172)
and the conjugate of the (m, n)th element of the matrix u
i
v
H
j
is
U(m, i)

V (n, j) . (173)
106
Using these results we nd
A
ij
, X = u
i
v
H
j
,
N1

=0
N1

=0
Y (i

, j

)u
i
v
H
j

=
N1

m=0
N1

n=0
U(m, i)

V (n, j)
_
N1

=0
N1

=0
Y (i

, j

)U(m, i

)V (n, j

_
=
N1

=0
N1

=0
Y (i

, j

)
N1

m=0
U(m, i)

U(m, i

)
N1

n=0
V (n, j)V (n, j

.
To evaluate these sums recall that U is a unitary matrices and thus UU
H
= I and U
H
U = I.
If we consider the (i, i

)th element of the product U


H
U = I we get
N1

n=0
(U
H
)(i, n)U(n, i

) = I(i, i

) ,
or
N1

n=0
U(n, i)

U(n, i

) = I(i, i

) , (174)
where I(i, i

) is the Kronecker delta symbol, i.e. I(i, i

) = 1 if i = i

and is 0 otherwise. Since


V is also a Hermitian matrix a similar result hold for sums of components of V . Sums like
this appear twice in the above expression for /
ij
, X and we have the following
A
ij
, X =
N1

=0
N1

=0
Y (i

, j

)I(i, i

)I(j, j

) = Y (i, j) ,
as we were to show.
Problem 6.2 (separable transforms)
We rst recall that to compute the lexicographic row ordered vector x the rows of the matrix
X are ordered sequentially in a column vector. Thus if we let X(i, :) be a row vector from
X then the lexicographically ordered row vector x is given by
x =
_

_
X(0, :)
T
X(1, :)
T
.
.
.
X(N 1, :)
T
_

_
.
Next recall that if A is a mn matrix and B is a p q matrix the Kronecker outer product
of two matrices A and B denoted as A B is dened as the mn pq matrix
AB =
_

_
a
11
B a
12
B a
13
B a
1n
B
a
21
B a
22
B a
23
B a
2n
B
.
.
.
.
.
.
.
.
.
.
.
.
a
m1
B a
m2
B a
m3
B a
mn
B
_

_
. (175)
107
Thus in terms of the matrices of this problem we have U V given by the matrix
_

_
U(0, 0)V U(0, 1)V U(0, 2)V U(0, N 1)V
U(1, 0)V U(1, 1)V U(1, 2)V U(1, N 1)V
.
.
.
.
.
.
.
.
.
.
.
.
U(N 1, 0)V U(N 1, 1)V U(N 1, 2)V U(N 1, N 1)V
_

_
.
Then when we multiply this by the lexicographic ordered vector x we get
_

_
U(0, 0)V X(0, :)
T
+ U(0, 1)V X(1, :)
T
+ + U(0, N 1)V X(N 1, :)
T
U(1, 0)V X(0, :)
T
+ U(1, 1)V X(1, :)
T
+ + U(1, N 1)V X(N 1, :)
T
.
.
.
U(N 1, 0)V X(0, :)
T
+ U(N 1, 1)V X(1, :)
T
+ + U(N 1, N 1)V X(N 1, :)
T
_

_
.
This is a block column matrix of size N 1 where the blocks are N N matrices with the
m block element given by
N1

i=0
U(m, i)V X(i, :)
T
.
Since X(i, :)
T
is a column vector the product V X(i, :)
T
is another column vector and the
above is the sum of column vectors. The nth element of this column vector is given by
N1

j=0
V (n, j)X(i, j) .
Thus the nth element of the mth block in the product (U V )x is
N1

i=0
N1

j=0
X(i, j)U(m, i)V (n, j) .
If we have the desired equality this should equal the value Y (m, n). To show this we can
simply recall that Y = UXV
T
and as such we can compute the (m, n)th element of this
product. Using the summation denition of a matrix product we nd
Y (m, n) =
N1

i=0
(UX)(m, i)(V
T
)(i, n) =
N1

i=0
N1

j=0
U(m, j)X(j, i)V (n, i)
=
N1

j=0
N1

i=0
X(j, i)U(m, j)V (n, i) , (176)
which is equivalent to the expression above showing the desired equivalence.
Problem 6.3 (minimizing the MSE by using the eigenvectors of R
x
)
For a xed orthonormal basis e
i
for i = 0, 1, 2, , N1, a random vector x the decomposition
x =
N1

i=0
y(i)e
i
, (177)
108
with y(i) = e
T
i
x. Note that since x is random the y(i)s are also random. The projection of
x in the m-dimensional subspace spanned by the vectors e
0
, e
1
, , e
m1
is given by
x =
m1

i=0
y(i)e
i
. (178)
Then as in the book the expectation of the error dened as = x x can be shown to be
given by
E
_
[[[[
2

=
N1

i=m
e
T
i
R
x
e
i
, (179)
with R
x
the correlation matrix of x i.e. R
x
= E[xx
T
]. Considering E [[[[[
2
] as the objective
function to be minimized we seek vectors e
i
that will achieve this minimum. Obviously
E [[[[[
2
] 0 and e
i
= 0 will make the right-hand-side of Equation 179 zero. To avoid this
trivial solution we need to introduced the constraint that the vectors e
i
are normalized or
e
T
i
e
i
= 1.
Question: Im not sure why we dont have to also introduce the orthogonality constraint
of e
T
i
e
j
= 0 for i ,= j. I think the answer might be because of the functional form for our
objective function E [[[[[
2
]. For example, if the vectors for i and j appeared together as
a product like e
i
Ae
j
for some matrix A in the objective function we would have to also
introduce the constraint e
T
i
e
j
= 0. If anyone knows more about this or has an opinion on
this please contact me.
Part (a): Given that we have the constraint e
T
i
e
i
= 1 we use the methods of constrained
optimization to seek the optimum. That is we introduce Lagrange multipliers
i
and form
the Lagrangian
/ =
N1

i=m
e
T
i
R
x
e
i

N1

i=0

i
(e
T
i
e
i
1) .
Then taking the derivative with respect to e
i
for i = m, m + 1, , N 1 and setting the
result equal to zero gives
2R
x
e
i
2
i
e
i
= 0 R
x
e
i
=
i
e
i
.
Thus e
i
is the eigenvector and
i
is the eigenvalue of R
x
.
Part (b): In this case using the normalization properties of e
i
we have that
E
_
[[[[
2

=
N1

i=m

i
.
Thus to make this as small as possible we want to take e
i
to be the eigenvectors with the
smallest eigenvalues.
Part (c): For the given approximation above consider the magnitude of the variance of x.
109
We nd
Var( x) = E[ x
T
x] = E
__
m

i=0
y(i)e
T
i
__
m

i=0
y(i)e
i
__
(180)
= E
_
m

i=0
m

i=0
y(i)y(j)e
T
i
e
j
_
= E
_
m

i=0
y(i)
2
_
= E
_
m

i=0
(e
T
i
x)
2
_
= E
_
m

i=0
e
T
i
xx
T
e
i
_
=
m

i=0
e
T
i
E
_
xx
T

e
i
=
m

i=0
e
T
i
R
x
e
i
=
m

i=0

i
.
Thus since e
i
are chosen to be the eigenvectors of R
x
ordered from largest eigenvalue to
smallest eigenvalue we see that this sum is maximal.
Problem 6.4 (Karhunen-Loeve with the covariance matrix
x
)
In the same way as earlier we have a representation of our random variable x given by
Equation 177 and now we will take our approximation of x given by
x =
m1

i=0
y(i)e
i
+
N1

i=m
c
i
e
i
, (181)
with y(i) = e
T
i
x.
Part (a): Consider the expected square error E[[[x x[[
2
]. We nd
E[[[x x[[
2
] = E
_
_

N1

i=m
(y
i
c
i
)e
i

2
_
_
= E
_
N1

i=m
N1

j=m
(y
i
c
i
)(y
j
c
j
)e
T
i
e
j
_
= E
_
N1

i=m
(y
i
c
i
)
2
_
=
N1

i=m
(E[y
2
i
] 2E[y
i
]c
i
+ c
2
i
) .
If we want to pick c
i
s that make this as small as possible, we can take the derivative with
respect to c
i
set the result equal to zero and solve for c
i
we nd

c
i
E[[[x x[[
2
] = 0 2E[y
i
] + 2c
i
= 0 .
This gives c
i
= E[y
i
], for i = m, m + 1, , N 1.
110
Part (b): We now want to ask for an approximation to x given by
x =
m1

i=0
y
i
e
i
+
N1

i=m
E[y
i
]e
i
,
how do we pick the orthonormal basis vectors e
i
. We do that by minimizing the square norm
of the error dened as = x x. We nd using the same techniques as the sequence of
steps around Equation 180 and recalling that y
i
= e
T
i
x we have
E[[[[[
2
] = E
_
N1

i=m
(y
i
E[y
i
])
2
_
= E
_
N1

i=m
(e
T
i
x e
T
i
E[x])
2
_
= E
_
N1

i=m
(e
T
i
(x E[x]))
2
_
= E
_
N1

i=m
e
T
i
(x E[x])(x E[x])
T
e
i
_
=
N1

i=m
e
T
i
E[(x E[x])(x E[x])
T
]e
i
=
N1

i=m
e
T
i

x
e
i
. (182)
Thus to pick the orthonormal basis that minimizes E[[[[[
2
] we minimize Equation 182 subject
to the constraint that e
T
i
e
i
= 1. Introducing Lagrange multipliers like in the previous problem
we nd e
i
are the eigenvectors of
x
.
Part (b): To make the expression for E[[[[[
2
] as small as possible we we order these
eigenvectors so that they are ranked in decreasing order of their eigenvalues, therefore the
vectors e
m
, e
m+1
, , e
N1
will be the eigenvectors of
x
corresponding to the Nm smallest
eigenvalues.
Problem 6.5 (the eigenvalues of X
H
X and XX
H
are the same)
Let be a nonzero eigenvalue of XX
H
with eigenvector v. Then by denition XX
H
v = v.
Now consider the vector v dened by v = X
H
v. Then
X
H
X v = X
H
XX
H
v = X
H
v = v .
This last expression shows that v is an eigenvector of X
H
X with eigenvalue . Thus both
XX
H
and X
H
X have the same eigenvalues.
Problem 6.6 (proving
2

N
m=0

N
n=0
[X(m, n)

X(m, n)[
2
=

r1
i=k

i
)
Recall the denition of
2
where we have

2
=
N1

m=0
N1

n=0
[X(m, n)

X(m, n)[
2
. (183)
111
Since we have our rank k approximate matrix

X given by

X =
k1

i=0
_

i
u
i
v
H
i
,
while the full decomposition for X is
X =
r1

i=0
_

i
u
i
v
H
i
.
We have the matrix dierence X

X given by
X

X =
r1

i=k
_

i
u
i
v
H
i
.
Thus the m, nth element of this matrix dierence X

X is given by using Equation 172
r1

i=k
_

i
U(m, i)V (n, i)

.
Now recall that for a complex number [x[
2
= xx

when we square the above expression we


have
[X(m, n)

X(m, n)[
2
=
r1

i=k
r1

j=k
_

i
_

j
U(m, i)V (n, i)

U(m, j)

V (n, j) .
It is this expression that we will sum for m and n both running from 0 to N 1. When we
apply this summation, then exchange the order of the sums and use Equation 174 we get

2
=
r1

i=k
r1

j=k
_

i
_

j
N1

m=0
U(m, i)U(m, j)

N1

n=0
V (n, j)V (n, i)

=
r1

i=k
r1

j=k
_

i
_

j
I(i, j)I(j, i) =
r1

i=k

i
,
as we were to show.
Problem 6.7 (an example with the SVD)
The SVD decomposition of a matrix X is given by
X =
r1

i=0
_

i
u
i
v
H
i
,
where u
i
and v
i
are the eigenvectors (with common eigenvalue
i
) of XX
H
and X
H
X re-
spectively or
XX
H
u
i
=
i
u
i
X
H
Xv
i
=
i
v
i
112
It turns out that u
i
and v
i
are related more directly as u
i
=
1

i
Xv
i
. In the MATLAB
script chap 6 prob 7.m we compute XX
H
and X
H
X and the eigenvector and eigenvalues
for these two matrices. We rst nd that X
H
X has u
i
eigenvectors (stored as columns) and
eigenvalues given by
_
_
0.8452 0.0998 0.5251
0.1690 0.8821 0.4397
0.5071 0.4604 0.7286
_
_
and 0.0 , 1.93 , 18.06 .
We next nd that XX
H
has v
i
eigenvectors (again stored as columns) with eigenvalues given
by
_
0.8649 0.5019
0.5019 0.8649
_
and 1.93 , 18.06 .
To use the SVD decomposition one has to match the eigenvectors of XX
H
and X
H
X to use
in the inner product so that their eigenvalues match. This means the decomposition of X is
given by

18.06
_
_
0.5251
0.4397
0.7286
_
_
_
0.5019 0.8649

1.937
_
_
0.0998
0.8821
0.4604
_
_
_
0.8649 0.5019

.
Problem 6.8 (the orthogonality of the DFT)
We begin by proving the following sum
1
N
N1

n=0
exp
_
j
2
N
(k l)n
_
=
_
1 l = k + rN r = 0, 1, 2,
0 otherwise
(184)
Since the sum above is a geometric sum from [6] we can evaluate it as
N1

n=0
exp
_
j
2
N
(k l)n
_
=
1 exp
_
j
2
N
(k l)N
_
1 exp
_
j
2
N
(k l)
_
=
1 exp (j2(k l))
1 exp
_
j
2
N
(k l)
_ .
This is true only if the expression we are summing powers of is not identically 1 (for which the
denominator would be 0 and division is undened). This latter will happen if the argument
of the exponential exp
_
j
2
N
(k l)
_
is a multiple of 2. This means the above sum is valid if
k l
N
,= r ,
where r is an integer. If this previous condition holds then the numerator vanishes
1 exp (j2(k l)) = 0 .
113
since k l is an integer. If
kl
N
is actually equal to and integer r then l = k + rN and the
sum is N and we have proven Equation 184.
Now consider the (m, n) element of the product W
H
W. Using Equation 159 and 161 we get
(W
H
W)(m, n) =
1
N
N1

k=0
W
mk
N
W
kn
N
=
1
N
N1

k=0
W
k(mn)
N
=
1
N
N1

k=0
exp
_
j
2
N
(mn)k
_
=
mn
,
when we use Equation 184. Here
mn
is the Kronecker delta.
Problem 6.9 (an example computing a 2-d DFT)
Using Equation 163 or Y = W
H
XW
H
we can compute the two-dimensional DFT by com-
puting the required matrix product. To generate the matrix W
H
of order N (as dened in
the book) we can use the MATLAB command dftmtx(N)/sqrt(N). In the MATLAB script
chap 6 prob 9.m given in the input matrix X we do this and perform the required matrix
multiplications. We nd that we get
Y =
_
_
3.6667 0.3333 0.1667 + 0.8660j
0.3333 0.1667 0.8660j 0.1667 0.8660j
0.3333 0.1667 + 0.8660j 0.3333
_
_
.
Problem 6.11 (orthogonality of the discrete cosine transform)
The discrete cosine transform (DCT) matrix C has elements C(n, k) given by
C(n, k) =
1

N
when k = 0
C(n, k) =
_
2
N
cos
_
(2n + 1)k
2N
_
when k > 1 , (185)
and for 0 n N 1. We want to show that C
T
C = I. To do this consider the (i, j)th
element of this product (denoted by (C
T
C)(i, j)) we have
(C
T
C)(i, j) =
N1

k=0
C
T
(i, j)C(k, j) =
N1

k=0
C(k, i)C(k, j) . (186)
Lets evaluate this for various values of i and j. When i = 0 and j = 0 Equation 186 gives
N1

k=0
C(k, 0)C(k, 0) =
N1

k=0
C(k, 0)
2
=
N1

k=0
1
N
= 1 .
114
When i = 0 and j 1 Equation 186 gives
(C
T
C)(0, j) =
N1

k=0
C(k, 0)C(k, j) =
1

N
N1

k=0
C(k, j)
=

2
N
N1

k=0
cos
_
(2k + 1)j
2N
_
By writing the summand above as
cos
_
(2k + 1)j
2N
_
= cos
_
j
2N
+
j
N
k
_
,
we can use the following identity [5]
N1

k=0
cos( + k) = cos
_
+
N 1
2

_
sin
_
N
2

_
sin
_

2
_ , (187)
with =
j
2N
and =
j
N
to evaluate it. In that case we have

2
=
j
2N
, so
N
2
=
j
2
, and +
N 1
2
=
j
2N
+
_
N 1
2
_
j
N
=
j
2
.
Thus we have
N1

k=0
cos
_
(2k + 1)
2N
_
= cos
_
j
2
_
sin
_
j
2
_
sin
_
j
2N
_ .
Since for j = 1, 2, , N 1 the value of

2
j is a multiple of

2
where we have cos
_
j
2
_
= 0
thus
(C
T
C)(0, j) =
N1

k=0
cos
_
(2k + 1)
2N
_
= 0 .
Next let i 1 and j = 0 and we have
(C
T
C)(i, 0) =
N1

k=0
C(k, i)C(k, 0) =
1

N
N1

k=0
C(k, i)
=

2
N
N1

k=0
cos
_
(2k + 1)i
2N
_
= 0 ,
since this is the same sum we evaluated earlier. Finally, let i 1 and j 1 to get
(C
T
C)(i, j) =
N1

k=0
C(k, i)C(k, j) =
2
N
N1

k=0
cos
_
(2k + 1)i
2N
_
cos
_
(2k + 1)j
2N
_
.
To evaluate this sum we could convert the trigonometric functions into exponentials and
then use the sum of a geometric series identity to evaluate each sum, or we can evaluate it
using Mathematica. In the Mathematica notebook chap 6 prob 11.nb we nd it equals
1
4
_
_
sin((i j))
sin
_
(ij)
2N
_ +
sin((i + j))
sin
_
(i+j)
2N
_
_
_
,
115
when neither of the denominators is zero, or in this case that i ,= j. When i ,= j both terms
in the numerator vanish and this expression is zero. If i = j then we want to evaluate
(C
T
C)(i, i) =
2
N
N1

k=0
cos
_
(2k + 1)i
2N
_
2
.
Using the following identity
N1

k=0
cos
_
(2k + 1)i
2N
_
2
=
N
2
+
sin(2i)
4 sin
_
i
N
_ , (188)
as i is an integer the second term vanishes and we have shown that
(C
T
C)(i, i) = 1 .
All of these elements show that C
T
C = I the desired expression.
Problem 6.12 (the discrete cosign transform)
The discrete cosign transform (DCT) Y of an image X is given by computing
Y = C
T
XC ,
where C is the matrix with elements given by Equation 185. This matrix can be constructed
using that MATLAB function mk DCT matrix C.m. Then using the X matrix given in for
this problem in the MATLAB script chap 6 prob 12.m we nd Y to be
Y =
_
_
3.6667 0.4082 0.2357
0.4082 0 1.1547
1.1785 0.5774 0.3333
_
_
.
Problem 6.14 (orthogonality of the Hadamard transform)
To begin recall the recursive denition of H
n
given by
H
n
= H
n1
H
1
= H
n1

_
1

2
_
1 1
1 1
__
=
1

2
_
H
n1
H
n1
H
n1
H
n1
_
. (189)
We will show that H
T
n
= H
n
and H
1
n
= H
n
. To do that we will use recursion, where we will
show that these two relationships are true for n = 1 and then assume that they hold up to
116
and equal to some index n. We will then show that we can prove that the relationships hold
for the index n + 1. Consider H
1
we see that H
T
1
= H
1
and
H
T
1
H
1
=
1
2
_
1 1
1 1
_ _
1 1
1 1
_
=
1
2
_
2 0
0 2
_
= I .
Then assume that H
T
n
= H
n
and H
1
n
= H
T
n
. Consider
H
T
n+1
=
1

2
_
H
T
n
H
T
n
H
T
n
H
T
n
_
=
1

2
_
H
n
H
n
H
n
H
n
_
= H
n+1
,
showing that H
n+1
is symmetric. Now consider
H
T
n+1
H
n+1
= H
n+1
H
n+1
=
1
2
_
H
n
H
n
H
n
H
n
_ _
H
n
H
n
H
n
H
n
_
=
1
2
_
2H
2
n
0
0 2H
2
n
_
=
_
I 0
0 I
_
= I ,
showing that H
1
n+1
= H
T
n+1
.
Problem 6.15 (computing the Hadamard transform)
We can use the MATLAB command hadamard to compute the Hadamard matrix H
n
as
dened in the book. Specically, we have
H
n
=
1
2
n/2
hadamard(2
n
) .
In the MATLAB script chap 6 prob 15.m given in the input matrix X we compute Y =
H
1

XH
1
, where

X is a submatrix of the original matrix X.
Problem 6.17 (the Noble identities)
Noble Downsampling Identity: Recall that downsampling by M produces a new se-
quence y(k) generated by the old sequence y(k) according to
y(k) = y(Mk) . (190)
The transfer function for this operation, D(z), when the input signal is y(k) is given by [8].
D(z) =
1
M
M1

k=0

Y
_
z
1/M
e

2j
M
k
_
, (191)
where i =

1. Using that we can write the serial aect of downsampling followed by


ltering with H(z) as
1
M
M1

k=0

Y
_
z
1/M
e

2j
M
k
_
H(z) .
117
If we consider the combined system of ltering with H(z
M
), to get H(z
M
)

Y (z), and then


downsampling we have that the combined aect is given by
1
M
M1

k=0

Y
_
z
1/M
e
2j
M
k
_
H
_
_
z
1/M
e
2j
M
k
_
M
_
=
1
M
M1

k=0

Y
_
z
1/M
e
2j
M
k
_
H (z) ,
the same expression as before, showing the equivalence.
Noble Upsampling Identity: Recall that upsampling by M produces the new sequence
y(k) generated by the old sample function y(k) according to
y(k) =
_
y
_
k
M
_
when
k
M
is an integer
0 otherwise
(192)
Then the transfer function for this operation U(z) when the input signal is y is given by [8]
U(z) =

Y (z
M
) . (193)
Then the aect of ltering with H(z) a signal with transfer function

Y (z) is H(z)

Y (z).
Following this by upsampling by M gives the transfer function
H(z
M
)

Y (z
M
) .
This is the same as taking the input

Y (z) upsampling by M to get

Y (z
M
) and then passing
that output through the linear system H(z
M
), showing the equivalence of the two Noble
upsampling forms.
Problem 6.18 (an equivalent lter bank representation)
In gure 6.5 we have three paths to generate the outputs y
0
, y
1
, and y
2
. When drawn without
the traditional system box notation we get these three paths given by
, x(2), x(1), x(0) H
0
(z) 2 y
0
, x(2), x(1), x(0) H
1
(z) 2 H
0
(z) 2 y
1
, x(2), x(1), x(0) H
1
(z) 2 H
1
(z) 2 y
2
.
The system for y
0
matches the same system in Figure 6.6b for y
0
when we take

F
0
(z) = H
0
(z).
If we then use Nobles downsampling identity we can write the output expressions for y
1
and
y
2
as
, x(2), x(1), x(0) H
1
(z) H
0
(z
2
) 2 2 y
1
, x(2), x(1), x(0) H
1
(z) H
1
(z
2
) 2 2 y
2
.
We can simplify the two downsampling procedures of size 2 on the right side of these ex-
pressions into one downsampling expression of size 4, and combine the two serial systems to
get
, x(2), x(1), x(0) H
1
(z)H
0
(z
2
) 4 y
1
, x(2), x(1), x(0) H
1
(z)H
1
(z
2
) 4 y
2
.
This matches the system drawn in Figure 6.6 when we take

F
1
(z) = H
1
(z)H
0
(z
2
) and

F
2
(z) = H
1
(z)H
1
(z
2
) proving the equivalence.
118
Feature Generation II
Notes on the text
Notes on co-occurrence matrices
The co-occurrence matrices provide a way to measure the relative position of gray levels in
an image and as such are functions of a pixel displacement d and an angle oset . They
rely on the joint probabilities that the given image takes gray level values at the angular
direction and a distance d. Typically d = 1 while is taken to be from 0, 45, 90, 135 in
degrees. That is for = 0 we need to compute
P(I(m, n) = I
1
, I(md, n) = I
2
) =
number of pairs of pixels with levels = (I
1
, I
2
)
total number of possible pixel pairs
.
Probability density functions can be obtained for = 45 where the probability we are
extracting can be written
P(I(m, n) = I
1
, I(md, n d) = I
2
) .
To make things easier to understand assume that we have four gray levels then I(m, n)
0, 1, 2, 3 and we can dene the co-occurrence matrix A (with elements P(I
1
, I
2
) above)
when given a specication of (d, ) as
A(d, ) =
1
R
_

_
(0, 0) (0, 1) (0, 2) (0, 3)
(1, 0) (1, 1) (1, 2) (1, 3)
(2, 0) (2, 1) (2, 2) (2, 3)
(3, 0) (3, 1) (3, 2) (3, 3)
_

_
, (194)
The book writes these A matrices with as a superscript as A

(d). Here (I
1
, I
2
) is the
number of pixel pairs at a relative position of (d, ) which have a gray level pair (I
1
, I
2
)
respectively and R is the total number of pixel pairs in that orientation in the given image.
Lets consider in some detail how to compute the expression R, the number of pairs of pixels
we have to consider, in the co-occurrence matrix above for some common orientations. Lets
rst consider the case where d = 1 and = 0. Then anchored at each pixel of the image we
will try to look left and right (since = 0) by one (since d = 1) and consider the resulting
image values (I
1
, I
2
). For simplicity assume our input image has four rows/columns. Now
at the position (0, 0) (upper left corner) we can only look right (otherwise we are looking o
the image) which gives one pixel pair. If we are at the pixel (0, 1) we can look left and right
for two pairs of pixels. At the pixel located at (0, 2) we can look left and right giving two
pixel pairs, and nally at the pixel (0, 3) we can look only left giving one pixel pair. In total
this is
1 + 2 + 2 + 1 = 6 ,
left/right pairs per row. Since we have four rows we have R = 6 4 = 24 possible pairs. In
general for an image of dimension M N with M rows and N columns we have
1 + 2(N 2) + 1 = 2(N 2) + 2 = 2N 2 ,
119
pixel pairs in each row, so
R(d = 1, = 0) = M(2N 2) .
If = 90 (again with d = 1) we have 1 +2(M 2) +1 = 2M 2 pixel pairs in each column
so with N columns we have
R(d = 1, = 90) = N(2M 2) ,
pixel pairs to consider. If = 45 the rst row has no pixel pairs in the northeast direction
or of the form (I(m, n), I(m d, n + d)) since we would be looking o the image, but has
N 1 pairs in the southwest direction of the form (I(m, n), I(m + d, n d)). All rows but
the last have 2(N 2) + 2 = 2N 2 pixel pairs to consider. The last row has N 1 pixel
pairs of the form (I(m, n), I(md, n+d)) and none like (I(m, n), I(m+d, nd)). Thus in
total we have
R(d = 1, = 45) = 2(N 1) + (M 2)(2N 2) = 2(N 1)(M 1) .
The pair count for R(d = 1, = 135) should equal that of R(d = 1, = 45) but with N and
M exchanged,
R(d = 1, = 135) = 2(M 1)(N 1) .
In practice, a very simple algorithm for computing the co-occurrence matrix for given values
of d and is to start with (I
1
, I
2
) = 0 and then walk the image over all pixels looking at
the image values (I
1
, I
2
) of the two pixels specied by the (d, ) inputs and incrementing
the corresponding (I
1
, I
2
). The value of A can then be obtained after the fact by summing
all the elements of the array. In the MATLAB function co occurrence.m using this very
simple algorithm we compute the co-occurrence matrix for an input (d, ). For the sample
input image
I =
_

_
0 0 2 2
1 1 0 0
3 2 3 3
3 2 2 2
_

_
,
for (d, ) = (1, 0) this routine gives
A(1, 0) =
1
24
_

_
4 1 1 0
1 2 0 0
1 0 6 3
0 0 3 2
_

_
,
the same as in the book. In the MATLAB script dup co occurrence example.m we duplicate
all of the co-occurrence matrices from this section.
Notes on second-order statistics features
We implemented several of the summary second-order statistics discussed in this section as
MATLAB functions. In particular we implemented
120
The Angular second moment in ASM.m.
The Contrast measure in CON.m.
The Inverse dierence moment measure in IDF.m.
The Entropy measure in entropy.m.
In general, these routines can take additional input argument parameters d and that specify
the displacement and angular oset that are used in computing the given co-occurrence
matrix one uses in the feature denition. If these additional arguments are not given then
the functions above compute all four possible co-occurrence matrices, the corresponding
feature from each, and then return the average of the four feature measurements.
Notes on gray level run lengths
For these run length features we pick a direction as before, then the matrix Q
RL
() has its
(i, j)th element given by the number of time that the gray level i for i = 0, 1, N
g
1 appears
with a run length j = 1, 2, N
r
in the direction . Thus Q
RL
is a matrix of dimension N
g

N
r
. We implemented the computation of the gray level run length matrix Q
RL
in the MAT-
LAB function Q RL.m. Using that in the MATLAB function dup run length example.m we
duplicated the examples computing Q
RL
(0) and Q
RL
(45). We then implemented a number
of derivative features based on Q
RL
() such as
The short run emphasis in SRE.m.
The long run emphasis measure in LRE.m.
The gray level nonuniformity measure in GLNU.m.
The run length nonuniformity measure in RLN.m.
The run percentage measure in RP.m.
The above computations are function of the angle . As in the second order statistics above,
to make these features rotation invariant we compute them for each of the four possible
0, 45, 90, 135 values, and then return the average of these four feature measurements.
Notes on local linear transformations
Given the three basis vectors: b
1
=
_
1 2 1

, for a local average, b


2
=
_
1 0 1

for
local edge detection, and b
3
=
_
1 2 1

for local spot detection then the N


2
local
lters are given by all possible outer products or
b
1
b
T
1
, b
1
b
T
2
, b
1
b
T
3
, b
2
b
T
1
, b
2
b
T
2
, b
2
b
T
3
, b
3
b
T
1
, b
3
b
T
2
, b
3
b
T
3
.
121
Figure 17: Duplicate petasti gures used to extract Hu invariant moments from.
For example
b
T
1
b
1
=
_
_
1
2
1
_
_
_
1 2 1

=
_
_
1 2 1
2 4 2
1 2 1
_
_
.
b
T
1
b
2
=
_
_
1
2
1
_
_
_
1 0 1

=
_
_
1 0 1
2 0 2
1 0 1
_
_
.
All outer products are computed in the MATLAB script gen local linear transformations.m,
which duplicate the 9 matrices presented in the text.
Notes on geometric moments
In this section I attempted to duplicate the results in the book on using the Hu moments for
image features extraction. I rst got a set of images of the petasti symbol, see Figure 17.
Then in the MATLAB code dup Hu moments.m we load in gif versions of these images and
call the function Hu moments.m. I scaled each image to the x and y ranges [1, +1] before
computing the moments. The dynamic ranges of the higher center moments is signicantly
smaller that the earlier ones (and some seem to vanish to zero), thus to compare the extracted
moments from each images we extract and plot the logarithm of the absolute value of the
direct moments this is suggested in [4]. This gives the following
phi_1 phi_2 phi_3 phi_4 phi_5 phi_6 phi_7
image a: -14.6794 -43.7024 -59.5204 -55.4081 -115.3626 -80.8707 -112.8758
image b: -15.3285 -43.7243 -60.1944 -56.1308 -118.0532 -80.5011 -114.2937
122
image c: -14.6794 -43.7024 -59.5204 -55.4081 -115.3626 -80.8707 -112.8758
image d: -14.6794 -43.7024 -59.5204 -55.4081 -115.3626 -80.8707 -112.8758
image e: -14.6794 -43.7024 -59.5204 -55.4081 -115.3626 -80.8707 -112.8758
image f: -17.0347 -36.9026 -57.2860 -56.1632 -113.1657 -74.8205 -113.3142
In general these numbers look very similar for each of the images. I was, however, unable
to duplicate the exact numerical results for the value of
i
from the book. If anyone sees
anything wrong with what I have done or a way that I can better match the books results
please let me know.
Notes on Zernike moments
The indices for the Zernike moments require that p = 0, 1, 2, and [q[ p with p [q[
even. This means that we have the following valid combinations (for a few value of p only)
p = 0 so q = 0 only.
p = 1 so q = 1 only.
p = 2 so q 2, 0, +2.
p = 3 so q 3, 1, +1, +3.
p = 4 so q 4, 2, 0, +2, +4.
p = 5 so q 5, 3, 1, +1, +3, +5.
The pattern at this point seems clear.
Notes on Fourier features
Consider the complex boundary u
k
with the origin shifted by the index k
0
or the signal u
kk
0
.
Then this shifted boundary has Fourier features given by
f

l
=
N1

k=0
u
kk
0
e
j
2
N
lk
=
N1k
0

k=k
0
u
k
e
j
2
N
l(k+k
0
)
= e
j
2
N
lk
0
N1k
0

k=k
0
u
k
e
j
2
N
lk
.
This last sum is e
j
2
N
lk
0
f
l
, since both u
k
and e
j
2
N
lk
are periodic in the index k with a period
N. Thus we have shown
f

l
= e
j
2
N
lk
0
f
l
. (195)
Note that a shift of origin does not change the magnitude of the Fourier coecients.
123
The book then presents an argument as to why the normalized Fourier coecients are the
index location invariant. We present a somewhat dierent version of that argument here.
Since the Fourier coecients change depending on the k origin (see Equation 195 above)
we would like to dene Fourier features that are independent of this choice in origin. One
way to do that is the following. One simply computes the Fourier features directly using the
denition
f
l
=
N1

k=0
u
k
e
j
2
N
lk
, (196)
ignoring any issue of k origin. Then we explicitly write the rst Fourier complex number f
1
in polar form as f
1
= [f
1
[e
j
1
(note the negative sign in the angle). With this denition
of
1
as the polar angle for the rst Fourier feature we dene the normalized Fourier
coecients

f
l
as

f
l
= f
l
exp(jl
1
) , (197)
that is we multiply each of the previously computed Fourier coecient by a power of the
complex phase of f
1
. We claim that these normalized Fourier coecients are invariant to
the choice of the sampling origin in k. To show this imagine that we had selected a dierent
origin (say k
0
) to evaluate u
k
at. Then from Equation 195 the rst Fourier feature would be
transformed to f

1
given by the product of the old value f
1
times a phase shift or
f

1
= f
1
e
j2
k
0
N
= [f
1
[e
j
1
e
j2
k
0
N
= [f
1
[e
j(
1
+2
k
0
N
)
.
Thus the angular phase we would extract as the polar angle from f

1
is given by

1
=
1
+ 2
k
0
N
.
The normalized Fourier coecients we compute for this shifted k origin path u

k
using Equa-
tion 197 again

l
= f

l
exp(jl

1
) .
Again using Equation 195 to evaluate f

l
and replacing

1
by what we found above we get

l
= f
l
e
j
2
N
lk
0
exp
_
jl(
1
+ 2
k
0
N
)
_
= f
l
exp(jl
1
) =

f
l
,
showing that the normalized Fourier coecients are indeed invariant with respect to where
we start sampling u
k
in k.
Problem Solutions
Problem 7.1 (the ASM and the CON features)
This problem is worked in the MATLAB script prob 7 1.m.
124
Figure 18: Left: A plot of the books image1.png. Right: A plot of the books im-
age3.png.
Problem 7.2 (the run-length matrices)
This problem is worked in the MATLAB script prob 7 2.m.
Problem 7.3 (image contrast)
Consider the image
I =
_

_
0 1 0 1
1 0 1 0
0 1 0 1
1 0 1 0
_

_
Then notice that this image alternates between 0 and 1 when we look along the = 0
direction but has the same value when we look along the = 45 direction. Our routines give
CON(I, 1, 0) = 1 while CON(I, 1, 45) = 0. This problem is worked in the MATLAB script
prob 7 3.m.
Problem 7.4 (feature extraction on various test images)
For this problem we use the MATLAB command imread to load in two test images from
the book. The imread command creates a matrix with quantized gray levels that can
be processed by the routines developed on Page 120. The two test images selected (and
converted to postscript for display in this document) are shown in Figure 18. This problem
is worked in the MATLAB script prob 7 4.m. When that script is run we get the outputs
given in Table 1.
125
Feature Image #1 Image #3
ASM 0.0023 1.69 10
4
CON 25.6573 725.08
IDF 0.332 0.04
H
xy
9.6371 12.86
SRE 0.8878 0.9890
LRE 2.1792 1.0452
GLNU 269.6925 176.5214
RLN 1.0051 10
4
1.5680 10
4
Table 1: Extracted features for the two images shown in Figure 18. Note that the Image #1
has larger values for the ASM, IDF, LRE features while Image #3 has larger values for the
CON, H
xy
, and SRE features. From the discussion in the book this means that Image #1
is smoother, has less contrast, and more long runs, while Image #3 has more contrast, has
more disorder, and has more short runs. All of these properties can be heuristically veried
as true by looking at the two images given in Figure 18.
Problem 7.5 (a constrained minimization problem)
This is a constrained optimization problem so to solve it we will use the method of Lagrange
multipliers. Technically this procedure is for nding unbounded optimal. Since in addition
to the summation constraint

N
i=1
P
i
= 1 we have the constraints 0 P
i
1 we need to
make sure that the solution to the unconstrained problem also satises these constraints. To
use this method we rst form the Lagrangian
/((P
1
, P
2
, , P
N
); )
N

i=1
P
2
i

_
N

i=1
P
i
1
_
,
and then look for stationary points with respect to P (P
1
, P
2
, , P
N
) and . We have
/
P
i
= 0 2P
i
= 0 (198)
/

= 0
N

i=1
P
i
+ 1 = 0 . (199)
From Equation 198 we have P
i
=

2
, which when we put these into Equation 199 we get

2
N + 1 = 0 .
Thus =
2
N
. When we put this back into Equation 198 we have
P
i
=

2
=
1
N
,
as we were to show. Note that these solutions also satisfy 0 P
i
1 as required.
126
Problem 7.6 (moments translational and scaling invariance)
We will consider the translated image I

dened by I

(x, y) = I(x a, y b). Then

00
=
_

(x, y)dxdy =
_

I(x a, y b)dxdy =
_

I(u, v)dudv =
00
,
when we make the substitution u = xa and v = y b. The same expression holds for m
00
.
That is m

00
= m
00
=
00
=

00
. Now for m

10
we have
m

10
=
_

xI(x a, y b)dxdy =
_

(u + a)I(u, v)dudv = m
10
+ am
00
.
In the same way we nd
m

01
= m
01
+ bm
00
.
Thus the new means x

and y

are given by
x

=
m

10
m

00
=
m
10
m
00
+ a = x + a
y

=
m

01
m

00
=
m
01
m
00
+ b = y + b .
We nd for

pq

pq
=
_

(x x)
p
(y y)
q
I

(x, y)dxdy
=
_

(x x a)
p
(y y b)
q
I(x a, y b)dxdy
=
_

(u x)
p
(v y)
q
I(u, v)dudv =
pq
.
Showing that the central moments are invariant to translations. From all of this we also see
that

pq
=

pq
(

00
)

=

pq

00
,
showing that the normalized central moments are invariant to translations as we were to
show.
Now consider a scaled image I

dened as I

(x, y) = I(x, y). Then

00
=
_

(x, y)dxdy =
_

I(x, y)dxdy =
1

2
_

I(u, v)dudv =
1

00
,
when we make the substitution u = x and v = y. This also equals m

00
and m
00
. Now for
m

10
we have
m

10
=
_

xI(x, y)dxdy =
1

3
_

uI(u, v)dudv =
1

3
m
10
.
127
In the same way we have
m

01
=
1

3
m
01
.
Thus the new means x

and y

are given by
x

=
m

10
m

00
=
1

m
10
m
00
=
1

x
y

=
m

01
m

00
=
1

y .
Using these we nd for

pq

pq
=
_

I(x, y)(x x

)
p
(y y

)
q
dxdy
=
_

I(x, y)
_
x
1

x
_
p
_
y
1

y
_
q
dxdy .
Let u = x and v = y to get

pq
=
_

I(u, v)
_
u

_
p
_
v

_
q
du

dv

=
1

p+q+2
_

I(u, v)(u x)
p
(v y)
q
dudv =
1

p+q+2

pq
.
Thus the central moments

pq
are not invariant to scaling but if we consider the normalized
central moments

pq
we see that

pq
=

pq
(

00
)

=

2

p+q+2

pq

00
.
Now from the denition of we have 2 = p + q + 2 thus

pq
=
pq
as we were to show.
Problem 7.8 (rotational invariants)
If our image is rotated by and angle
0
then when we express the image in terms of polar
coordinates we have that the new image I

(, ) is given in terms of the old image I(, ) by


I

(, ) = I(,
0
) .
Then the Zernike moments of the rotated image are given by
A

pq
=
p + 1

_ _
x
2
+y
2
1
I

(x, y)V

(, )dd
=
p + 1

_ _
x
2
+y
2
1
I(,
0
)V

(, )dd .
In this integral let =
0
so that d = d and we get
A

pq
=
p + 1

_ _
x
2
+y
2
1
I(, )V

(, +
0
)dd
128
Since
V

pq
(, +
0
) = R
pq
()e
jq(+
0
)
= V

pq
(, )e
jq
0
,
the above expression for A

pq
becomes
A

pq
=
_
p + 1

_ _
x
2
+y
2
1
I(, )V

(, )dd
_
e
jq
0
= A
pq
e
jq
0
.
In deriving this result we have needed the fact that both I(, ) and V

pq
(, ) are periodic
in with period 2.
Problem 7.9 (computing the moments of Hu)
See the notes on Page 122 for a discussion on this.
Problem 7.10 (computing the Zernike moments)
See the MATLAB script dup Zernike moments.m which uses the functions Zernike moments.m
and Zernike polynomial.m to compute the Zernike moments for several values of p and q
for the petasti images. When that code is run (after some time) we nd the absolute values
of the A
1,1
, A
2,2
, A
2,0
and A
2,2
moments given by
A B C D E F
A_{1,1} 0.0016 0.0056 0.0016 0.0016 0.0016 0.3993
A_{2,-1} 0.0008 0.0029 0.0008 0.0008 0.0008 0.3204
A_{2,0} 0.0098 0.0351 0.0098 0.0098 0.0098 2.9708
A_{2,2} 0.0008 0.0029 0.0008 0.0008 0.0008 0.3204
all multiplied by 10
6
. From these numbers we can see the invariance of the Zernike moments
with rotation.
Problem 7.11 (the variance of the error or
2

)
We can compute the desired variance
2

as the expectation of
_
I(m, n)

k,l
a(k, l)I(mk, n l)
_
2
= I(m, n)
2
2I(m, n)

k,l
a(k, l)I(mk, n l)
+

k
1
,l
1
,k
2
,l
2
a(k
1
, l
1
)a(k
2
, l
2
)I(mk
1
, n l
1
)I(mk
2
, n l
2
) .
129
Taking the expectation of the right-hand-side of the above expression gives

= r(0, 0) 2

k,l
a(k, l)r(k, l) +

k
1
,l
1

k
2
,l
2
a(k
1
, l
1
)a(k
2
, l
2
)r(k
2
k
1
, l
2
l
1
) . (200)
The equation used to solve for a(k, l) requires that

k
2
,l
2
a(k
2
, l
2
)r(k
2
k
1
, l
2
l
1
) =

k
2
,l
2
r(k
1
k
2
, l
1
l
2
) = r(k
1
, l
1
) . (201)
Using this expression in the (k
2
, l
2
) summation in Equation 200 gives

= r(0, 0) 2

k,l
a(k, l)r(k, l) +

k
1
,l
1
a(k
1
, l
1
)r(k
1
, l
1
)
= r(0, 0)

k,l
a(k, l)r(k, l) ,
as we were to show.
Problem 7.13 (a rotation on u
k
)
To compute the new point (x

, y

) when a point (x, y) is rotated counterclockwise by an angle


we compute
_
x

_
=
_
cos() sin()
sin() cos()
_ _
x
y
_
.
Thus the new complex point on the boundary u

k
is given by
u

k
= x

k
+ jy

k
= (cos()x
k
sin()y
k
) + j(sin()x
k
+ cos()y
k
) (202)
= (cos() + j sin())x
k
+ (sin() + j cos())y
k
= e
j
x
k
+ j(cos() + j sin())y
k
= e
j
(x
k
+ jy
k
) = e
j
u
k
,
as we were to show.
Problem 7.14 (computing the Fourier series coecients a
n
, b
n
, c
n
and d
n
)
This problem is discussed motivated in more detail in the reference [7]. For the given Fourier
expansions of x(t) we can compute the coecients a
0
, a
n
, and b
n
by integration
a
0
=
1
T
_
T
0
x(t)dt
a
n
=
2
T
_
T
0
x(t) cos
_
2nt
T
_
dt
b
n
=
2
T
_
T
0
x(t) sin
_
2nt
T
_
dt .
130
The same type of expressions hold for the coecients in the Fourier expansion of y(t). Since
we assume that x(t) is piecewise linear it might be easier to consider the t derivative of x(t)
We can express x(t) in a dierent Fourier series as
x(t) =

n=1

n
cos
_
2nt
T
_
+
n
sin
_
2nt
T
_
.
The Fourier coecients
n
and
n
of x(t) are given by the same type of expression used to
compute a
n
and b
n
. Namely for
n
we have

n
=
2
T
_
T
0
x(t) cos
_
2nt
T
_
dt .
But since the the boundary curve in x(t) is constant over the range of times t
i1
< t < t
i
we
can evaluate this integral by summing several smaller integrals over these segments as

n
=
2
T
m

i=1
_
t
i
t
i1
x(t) cos
_
2nt
T
_
dt .
Now on the range t
i1
< t < t
i
we can introduce x
i
= x
i
x
i1
and t
i
= t
i
t
i1
and
then take x
x
i
t
i
, which is independent of t and the above integral becomes

n
=
2
T
m

i=1
x
i
t
i
_
t
i
t
i1
cos
_
2nt
T
_
dt =
2
T
m

i=1
x
i
t
i
_
T
2n
sin
_
2nt
T
_

t
i
t
i1
=
1
n
m

i=1
x
i
t
i
(sin (
i
) sin(
i1
)) ,
where we have dened
i

2nt
i
T
. The coecient
n
is dened in the same way and is given
by

n
=
1
n
m

i=1
x
i
t
i
(cos (
i
) cos(
i1
)) .
Given the original Fourier expansion of x(t) we can compute the time derivative explicitly
where we get
x(t) =
2
T

n=1
nb
n
cos
_
2nt
T
_
na
n
sin
_
2nt
T
_
.
Equating the coecients of cos
_
2nt
T
_
and sin
_
2nt
T
_
with the denitions of
n
and
n
we get
2
T
nb
n
=
n
=
1
n
m

i=1
x
i
t
i
(sin (
i
) sin(
i1
))

2
T
na
n
=
n
=
1
n
m

i=1
x
i
t
i
(cos (
i
) cos(
i1
)) .
Thus solving for a
n
and b
n
we get
a
n
=
T
2
2
n
2
m

i=1
x
i
t
i
(cos (
i
) cos(
i1
))
b
n
=
T
2
2
n
2
m

i=1
x
i
t
i
(sin (
i
) sin(
i1
)) .
131
Expressions for c
n
and d
n
for n 1 can be obtained in the same way but working with the
function y(t).
Problem 7.15 (invariants of the Fourier coecients a
n
, b
n
, c
n
, and d
n
)
If we consider a rotation of the parametrically described curve z(t) then the transformed
curve z

(t) = z(t)e
j
and the real and imaginary components of z

(t) are given in terms of


the real and imaginary components of z(t) by
x

i
= cos()x
i
sin()y
i
y

i
= sin()x
i
+ cos()y
i
.
See Equation 202. Therefore the discrete changes in x

and y

are given by
x

i
= cos()x
i
sin()y
i
y

i
= sin()x
i
+ cos()y
i
.
From the forms of a
n
, b
n
, c
n
and d
n
and how the depend on x
i
and y
i
given in Problem 7.14
we have that the Fourier coecients a
n
transforms as
a

n
=
T
2
2
n
2
m

i=1
x

i
t
i
(cos (
i
) cos(
i1
))
= cos()a
n
sin()
_
T
2
2
n
2
m

i=1
y
i
t
i
(cos(
i
) cos(
i1
))
_
= cos()a
n
sin()c
n
.
In the same way we nd that b
n
, c
n
, and d
n
transform as follows
b

n
= cos()b
n
sin()d
n
c

n
= sin()a
n
+ cos()c
n
d

n
= sin()b
n
+ cos()d
n
.
Using these expressions we can evaluate I
n
, J
n
, and K
1,n
in the rotated frame. Using the
MATHEMATICA le chap 7 prob 15.nb we simplify each expression using the above re-
lationships for a

n
, b

n
etc and show that they equal the original denitions in the original
frame.
Problem 7.16 (more Fourier invariants)
If our original boundary is given in parametric form as z(t) = x(t) + jy(t) then a rotation
counter-clockwise by the angle produces the boundary z

(t) given by z

(t) = z(t)e
j
. This
132
causes the complex Fourier coecients a
n
to transform as a

n
= a
n
e
j
. Then the suggested
features b
n
and d
mn
transform as
b

n
=
a

1+n
a

1n
a
2
1
=
a
1+n
a
1n
e
2j
a
2
1
e
2j
=
a
1+n
a
1n
a
2
1
= b
n
d

mn
=
a

1+m
n
a

1n
m
a

1
m+n
=
a
1+m
n
a
1n
m
e
j(n+m)
a
1
m+n
e
j(n+m)
= d
mn
,
showing the invariance. Multiplying our boundary by a scalar say produces the new curve
z

(t) = z(t) which gives new Fourier coecients of a

n
= a
n
. The proof above again shows
scale invariance.
Problem 7.18 (derivation of the orientation angle )
Expand the quadratic in the expression given for I() to get
I() =

i,j
_
(i x)
2
cos()
2
2(i x)(j y) sin() cos() + (j y)
2
sin()
2

=
20
cos()
2
2
11
sin() cos() +
02
sin()
2
.
The derivative of this expression with respect to is given by
I

() = 2
20
cos() sin() 2
11
cos()
2
+ 2
11
sin()
2
+ 2
02
sin() cos()
= 2(
02

20
) cos() sin() 2
11
(cos()
2
sin()
2
)
= (
02

20
) sin(2) 2
11
cos(2) .
When we set this equal to zero and then solve for we get
=
1
2
tan
1
_
2
11

02

20
_
.
For some reason the above representation of has the expression
02

20
rather than the
desired
20

02
(i.e. there is a negative sign dierence) if any one sees an error in what I
have done above please contact me.
133
Template Matching
Problem Solutions
Problem 8.1 (the edit distance)
The MATLAB function edit distance.m computes the edit distance between two words.
The call edit_distance(poem,poten) gives the distance matrix (which represents
the optimal path one would take)
0 1 2 3 4 5
1 0 1 2 3 4
2 1 0 1 2 3
3 2 1 1 1 2
4 3 2 2 2 2
The value of the corner element (here the value in the 5th row and 6th column) is the edit
distance. From the above we see that it is 2 representing the deletion of the character t
and the change of the n to an m.
Problem 8.2 (slopes of the Sakoe-Chiba constraints)
In the Sakoe-Chiba constraints part a we can take the transition from (i 1, j) to (i, j)
giving a slope of
i (i 1)
j j
= .
In the Sakoe-Chiba constraints part b we can take the transition from (i 2, j 1) to (i, j)
giving a slope of
i (i 2)
j (j 1)
= 2 .
In the Sakoe-Chiba constraints part c we can take the transition from (i 3, j 1) to (i, j)
giving a slope of
i (i 3)
j (j 1)
= 3 .
In the Sakoe-Chiba constraints part d we can take the transition from (i 3, j 2) to (i, j)
giving a slope of
i (i 3)
j (j 2)
=
3
2
.
134
Problem 8.4 (a measure of image similarity)
The expression given represents the cross-correlation coecient between the seven Hu mo-
ments of the test and the reference image. Since the Hu moments have great number of
invariants this measure of similarity might be more robust than using a direct correlation
metric.
Problem 8.5 (the Mellin transform)
Consider the scaled function f

dened by f

(x, y) = f(x, y), where > 0 is a real


constant. Then the Mellin transform for this function is given by
M

(u, v) =
__
f(x, y)x
ju1
y
jv1
dxdy .
Let x

= x and y

= y in the above to get


M

(u, v) =
__
f(x

, y

)
_
x

_
ju1
_
y

_
jv1
dx

dy

=
1

ju1

jv1

2
__
f(x

, y

)x

ju1
y

jv1
dx

dy

=
1

ju

jv
M(u, v) ,
since , and u, v are a real numbers we have [
ju
[ = 1 and [
jv
[ = 1 showing that the
magnitude of the Mellin transform is invariant to scaling.
Problem 8.6 (computational resources for correlation based matching)
In the motion compensation step we assume we have the original frame taken at the time
t and of size I J that we break up into subblocks of a smaller size say MN. The camera
or visual recording device then records another frame at the time t + 1 of the same size
M N. To develop a mapping of the frame at time t to the new frame at time t + 1 each
of the smaller M N subblocks in the rst frame must be searched for in the second frame.
Since there are on order of
IJ
MN
,
smaller subblocks in the larger I J frame we have to do this many searches for optimal
cross-correlation points. For the numbers given in this problem M = N = 16, I = 720,
J = 480, and f = 30 frames per second this number becomes 1350.
In the case where we are doing the full cross-correlation computation on every pixel (m, n)
in the test image we must compute
c(m, n) =
m+M1

i=m
n+N1

j=n
t(i, j)r(i m, j n) , (203)
135
at each of the (2p + 1)
2
pixels in the test image. Each of the sums above requires O(MN)
multiplications and additions giving a total computational cost of
(2p + 1)
2
NM .
for the full search technique. Thus the computational resources for the full search technique
is
IJ
MN
(2p + 1)
2
MNf = IJ(2p + 1)
2
f = 9.96 10
9
,
ops per second.
If we consider a two-dimensional logarithmic search we start with a test box of dimen-
sion [p, +p] [p, +p] and in this box compute the cross-correlation at 8 points (and the
center) spaced at a distance of
p
2
around this center. This means that we compute the
cross-correlation at the points
(0, 0) ,
_
p
2
,
p
2
_
,
_
p
2
, 0
_
,
_
p
2
,
p
2
_
,
_
0,
p
2
_
,
_

p
2
,
p
2
_
,
_

p
2
, 0
_
,
_

p
2
,
p
2
_
,
_
0,
p
2
_
.
From the cross-correlation computed at these points we nd the point with the largest cross-
correlation. We now impose a box of size
_

p
2
,
p
2

p
2
,
p
2

on the maximal point and search


the 8 points on the perimeter of a box with edge spaced
p
4
from this new center. We will
specify a new center to search about k = log
2
(p) times. Each new center requires 8 cross-
correlation searches thus including the cross-correlation taken at the rst center we have
8k + 1 cross-correlations. Since each of these cross-correlations takes MN calculations the
total operations required using this method is
IJ
MN
(8k + 1)MNf = IJ(8k + 1)f = 0.342 10
9
,
ops per second.
The linear variant of the two-dimensional logarithmic search searches the top and bottom
locations but not the diagonal locations searched in the full two-dimensional search. We
search
_
0,
p
2
_
and
_
0,
p
2
_
for the vertical search and
_

p
2
, 0
_
and
_
p
2
, 0
_
for the horizontal
search. This gives four cross-correlation calculations for every central point and again we
have k = log
2
(p) total computations. Since each of these cross-correlations takes MN
calculations the total operations required using this method is
IJ
MN
(4k + 1)MNf = IJ(8k + 1)f = 0.176 10
9
,
ops per second.
136
Context-Dependent Classication
Notes on the text
Notes on Channel Equalization
The total number of clusters will be equal to the number of possible vectors of the form
x
T
k
=
_
x
k
x
k1
x
k2
x
kl+2
x
kl+1

,
where there are l samples of the noisy x
k
. The last samples is x
kl+1
and from the model of
the noisy transmission channel is given in terms of the binary inputs I
k
as
x
k
= f(I
k
, I
k1
, , I
kn+2
, I
kn+1
) ,
will need a total of n samples in the past of I
k
to determine the value of x
kl+1
. Thus to
know the value of x
k
dened above we need
I
k
, I
k1
, I
k2
, , I
kl+2
, I
kl+1
, I
kl
, , I
kln+3
, I
kln+2
,
or k (k l n+2) +1 = l +n1 samples of I
k
starting from I
k
and working backwards to
I
kln+2
. If the value of I
k
are binary valued then we have a total of 2
l+n1
distinct inputs
to produce 2
l+n1
distinct vectors x (this ignores the value of the noise term
t
which would
only spread the samples x
k
about the cluster centers).
From this discussion we can construct Table 9.1 by forming all possible sequences of three
bit patterns for the inputs I
k
that we would need to know to determine the lagged vector x
k
having two elements i.e. x
T
k
=
_
x
k
x
k1

. That is we can have (I


k
, I
k1
, I
k2
) be (0, 0, 0),
(0, 0, 1), (0, 1, 0), (1, 0, 0) etc. and the observed outputs of x
k
and x
k1
are computed from
the model (ignoring noise)
x
k
= 0.5I
k
+ I
k1
.
Notes on Hidden Markov Models
From the initial denition of (i
k+1
) we can express it as
(i
k+1
) = p(x
1
, . . . , x
k+1
, i
k+1
[o) (204)
=

i
k
(i
k
)P(i
k+1
[i
k
)p(x
k+1
[i
k+1
) , (205)
by using the rule of total probability when we sum over all ways in which we can get into
the state i
k+1
from states i
k
1, 2, , M.
137
Problem Solutions
Problem 9.2 (self-transition probabilities)
To be in state i for d successful strategies means that we take d 1 transitions that result
in no movement of our underlying state. That is d 1 times we stay put (this happens with
probability P(i[i)) and on the dth transition we move somewhere else (which happens with
probability 1 P(i[i)). Thus the probability we stay in state i for d successive stages is
P(i[i)
d1
(1 P(i[i)) .
Note that this expression works for d = 1 since the start state is i. This is called a geometric
distribution [10] and has an expected number of transitions needed to leave the state i given
by
1
1 P(i[i)
.
If P(i[i) 1 then

d can be very large resulting in many self transitions.
138
Chapter 10 (System Evaluation)
Notes on the text
Notes on the error counting approach
When, for a given classier, our empirical error rate for the ith class 1 i M is given
by the frequency count

P
i
=
k
i
N
i
. With this, an estimate for the total error rate

P of this
classier is given by

P =
M

i=1
P(
i
)

P
i
.
Since the random variables k
i
(the number of misclassications in class i) is a binomial
random variable with parameters (P
i
, N
i
) we have that the variance in k
i
given by the
standard formula

2
k
i
= N
i
P
i
(1 P
i
) . (206)
Here P
i
is the true error rate in the ith class. We can estimate the variance in our estimate
of the total error probability

P by assuming that the k
i
random variables are independent.
We then have that

P
=
M

i=1
P(
i
)
2
N
2
i

2
k
i
=
M

i=1
P(
i
)
2
P
i
(1 P
i
)
N
i
, (207)
when we put in Equation 206. Warning: Im not sure I follow the argument that the k
i
random variables are independent. I would assume that the error made in classifying class
i would inuence whether or not one made an error in class j for j ,= i, even if the feature
vectors x are independent. If anyone has a better argument or explanation please contact
me.
139
Problem Solutions
Problem 10.1 (the expectation and variance of a binomial RV)
For a binomial random variable (RV) with probability of success p and dening q = 1 p
we nd its expectation given by E(X)
E(K) =
N

k=0
k
_
N
k
_
p
k
q
Nk
=
N

k=1
k
n!
k!(n k)!
p
k
q
Nk
=
N

k=1
n!
(k 1)!(n k)!
p
k
q
Nk
= n
N

k=1
(n 1)!
(k 1)!((n 1) (k 1))!
p
k1
q
(n1)(k1)
= np
N

k=1
_
n 1
k 1
_
p
k1
q
(n1)(k1)
= np
N1

k=0
_
n 1
k
_
p
k
q
(n1)k
= np 1 = np .
140
Next we need to evaluate E(K
2
). We nd
E(K
2
) =
N

k=0
k
2
_
N
k
_
p
k
q
Nk
=
N

k=1
k
n(n 1)!
(k 1)!(n k)!
p
k1+1
q
(n1)(k1)
= np
N

k=1
(k 1 + 1)
_
n 1
k 1
_
p
k1
q
(n1)(k1)
= np
N

k=1
(k 1)
_
n 1
k 1
_
p
k1
q
(n1)(k1)
+ np
N

k=1
_
n 1
k 1
_
p
k1
q
(n1)(k1)
= np
N

k=2
(k 1)
_
n 1
k 1
_
p
k1
q
(n1)(k1)
+ np
N1

k=0
_
n 1
k
_
p
k
q
(n1)k
= np
N

k=2
(n 1)(n 2)!
(k 2)!((n 1) (k 1))!
p
k2+1
q
(n2)(k2)
+ np
= n(n 1)p
2
N

k=2
_
n 2
k 2
_
p
k2
q
(n2)(k2)
+ np
= n(n 1)p
2
N2

k=0
_
n 2
k
_
p
k
q
(n2)k
+ np
= n(n 1)p
2
+ np .
Thus the variance of a binomial random variable is given by combining these two results as
Var(K) = E(K
2
) E(K)
2
= n(n 1)p
2
+ np n
2
p
2
= np(1 p) = npq . (208)
141
Clustering: Basic Concepts
Notes on the text
Notes on similarity measures for real-valued vectors
The Tanimoto measure/distance is given by
s
T
(x, y) =
x
T
y
[[x[[
2
+[[y[[
2
x
T
y
. (209)
Since (x y)
T
(x y) = [[x[[
2
+[[y[[
2
2x
T
y we have that s
T
(x, y) becomes
s
T
(x, y) =
x
T
y
(x y)
T
(x y) + x
T
y
=
1
1 +
(xy)
T
(xy)
x
T
y
.
If [[x[[ = [[y[[ = a, then we have
s
T
(x, y) =
x
T
y
2a
2
x
T
y
=
1
1 + 2
a
2
x
T
y
.
Problem Solutions
Problem 11.1
If s is a similarity measure on X with s(x, y) > 0 for all x, y X by dening d(x, y) =
a
s(x,y)
with a > 0 we claim that d(x, y) is a dissimilarity measure. To be a dissimilarity measure
we need to satisfy several things. Note that since s(x, y) is a positive similarity measure we
have that 0 < s(x, y) s
0
and thus
a
s
0

a
s(x, y)
< +.
Thus d(x, y) is bounded as
a
s
0
d(x, y) < +. Next for notational simplication lets dene
d
0

a
s
0
. Note that d(x, x) is given by
d(x, x) =
a
s(x, x)
=
a
s
0
= d
0
.
Next the arguments of d are symmetric in that
d(x, y) =
a
s(x, y)
=
a
s(y, x)
= d(y, x) .
142
Thus we have shown that d is a dissimilarity measure (DM) on X. If we have d(x, y) = d
0
then this implies that s(x, y) = s
0
which happens if and only if x = y, since s(x, y) is a
metric similarity measure. Finally, by the property of s(x, y) we have
s(x, y)s(y, z) [s(x, y) + s(y, z)]s(x, z) x, y X . (210)
We can write this in terms of d(x, y) as
a
d(x, y)
a
d(y, z)

_
a
d(x, y)
+
a
d(y, z)
_
a
d(x, z)
.
As d(x, y) > 0 this equals
d(x, z) d(y, z) + d(x, y) ,
or the nal condition for a metric dissimilarity measure.
Problem 11.2
Note that if we take p = 2 in the Minkowski inequality we have
[[x + y[[
2
[[x[[
2
+[[y[[
2
. (211)
To make this match the normal denition of the triangle inequality lets introduce three new
vectors a, b, and c such that
x + y = a c
x = a b .
These two equations require that y is given by
y = a c x = a c a + b = b c .
Then using Equation 211 we get
[[a c[[
2
[[a b[[
2
+[[b c[[
2
,
or
d(a, c) d(a, b) + d(b, c) ,
which is the triangle inequality.
Problem 11.4
Consider d
2
(x, y) = f(d(x, y)) where d(x, y) is a metric dissimilarity measure. Then
d
2
(x, x) = f(d(x, x)) = f(d
0
) x X ,
and
d
2
(x, y) = f(d(x, y)) = f(d(y, x)) = d
2
(y, x) x, y X .
143
If we have d
2
(x, y) = f(d
0
) or f(d(x, y)) = f(d
0
) then since f is monotonic we can invert
the above equation to get d(x, y) = d
0
. From the properties of d we know that this happens
if and only if x = y.
Next since f() is increasing and d(x, z) d(x, y) + d(y, z) we have
f(d(x, z)) f(d(x, y) + d(y, z)) .
Using the stated properties of f this expression on the right is bounded above by
f(d(x, y)) + f(d(y, z)) = d
2
(x, y) + d
2
(y, z) .
These show that d
2
(x, y) is a dissimilarity metric.
Problem 11.5
For this problem we will look at the various properties that a dissimilarity metric must
satisfy and then show that d(x, y) f(s(x, y)) satises them, when f is a function that
has the properties specied. To begin note that d(x, x) = f(s(x, x)) = f(s
0
) for all x X.
Lets dene d
0
f(s
0
) for notational simplicity. As a second property of d note that d is
symmetric in its arguments since
d(x, y) = f(s(x, y)) = f(s(y, x)) = d(y, x) .
Now if d(x, y) = d
0
= f(s
0
) then since f is monotone and increasing we can invert this last
equation to get s(x, y) = s
0
which imply that x = y. Next consider d(x, y) + d(y, z) which
from the assumed hypothesis is greater than
f
_
1
1
s(x,y)
+
1
s(y,z)
_
= f
_
s(x, y)s(y, z)
s(x, y) + s(y, z)
_
. (212)
Since s(x, y) is a similarity metric it must satisfy Equation 210 so that
s(x, y)s(y, z)
s(x, y) + s(y, z)
s(x, z) .
Since f is monotonically increasing the right-hand-side of Equation 212 is less than f(s(x, z)) =
d(x, z). Thus we have shown that d(x, y) + d(y, z) d(x, z) so d is a dissimilarity metric.
Problem 11.6
For this problem we want to show that
d

(x, y) d
2
(x, y) d
1
(x, y) , (213)
144
when all of the weights w
i
in their denitions are equal to one. This is equivalent to showing
max
1il
[x
i
y
i
[
_
l

i=1
[x
i
y
i
[
2
_
1/2

i=1
[x
i
y
i
[ .
To show this later expression consider the rst inequality. In that expression let i

be dened
as
i

= argmax
1il
[x
i
y
i
[ .
Then we have
_
l

i=1
[x
i
y
i
[
2
_
1/2
=
_
[x
i
y
i
[
2
+
l

i=1;i=i

[x
i
y
i
[
2
_
1/2
= [x
i
y
i
[
_
1 +
1
[x
i
y
i
[
l

i=1;i=i

[x
i
y
i
[
2
_
1/2
.
Since
1
|x
i
y
i
|

l
i=1;i=i

[x
i
y
i
[
2
> 0 we see that the right-hand-side of the above equality is
greater than or equal to [x
i
y
i
[, showing
d
2
(x, y) d

(x, y) .
Next consider d
2
2
(x, y) =

l
i=1
[x
i
y
i
[
2
in comparison to d
2
1
(x, y). This later expression is
equal to
d
2
1
(x, y) =
_
l

i=1
[x
i
y
i
[
_
2
=
l

i=1
[x
i
y
i
[
2
+ 2
l

i=1
l

j=i+1
[x
i
y
i
[[x
j
y
j
[ .
Note that the right-hand-side of the above is larger than the sum
l

i=1
[x
i
y
i
[
2
= d
2
2
(x, y) .
Thus
d
2
1
(x, y) d
2
2
(x, y) or d
1
(x, y) d
2
(x, y) ,
showing the second half of the requested identity.
Problem 11.7
Part (a): That the maximum of s
q
F
(x, y) is l
1/q
can be seen since each term in its sum has
the property 0 s(x
i
, y
i
) 1 and so
l

i=1
s(x
i
, y
i
)
q

i=1
1 = l .
145
Thus
s
q
F
(x, y) l
1/q
(214)
Question: How show that s
F
(x, y)
1
2
l
1/q
?
Part (b): If we let i

= argmax
i
s(x
i
, y
i
) then
s(x
i
, y
i
)
s(x
i
, y
i
)
1 for 1 i l .
Then writing s
q
F
(x, y) as
s
q
F
(x, y) = s(x
i
, y
i
)
_
l

i=1;i=i

_
s(x
i
, y
i
)
s(x
i
, y
i
)
_
q
+ 1
_
1/q
.
Since lim
q
x
q
= 0 if [x[ < 1 we have
lim
q
s
q
F
(x, y) = s(x
i
, y
i
) = max
1il
s(x
i
, y
i
) .
Problem 11.8
Question: How to show for these similarity functions that
s(x, y)s(y, z) [s(x, y) + s(y, z)]s(x, z)
for all x, y, z X.
Problem 11.9
A proximity measure is a general notation for either a dissimilarity measure or a similar-
ity measure. Consider the denition of s
ps
avg
(x, C) which is the point-set average similarly
between the set C and the point x given by
s
ps
avg
(x, C) =
1
n
C

yC
s(x, y) .
Since d
ps
avg
(x, C) is equal to
d
ps
avg
(x, C) =
1
n
C

yC
d(x, y) ,
and d
max
can be written as
d
max
=
1
n
C

yC
d
max
,
146
the dierence between these two expressions gives
d
max
d
ps
avg
(x, C) =
1
n
C

yC
d
max

1
n
C

yC
d(x, y)
=
1
n
C

yC
(d
max
d(x, y))
=
1
n
C

yC
s(x, y) s
ps
avg
(x, C) .
Problem 11.10
Recall that d
Hamming
(x, y) is equal to the number of places where the two vectors dier. Using
the contingency table A we can write
d
Hamming
(x, y) =
k1

i=1
k1

j=0;j=i
a
ij
,
or the sum of the o-diagonal elements of the contingency table A. Recall that
d
2
(x, y) =

_
l

i=1
(x
i
y
i
)
2
.
Now if x, y 0, 1
l
then if x
i
= y
i
then (x
i
y
i
)
2
= 0 (as always) while if x
i
,= y
i
then
(x
i
y
i
)
2
= 1. Thus the sum above

l
i=1
(x
i
y
i
)
2
equals the number of elements that dier.
This is the same denition of the Hamming distance.
Problem 11.13
In general we can determine proximity functions between a point and a set from proximity
functions between two sets by converting one of the sets to a set with a single point x.
For example the max set-set similarity measure
s
ss
max
(D
i
, D
j
) = max
xD
i
,yD
j
s(x, y) ,
would be converted to a point-set similarity function in the straight forward way as
s
ps
max
(x, D
j
) = max
yD
j
s(x, y) .
147
Clustering Algorithms I:
Sequential Algorithms
Notes on the text
Notes on the number of possible clusterings
In this section of the text we would like to evaluate the numerical value of S(N, m) so that
we can determine if we need a clustering with m clusters from N points how many dierent
clusterings would we have to search over to nd the optimal clustering given some clustering
criterion. We can compute S(N, m) in terms of smaller values of N and m in the following
way. Assume that we have N 1 points and we will add another point to get a total of N.
We can add this additional point N in two ways and end up with m clusters
If we have m clusters of N 1 points we can add this new point as a member of any
of the m clusters to create m clusters of N points. This can be done in mS(N 1, m)
ways.
If we have m1 clusters of N 1 points we can add this new point as a new singleton
cluster to create m clusters of N points. This can be done in S(N 1, m1) ways.
Since each of these is exclusive we can enumerate the totality of S(N, m) ways to form m
clusters from N points as
S(N, m) = mS(N 1, m) + S(N 1, m1) .
We are told that the solution to this is given by the Stirling number of the second kind or
S(N, m) =
1
m!
m

i=0
(1)
mi
_
m
i
_
i
N
.
If m = 2 we can evaluate the above expression as
S(N, 2) =
1
2
2

i=0
(1)
2i
_
2
i
_
i
N
=
1
2
__
2
0
_
0
N

_
2
1
_
1
N
+ 2
N
_
= 2
N1
1 ,
or the books equation 12.3.
Notes on sequential clustering algorithms (BSAS) and (MBSAS)
In the MATLAB/Octave code BSAS.m and MBSAS.m we have implemented the basic and modi-
ed sequential algorithm schemes. To verify their correctness, in the script dup figure 12 1.m
148
4 3 2 1 0 1 2 3 4
0.8
1
1.2
1.4
1.6
1.8
2
2.2
2.4
2.6
4 3 2 1 0 1 2 3 4
0.8
1
1.2
1.4
1.6
1.8
2
2.2
2.4
2.6
Figure 19: A duplicate of the books gure 12.1. Left: Running BSAS with q, the maximum
number of clusters, taken to be q = 3 (or larger) Right: Running BSAS with q = 2.
we duplicated data like that presented in the books gure 12.1. Next we provide Mat-
lab/Octave code that duplicates the books gure 12.2. The script dup figure 12 2.m gener-
ates a very simple two cluster data set and then calls the function estimateNumberOfClusters.m
which runs the BSAS algorithm many times each time with a randomly selected data order-
ing. When we run that script we obtain the two plots shown in Figure 20.
Notes on a two-threshold sequential scheme (TTSAS)
Next we provide Matlab/Octave code that duplicates the books gure 12.3. The script
dup figure 12 3.m creates the data suggested in example 12.3 (a very simple two cluster
data set) and then calls the function MBSAS.m and the TTSAS.m. Where the Matlab/Octave
code in TTSAS.m is an implementation of the two-threshold sequential scheme described in
the book. When we run that script we obtain the two plots shown in Figure 21. Note
that I was not able to get the MBSAS algorithm to show the three class clustering claimed
in the book. Using the suggested value of = 2.5 gave the plot shown in Figure 21 (left).
Increasing the threshold value for to 3 however gave the same two clustering result that
TTSAS gave shown in Figure 21 (right).
Notes on renement stages
On the web site that accompanies this text one can nd the Matlab procedure merging.m
that implements the merging procedure discussed in in section of the text. To demonstrate
the usage of the merging.m routine, in the Matlab script merging example.m we consider
the same data from Example 12.3 and clustered using the routine MBSAS.m. The results
from running this clustering are presented in Figure 22 (left) there we see four clusters
have been found. We next run the merging.m code on the resulting clusters and obtain
149
10 5 0 5 10 15 20 25
5
0
5
10
15
20
25
5 10 15 20 25 30 35
0
5
10
15
20
25
30
35
40
theta
m
o
s
t

f
r
e
q
u
e
n
t

n
u
m
b
e
r

o
f

c
l
u
s
t
e
r
s
Figure 20: A duplicate of the books gure 12.2. Left: The initial data chosen to run the
estimateNumberOfClusters.m function on. Right: A plot of the most frequent (mode)
number of clusters found for each value of . This plot looks similar to the one presented
in the book. The long stretch of values of where the mode is 2 indicates that 2 maybe a
good value for the number of clusters present.
0 1 2 3 4 5 6 7
0
1
2
3
4
5
6
0 1 2 3 4 5 6 7
0
1
2
3
4
5
6
Figure 21: Plots duplicating the books gure 12.3. Left: The cluster labels produced using
the MBSAS algorithm on the data set of example 12.3, and using the parameters given in the
book. Note that I was not able to exactly duplicate the cluster results given in the book.
Right: The result of apply the TTSAS algorithm on the data set of example 12.3.
150
0 1 2 3 4 5 6 7
0
1
2
3
4
5
6
0 1 2 3 4 5 6 7
0
1
2
3
4
5
6
Figure 22: Plots to show the results from using the merging.m routine. Left: The cluster
labels produced using the MBSAS algorithm on the data set from example 12.3. Note that we
found four clusters. Right: The result of applying the merging algorithm on the resulting
data set. We have merged two of the original clusters leaving two larger clusters.
Figure 22 (right). Note that we need to use a larger value for M
1
= 2.85 than the value of
= 1.5 that which we used in clustering with MBSAS.
Problem Solutions
Problem 12.1 (the number of binary divisions of N points)
In this problem we prove by induction that given a set with N points the number of binary
divisions (divisions into two non empty sets) is given by 2
N1
1. See also page 157 where
some alternative derivations of this same result are given. To begin note that from exam-
ple 12.1 in the book that when N = 3 the number of binary divisions S(3, 2) = 3 which also
equals the expression 2
N1
1 when N = 3. Thus we have shown the required base case for
an induction proof. Lets assume that
S(N, 2) = 2
N1
1 for N N
1
,
and consider the evaluation of S(N
1
+1, 2). We can count the number of binary divisions of
a set with N
1
+1 points (and evaluate S(N
1
+1, 2)) in the following way. First we can take
each of the pairs of sets formed from N
1
points (of which there are S(N
1
, 2) of them) and
introduce this N
1
+ 1-st point into either of the pairs. This would give 2S(N
1
, 2) sets with
N
1
+ 1 points. In addition, we can add this N
1
-st point as a singleton set (a set with only
one element) to the set with all other N
1
points. This can be done in only one way. Thus
we have expressed S(N
1
+ 1, 2) as
S(N
1
+ 1, 2) = 2S(N
1
, 2) + 1 .
151
Using the induction hypothesis we nd
S(N
1
+ 1, 2) = 2(2
N
1
1
1) + 1 = 2
N
1
1 ,
as the number of binary divisions of a set with N
1
+ 1 points. As this satises our desired
expression for N
1
+ 1 points we have proven the requested expression is true.
Problem 12.2 (recursively updating the cluster mean vector)
Since the mean vector of an old cluster C
old
k
is dened as
m
C
old
k
=
1
n
C
old
k

x
i
C
old
k
x
i
,
we can represent the sum over all points in C
old
k
cleanly as the product n
C
old
k
m
C
old
k
. If we merge
another cluster D with n
D
points into C
old
k
to make a new cluster such that C
new
k
= C
old
k
D
then the new mean vector over this merged cluster is given by
m
C
new
k
=
1
n
C
new
k
_
_

x
i
C
old
k
x
i
+

x
i
D
x
i
_
_
=
1
n
C
new
k
_
n
C
old
k
m
C
old
k
+

x
i
D
x
i
_
.
If we only have one point in D denoted as x then n
C
new
k
= n
C
old
k
+ 1 and using the above we
get
m
C
new
k
=
(n
C
new
k
1)m
C
old
k
+ x
n
C
new
k
the requested expression.
Problem 12.3 (experiments with the BSAS and MBSAS algorithm)
Problem 12.4 (more experiments with BSAS and MBSAS)
Problem 12.5 (clustering in a square)
Problem 12.6 (estimating the number of clusters)
152
4 3 2 1 0 1 2 3 4 5
1
1.5
2
2.5
3
3.5
4
4.5
5
5.5
6
4 3 2 1 0 1 2 3 4 5
1
1.5
2
2.5
3
3.5
4
4.5
5
5.5
6
4 3 2 1 0 1 2 3 4 5
1
1.5
2
2.5
3
3.5
4
4.5
5
5.5
6
Figure 23: Some examples using the MATLAB function histfit function to plot normal
densities on some toy data sets. Left: Center: Right:
4 3 2 1 0 1 2 3 4 5
1
1.5
2
2.5
3
3.5
4
4.5
5
5.5
6
4 3 2 1 0 1 2 3 4 5
1
1.5
2
2.5
3
3.5
4
4.5
5
5.5
6
4 3 2 1 0 1 2 3 4 5
1
1.5
2
2.5
3
3.5
4
4.5
5
5.5
6
Figure 24: Some examples using the MATLAB function histfit function to plot normal
densities on some toy data sets. Left: Center: Right:
153
Clustering Algorithms II:
Hierarchical Algorithms
Notes on the text
Notes on agglomerative algorithms based on matrix theory
In this section of the book some algorithms for agglomerative clustering are introduced.
These algorithms are presented in an way that involves modications of the starting input
dissimilarity matrix P
0
= P(X) by modifying this matrix as clustering proceeds in stages
from the initial singleton clusters of 1
0
which consist of only the points x
i
to the cluster
1
N1
that contains all points in one cluster. What is not suciently emphasized in this
section is that these clusters can be formed based only on the specied pairwise proximity
measure between points. In normal clustering problem we initially have access to the sample
points x
i
from which we can then form the initial proximity matrix P
0
= P(X), which
has elements T(x
i
, x
j
) for i, j 1, 2, , N. Once this initial matrix is formed we can
eectively forget the original data points x
i
and work only with these proximity matrices
P
t
. At the step t > 1, once we have decided to merge two clusters C
i
and C
j
into a new cluster
C
q
the rst step in obtaining the new proximity matrix P
t
from the old P
t1
is to remove
the ith and jth rows and columns of P
t1
. This corresponds to removing clusters C
i
and C
j
since their data are now merged into the new cluster C
q
. Next, a new row and column is
added to the modied proximity matrix P
t1
. This added row measures the cluster distances
between the new cluster C
q
and all existing unmodied clusters C
s
for s 1, 2, , N t
and s , i, j. The values in the new proximity matrix P
t
are created using elements derived
from
d(C
q
, C
s
) = f(d(C
i
, C
s
), d(C
j
, C
s
), d(C
i
, C
j
)) , (215)
for some function f(, , ) of three arguments. As a nal comment most clustering algorithms
can be express f in a simpler form as
d(C
q
, C
s
) = a
i
d(C
i
, C
s
) + a
j
d(C
j
, C
s
) + bd(C
i
, C
j
)
+ c[d(C
i
, C
s
) d(C
j
, C
s
)[ , (216)
for various values of a
i
, a
j
, b, and c. Note that in the above expression all of these cluster
distances d(, ) have already been computed previously and can be found in the old proximity
matrix P
t1
.
Notes on the minimum variance clustering algorithm (Ward)
In this section of these notes we derive the result that Wards linkage algorithm is equivalent
to merging the two clusters that lead to the smallest possible increase in the total variance.
We assume that the clusters C
i
and C
j
are to be merged at the iteration t +1 into a cluster
denoted C
q
and all other clusters remain the same. We begin by dening the total variance
154
E
t
over all clusters at step t by
E
t
=
Nt

r=1
e
2
r
, (217)
where e
r
is the scatter around the rth cluster given by
e
r
=

r
[[x m
r
[[
2
. (218)
Then the change in the total variance denoted by E
t+1
E
t
where E
t
is the total cluster
variance at step t dened above under the merge of the clusters C
i
and C
j
will be
E
ij
t+1
= e
2
q
e
2
i
e
2
j
. (219)
Noting that we can express

xCr
[[x m
r
[[
2
as

xCr
[[x m
r
[[
2
=

xCr
([[x[[
2
2x
T
m
r
+[[m
r
[[
2
)
=

xCr
[[x[[
2
2
_

xCr
x
T
_
m
r
+ n
r
[[m
r
[[
2
=

xCr
[[x[[
2
2n
r
m
T
r
m
r
+ n
r
[[m
r
[[
2
=

xCr
[[x[[
2
2n
r
[[m
r
[[
2
+ n
r
[[m
r
[[
2
=

xCr
[[x[[
2
n
r
[[m
r
[[
2
. (220)
This last equation is the books equation 13.16. If we use expressions like this to evaluate
the three terms e
q
, e
i
and e
j
we have
E
ij
t+1
=

xCq
[[x[[
2
n
q
[[m
q
[[
2

xC
i
[[x[[
2
+ n
i
[[m
i
[[
2

xC
j
[[x[[
2
+ n
j
[[m
j
[[
2
= n
i
[[m
i
[[
2
+ n
j
[[m
j
[[
2
n
q
[[m
q
[[
2
. (221)
Since when we merge cluster C
i
and C
j
into C
q
we take all of the points from C
i
and C
j
in
forming C
q
we have

xCq
[[x[[
2
=

xC
i
[[x[[
2
+

xC
j
[[x[[
2
.
An equivalent statement of the above in terms of the means m
i
and the number of elements
summed in each mean n
i
is
n
i
m
i
+ n
j
m
j
= n
q
m
q
,
since the product n
i
m
i
is just the sum of the x vectors in C
i
. From this last expression we
compute
[[m
q
[[
2
=
1
n
2
q
[[n
i
m
i
+ n
j
m
j
[[
2
=
1
n
2
q
(n
2
i
[[m
i
[[
2
+ 2n
i
n
j
m
T
i
m
j
+ n
2
j
[[m
j
[[
2
) .
155
Thus using this expression in Equation 221 we can write E
ij
t+1
as
E
ij
t+1
= n
i
[[m
i
[[
2
+ n
j
[[m
j
[[
2

1
n
q
(n
2
i
[[m
i
[[
2
+ 2n
i
n
j
m
T
i
m
j
+ n
2
j
[[m
j
[[
2
) .
Since we have n
q
= n
i
+ n
j
this simplies to
E
ij
t+1
=
1
n
q
_
n
2
i
[[m
i
[[
2
+ n
i
n
j
[[m
i
[[
2
+ n
i
n
j
[[m
j
[[
2
+ n
2
j
[[m
j
[[
2
n
2
i
[[m
i
[[
2
2n
i
n
j
m
T
i
m
j
n
2
j
[[m
j
[[
2

=
n
i
n
j
n
q
_
[[m
i
[[
2
2m
T
i
m
j
+[[m
j
[[
2

=
n
i
n
j
n
q
[[m
i
m
j
[[
2
.
This last equation is the books equation 13.19.
Notes on agglomerative algorithms based on graph theory
In this section it can be helpful to discuss Example 13.4 in some more detail. Now in going
from the clustering 1
2
= x
1
, x
2
, x
3
, x
4
, x
5
to 1
3
we are looking for the smallest
value of a such that the threshold graph G(a) has the property h(k). Thus we compute
g
h(k)
(C
r
, C
s
) for all pairs (C
r
, C
s
) of possible merged clusters. In this case the two clusters
we would consider merging in the new clustering 1
3
are
x
1
, x
2
x
3
, x
3
x
4
, x
5
, or x
1
, x
2
x
4
, x
5
.
The smallest value of g
h(k)
using these pairs is given by 1.8 since when a = 1.8, the threshold
graph G(a) of x
3
x
4
, x
5
is connected (which is property h(k) for this example).
Another way to view the numerical value of the function g
h(k)
(C
r
, C
s
) is to express its meaning
in words. In words, the value of the function
g
h(k)
(C
r
, C
s
) ,
is the smallest value of a such that the threshold graph G(a) of the set C
r
C
s
is connected
and has either one of two properties:
The set C
r
C
s
has the property h(k).
The set C
r
C
s
is complete.
Thus we see that the value of g
h(k)
(x
1
, x
2
, x
3
, x
4
, x
5
) is 2.5 since in this example this is
where the threshold graph G(2.5) of x
1
, x
2
x
3
, x
4
, x
5
= X is now connected which is
property h(k) for the single link algorithm.
156
Notes on divisive algorithms
The book claims the result that the number of possible partition of of N points into two sets
is given by 2
N1
1 but no proof is given. After further study (see Page 148) this result
can be derived from the Stirling numbers of the second kind S(N, m) by taking the number
of clusters m = 2 but we present two alternative derivations here that might be simpler to
understand.
Method 1: The rst way to derive this result is to consider in how many ways could we
label each of the points x
i
such that each point is in one cluster. Since each point can be in
one of two clusters we can denote its membership by a 0 or a 1 depending on which cluster
a given point should be assigned. Thus the rst point x
1
has 2 possible labelings (a 0 or a
1) the second point x
2
has the same two possible labelings etc. Thus the total number of
labeling for all N points is
2 2 2 2 = 2
N
.
This expression over counts the total number of two cluster divisions in two ways. The rst
is that it includes the labeling where every point x
i
gets the same label. For example all
points are labeled with a 1 or a 0, of which there are two cases giving
2
N
2 .
This number also over counts the number of two cluster divisions in that it includes two
labelings for each allowable cluster. For example, using the above procedure when N = 3
we have the possible labelings
x
1
x
2
x
3
0 0 0 X
0 0 1 1
0 1 0 2
0 1 1 3
1 0 0 3
1 0 1 2
1 1 0 1
1 1 1 X
In the above we have separated the labelings and an additional piece of information with a
vertical pipe [. We present the two invalid labelings that dont result in two nonempty sets
with an X. Note also that the labeling 0 , 0 , 1 and 1 , 1 , 0 are equivalent in that they have the
same points in the two clusters. To emphasis this we have denoted the 3 pairs of equivalent
labelings with the integers 1, 2 and 3. Thus we see that the above counting represents twice
as many clusters. Thus the number of two cluster divisions is given by
1
2
(2
N
2) = 2
N1
1 ,
as we were to show.
Method 2: In this method we recognize that the total problem of counting the number
of partitions of the N points into two clusters has as a subproblem counting the number of
157
ways we can partition of the N points into two sets of size k and N k. This subproblem
can be done in
_
N
k
_
ways. Since we dont care how many points are in the individual
clusters the total number of ways in which we can perform a partition into two sets might
be represented like
N1

k=1
_
N
k
_
.
Here we have exclude from the above sum the sets with k = 0 and K = N since they
correspond to all of the N points in one set and no points in the other set. The problem
with this last expression is that again it over counts the number of sets. This can be seen
from the identity
_
N
k
_
=
_
N
N k
_
. Thus to correctly count these we need to divide
this expression by two to get
1
2
N1

k=1
_
N
k
_
.
We can evaluate this expression if we recall that
N

k=0
_
N
k
_
= 2
N
, (222)
Using this the above becomes
1
2
N1

k=1
_
N
k
_
=
1
2
_
2
N

_
N
0
_

_
N
N
__
=
1
2
(2
N
2) = 2
N1
1 ,
the same expression as earlier.
Problem Solutions
Problem 13.1 (the denitions of the pattern / proximity matrix)
Part (a): The pattern matrix D(X) is the N l matrix whos ith row is the transposed ith
vector of X. This matrix thus contains the N feature vectors as rows stacked on top of each
other. Since the proximity matrix P(X) is the N N with (i, j)th elements that are given
by either s(x
i
, x
j
) if the proximity matrix corresponds to a similarity matrix or to d(x
i
, x
j
)
if the proximity matrix corresponds to a dissimilarity matrix. The term proximity matrix
covers both cases. Thus given the pattern matrix D(X) an application of the proximity
function will determine a unique proximity matrix
Part (b): To show that a proximity matrix does not determine the pattern matrix one
would need to nd two sets feature vectors that are the same under the Euclidean distance.
The scalar measurements 1, 2, 3 with the dissimilarity metric d(x, y) = [xy[ has a proximity
158
matrix given by
_
_
0 1 2
1 0 1
2 1 0
_
_
.
While the scalar values 3, 4, 5 have the same proximity matrix. These two sets have dierent
pattern matrices given by
_
_
1
2
3
_
_
and
_
_
3
4
5
_
_
.
Problem 13.2 (the unweighted group method centroid (UPGMC))
To solve this problem lets rst show that
n
1
[[m
1
m
3
[[
2
+ n
2
[[m
2
m
3
[[
2
=
n
1
n
2
n
1
+ n
2
[[m
1
m
2
[[
2
(223)
Since n
3
= n
1
+ n
2
and C
3
= C
1
C
2
, we can write m
3
as
m
3
=
1
n
3

xC
3
x =
1
n
3
_

xC
1
x +

xC
2
x
_
=
1
n
3
[n
1
m
1
+ n
2
m
2
] .
Now the left-hand-side of Equation 223 denoted by
LHS = n
1
[[m
1
m
3
[[
2
+ n
2
[[m
2
m
3
[[
2
,
using the above for m
3
is given by
LHS = n
1

_
1
n
1
n
3
_
m
1

n
2
n
3
m
2

2
+ n
2

_
1
n
2
n
3
_
m
2

n
1
n
3
m
1

2
= n
1
_
1
n
1
n
3
_
2
[[m
1
[[
2
2n
1
_
1
n
1
n
3
__
n
2
n
3
_
m
T
1
m
2
+ n
1
n
2
2
n
2
3
[[m
2
[[
2
+ n
2
_
1
n
2
n
3
_
2
[[m
2
[[
2
2n
2
_
1
n
2
n
3
__
n
1
n
3
_
m
T
1
m
2
+ n
2
n
2
1
n
2
3
[[m
2
[[
2
=
_
n
1
_
1 2
n
1
n
3
+
n
2
1
n
2
3
_
+ n
2
_
n
2
1
n
2
3
__
[[m
1
[[
2
2
_
n
1
_
1
n
1
n
3
__
n
2
n
3
_
+ n
2
_
1
n
2
n
3
__
n
1
n
3
__
m
T
1
m
2
+
_
n
1
n
2
2
n
2
3
+ n
2
_
1 2
n
2
n
3
+
n
2
2
n
2
3
__
[[m
2
[[
2
.
Next consider the coecient of [[m
1
[[
2
. We see that it is equal to
n
1
n
2
3
(n
2
3
2n
1
n
3
+ n
2
1
) + n
2
_
n
2
1
n
2
3
_
=
n
1
n
2
3
(n
3
n
1
)
2
+ n
2
_
n
2
1
n
2
3
_
=
n
1
n
2
n
2
3
(n
2
+ n
1
) =
n
1
n
2
n
3
.
159
The same type of transformation changes the coecient of [[m
2
[[
2
into
n
1
n
2
n
3
also. For the
coecient of m
T
1
m
2
we have
_
n
1
_
1
n
1
n
3
__
n
2
n
3
_
+ n
2
_
1
n
2
n
3
__
n
1
n
3
__
=
n
1
n
2
n
3
_
1
n
1
n
3
+ 1
n
2
n
3
_
=
n
1
n
2
n
3
_
2
n
1
+ n
2
n
3
_
=
n
1
n
2
n
3
.
Using all three of these results we have that
LHS =
n
1
n
2
n
3
_
[[m
1
[[
2
2m
T
1
m
2
+[[m
2
[[
2

=
n
1
n
2
n
3
[[m
1
m
2
[[
2
,
which we were to show. Now we can proceed to solve the requested problem. We begin by
recalling that the recursive matrix update algorithm for UPGMC when we merge cluster C
i
and C
j
into C
q
is given by
d
qs
=
_
n
i
n
i
+ n
j
_
[[m
i
m
s
[[
2
+
n
j
n
i
+ n
j
[[m
j
m
s
[[
2

n
i
n
j
(n
i
+ n
j
)
2
[[m
i
m
j
[[
2
. (224)
If we use Equation 223 with m
1
= m
i
, m
2
= m
j
and m
3
= m
q
to express [[m
i
m
j
[[
2
in the
above as
[[m
i
m
j
[[
2
=
_
n
i
+ n
j
n
i
n
j
_
[n
i
[[m
i
m
q
[[
2
+ n
j
[[m
j
m
q
[[
2
]
Using this we can then write d
qs
as
d
qs
=
n
i
n
q
[[m
i
m
s
[[
2
+
n
j
n
q
[[m
j
m
s
[[
2

n
i
n
q
[[m
i
m
q
[[
2

n
j
n
q
[[m
j
m
q
[[
2
=
1
n
q
_
n
i
([[m
i
m
s
[[
2
[[m
i
m
q
[[
2
) + n
j
([[m
j
m
s
[[
2
[[m
j
m
q
[[
2
)

.
To simplify this recall that for any two vectors a and b we have
[[a[[
2
[[b[[
2
= (a b)
T
(a + b) = (a + b)
T
(a b) ,
as one can prove by expanding out the product in the right-hand-side. Using this we can
write d
qs
as
d
qs
=
1
n
q
_
n
i
(m
i
m
s
+ m
i
m
q
)
T
(m
i
m
s
(m
i
m
q
))
+ n
j
(m
i
m
s
+ m
j
m
q
)
T
(m
j
m
s
(m
j
m
q
))

=
1
n
q
_
n
i
(2m
i
m
s
m
q
)
T
(m
q
m
s
) + m
j
(2m
j
m
s
m
q
)
T
(m
q
m
s
)

=
1
n
q
[n
i
(2m
i
m
s
m
q
) + m
j
(2m
j
m
s
m
q
)]
T
(m
q
m
s
)
=
1
n
q
[2n
i
m
i
+ 2n
j
m
j
n
i
m
s
n
i
m
q
n
j
m
s
n
j
m
q
]
T
(m
q
m
s
) .
160
Since n
i
m
i
+ n
j
m
j
= n
q
m
q
the above becomes
d
qs
=
1
n
q
[(n
i
+ n
j
)m
q
n
i
m
s
n
j
m
s
]
T
(m
q
m
s
)
=
1
n
q
[n
i
(m
q
m
s
) + n
j
(m
q
m
s
)]
T
(m
q
m
s
)
=
1
n
q
(n
i
+ n
j
)(m
q
m
s
)
T
(m
q
m
s
) = [[m
q
m
s
[[
2
,
which is the result we wanted to show.
Problem 13.3 (properties of the WPGMC algorithm)
The weighted pair group mean centroid (WPGMC) algorithm has an update equation for
d
qs
given by
d
qs
=
1
2
d
is
+
1
2
d
js

1
4
d
ij
.
That there exists cases where d
qs
min(d
is
, d
js
) is easy to see. Consider any existing cluster
C
s
that is equally distant between C
i
and C
j
or d
is
= d
js
= min(d
is
, d
js
). A specic example
of three clusters like this could be created from single points if needed. Then in this case
using the above WPGMC update algorithm we would have
d
qs
= d
is

1
4
d
ij
d
is
= min(d
is
, d
js
) .
Problem 13.4 (writing the Ward distance as a MUAS update)
The Ward or minimum variance algorithm denes a distance between two clusters C
i
and
C
j
as
d

ij
=
n
i
n
j
n
i
+ n
j
[[m
i
m
j
[[
2
.
We want to show that this distance update can be written in the form of a MUAS algorithm
d(C
q
, C
s
) = a
i
d(C
i
, C
s
) + a
j
d(C
j
, C
s
) + bd(C
i
, C
j
) + c[d(C
i
, C
s
) d(C
j
, C
s
)[ . (225)
In problem 3.2 we showed that
d
qs
=
n
i
n
i
+ n
j
d
is
+
n
j
n
i
+ n
j
d
js
d
is

n
i
n
j
(n
i
+ n
j
)
2
d
ij
= [[m
q
m
s
[[
2
.
As suggested in the hint lets multiply both sides of this expression by the expression
(n
i
+n
j
)ns
n
i
+n
j
+ns
to get
(n
i
+ n
j
)n
s
n
i
+ n
j
+ n
s
[[m
q
m
s
[[
2
=
n
i
n
s
n
i
+ n
j
+ n
s
d
is
+
n
j
n
s
n
i
+ n
j
+ n
s
d
js

n
i
n
j
n
s
(n
i
+ n
j
)(n
i
+ n
j
+ n
s
)
d
ij
.
161
Writing n
q
= n
i
+ n
j
the left-hand-side of the above becomes
n
q
n
s
n
q
+ n
s
d
qs
= d

qs
,
while the right-hand-side becomes
n
i
+ n
s
n
i
+ n
j
+ n
s
_
n
i
n
s
n
i
+ n
j
_
d
is
+
n
j
+ n
s
n
i
+ n
j
+ n
s
_
n
j
n
s
n
j
+ n
s
_
d
js

n
s
n
i
+ n
j
+ n
s
_
n
i
n
j
n
i
+ n
j
_
d
ij
,
or introducing thee denition of d

and equating these two expressions we have


d

qs
=
n
i
+ n
s
n
i
+ n
j
+ n
s
d

is
+
n
j
+ n
s
n
i
+ n
j
+ n
s
d

js

n
s
n
i
+ n
j
+ n
s
d

ij
.
This is the books equation 13.13 which we were to show.
Problem 13.5 (Wards algorithm is the smallest increase in variance)
This problem is worked on Page 154 of these notes.
Problem 13.7 (clusters distances from the single link algorithm)
The single link algorithm in the matrix updating algorithmic scheme (MUAS) has a dissim-
ilarity between the new cluster C
q
formed from the clusters C
i
and C
j
and an old cluster C
s
given by
d(C
q
, C
s
) = min(d(C
i
, C
s
), d(C
j
, C
s
)) . (226)
We desire to show that this distance is equal to the smallest pointwise distance for point
taken from the respective clusters or
d(C
q
, C
s
) = min
xCq,yCs
d(x, y) . (227)
At step R
0
when every cluster is a single point Equation 227 is true since C
q
and C
s
are
singleton point sets i.e. sets with only one element in them. Assuming that at level t the
clusters at that level in 1
t
have clusters distances where Equation 227 holds we will now
prove that the clusters at level t + 1 will also have distances that satisfy this property.
Consider the next cluster level R
t+1
, where we form the cluster C
q
from the sets C
i
and C
j
say picked as specied by the Generalized Agglomerative Scheme (GAS) with
g(C
i
, C
j
) = min
r,s
g(C
r
, C
s
) ,
where g is a dissimilarity measure. Thus to show that Equation 227 holds between the new
set C
q
and all the original unmerged sets from R
t
we use Equation 226 to write
d(C
q
, C
s
) = min(d(C
i
, C
s
), d(C
j
, C
s
)) ,
162
1
2 3 4 5
1
.0
1
.5
2
.0
2
.5
3
.0
3
.5
4
.0
Cluster Dendrogram
agnes (*, "single")
P
H
e
ig
h
t
1
4 5 2 3 0
2
4
6
8
Cluster Dendrogram
agnes (*, "complete")
P
H
e
ig
h
t
Figure 25: Left: Single link clustering on the dissimilarity matrix for problem 13.10. Right:
Complete link clustering on the dissimilarity matrix for problem 13.10.
and then use the induction hypothesis to write the above as
d(C
q
, C
s
) = min
_
min
x
1
C
i
,y
1
Cs
d(x
1
, y
1
), min
x
2
C
j
,y
2
Cs
d(x
2
, y
2
)
_
= min
xC
i
C
j
,yCs
d(x, y) .
This last expression is what we wanted to prove.
Problem 13.8 (clusters distances from the complete link algorithm)
All of the arguments in Problem 13.7 are still valid for this problem when we replace minimum
with maximum.
Problem 13.9 (similarity measures vs. dissimilarity measures)
For this problem one simply replaces dissimilarities d(x, y) with similarities s(x, y) and re-
places minimizations with maximizations in the two earlier problems. All of the arguments
are the same.
Problem 13.10 (some simple dendrograms)
Note that for this proximity matrix we do have ties in P (for example P(2, 3) = 1 =
P(4, 5)) and thus as discussed in the book we may not have a unique representations for the
dendrogram produced by the complete link clustering algorithm. The single link clustering
163
1
2
3
4 5
1
.0
1
.5
2
.0
2
.5
3
.0
3
.5
4
.0
Cluster Dendrogram
agnes (*, "single")
P
H
e
ig
h
t
1 2
3
4 5 0
2
4
6
8
Cluster Dendrogram
agnes (*, "complete")
P
H
e
ig
h
t
Figure 26: Left: Single link clustering on the dissimilarity matrix for problem 13.12. Right:
Complete link clustering on the dissimilarity matrix for problem 13.12.
algorithm should produce a unique dendrogram however. We can use the R language to
plot the associated single and complete link dendrograms. See the R le chap 13 prob 10.R
for the code to apply these clustering procedures to the given proximitry matrix. Two
dendrograms for this problem that are output from the above script are shown in Figure 25.
Problem 13.12 (more simple dendrograms)
Part (a): Note that for this proximity matrix we have ties in P (for example P(2, 3) =
3 = P(4, 5)) and thus we may not have a unique representation of the dendrogram for the
complete link clustering algorithm. The histogram may depend on the order in which the two
tied results are presented to the clustering algorithm. The single link clustering algorithm
should be unique however. See the R le chap 13 prob 12.R for numerical code to perform
complete and single link clustering on the given proximity matrix. Results from running this
code are presented in Figure 26.
Problem 13.13 (a specication of the general divisive scheme (GDS))
To begin this problem, recall that in the general divisive clustering scheme the rule 2.2.1
is where given a cluster from the previous timestep, C
t1,i
, we consider all possible pairs of
clusters (C
r
, C
s
) that could form a partition of the cluster C
t1,i
. From all possible pairs we
search to nd the pair (C
1
t1,i
, C
2
t1,i
) that gives the maximum value for g(C
r
, C
s
) where g(, )
is some measure of cluster dissimilarity. In this problem we are further restricting the general
partioning above so that we only consider pairs (C
1
t1,i
, C
2
t1,i
) where C
t1,i
= C
1
t1,i
C
2
t1,i
and C
1
t1,i
only has one point. We can consider the total number of cluster comparisons
required by this process as follows.
164
At t = 0 there is only one cluster in 1
0
and we need to do N comparisons of the values
g(x
i
, X x
i
) for i = 1, 2, , N to nd the single point to split rst.
At t = 1 we have two clusters in 1
1
where one cluster a singleton (has only a single
point) and the other cluster has N 1 points. Thus we can only possibly divide the
cluster with N 1 points. Doing that will require N 1 cluster comparisons to give
1
2
.
In general, we see that at step t we have N t comparisons to make to derive the new
clustering 1
t+1
from 1
t
.
Thus we see that this procedure would require
N + (N 1) + (N 2) + + 3 ,
comparisons. The above summation stops at three because this is the number of comparisons
required to nd the single split point for a cluster of three points. The above sum can be
evaluated as
_
N

k=1
k
_
1 2 =
N(N + 1)
2
3 =
N
2
+ N 6
2
.
The merits of this procedure is that it is not too computationally demanding since it is an
O(N
2
) procedure. From the above discussion we would expect that this procedure will form
clusters that are similar to that formed under single link clustering i.e. the clusters will most
likely possess chaining. Note that in searching over such a restricted space for the two sets
C
1
t1,i
and C
2
t1,i
this procedure will not fully explore the space of all possible partitions of
C
t1,i
and thus could result in non optimal clustering.
Problem 13.14 (the alternative divisive algorithm)
The general divisive scheme (GDS) for t > 0 procedes by consideing all clusters C
t1,i
for
i = 1, 2, , t from the clustering 1
t1
and for each cluster all their 2
|C
t1,i
|1
1 possible
divisions into two sets. Since the procedure we apply in the GDS is the same for each
timestep t we can drop that index from the cluster notation that follows.
The alternative divisive algoithm searches over much fewer sets than 2
|C
i
|1
1 required by
the GDS by instead performing a linear search on the [C
i
[ elements of C
i
. Since for large
values of [C
i
[ we have
[C
i
[ 2
|C
i
|1
1 ,
this alternative procedure has a much smaller search space and can result in signicant
computational savings over the GDS.
The discription of this alternative partiioning procedure for C
i
is as follows. We start with
an empty set C
1
i
= and a full set C
2
i
, where the full set is initialized to be C
i
. As a
rst step, we nd the vector x in the full set, C
2
i
, whos average distance with the remaining
vectors in C
2
i
is the largest and move that point x into the emtpy set C
1
i
. If we dene g(x, C)
165
to be a function that measures the average dissimilarity between a point x and the set C
the rst point we move into C
1
i
will be the point x that maximizes
g(x, C
2
i
x) ,
where C
2
i
x means the set C
2
i
but without the point x in it. After this initial point
has been moved into C
1
i
we now try to move more points out of the full set C
2
i
and into the
empty set C
1
i
as follows. For all remaining x C
2
i
we would like to move a point x into C
1
i
from C
2
i
if the dissimilarity of x with C
1
i
is smaller than that of x with C
2
i
(without x) or
g(x, C
1
i
) < g(x, C
2
i
x) .
Motivated by this expression we compute
D(x) g(x, C
2
i
x) g(x, C
1
i
) ,
for all x C
2
i
. We then take the point x

that makes D(x) largest but only if at x

the value
of D(x

) is still positive. If no such point exists that is D(x) < 0 for all x or equivalently
g(x, C
1
i
) > g(x, C
2
i
x) ,
then we stop and return the two sets (C
1
i
, C
2
i
). Note that this procedure cannot gaurentee to
give the optimal partition of the set C
i
since we are limiting our search of possible splits over
the much smaller space of pairwise sets than the full general divisive scheme would search
over.
Problem 13.15 (terminating the number of clusters on = + )
This problem refers to Method 1 for determining the number of clusters suggested by the
data. To use this method one needs to introduce a set function h(C) that provides a way of
measuring how dissimilar the vectors in a given set are. Common measures for h(C) might
be
h(C) = max
x,yC
d(x, y)
h(C) = median
x,yC
d(x, y) ,
where d(, ) is a dissimilarity measure. Then we stop clustering with 1
t
at level t when there
is a cluster in 1
t+1
(the next level) that is so large that it has points that are too dissimilar
to continue. Mathematically that means that we keep the 1
t
clustering (and cluster farther
than the 1
t+1
clustering) if
C
j
1
t+1
such that h(C
j
) > ,
where the threshold still has to be determined experimentally. To help in evaluating the
value of we might write it as
= + ,
166
where is the average dissimilarity between two points in the full set X and is the variance
of that distance. These can be computed as
=
2
N(N 1)
N

i=1
N

j=i+1
d(x
i
, x
j
)

2
=
2
N(N 1)
N

i=1
N

j=i+1
(d(x
i
, x
j
) )
2
.
Thus when the choice of the value of the threshold is transfered to the choice of a value for
we are eectivly saying that we will stop clustering when we get sets that have a average
dissimilatrity greater than standard deviations from the average pointwise dissimilarity.
167
Clustering Algorithms III:
Schemes Based on Function Optimization
Notes on the text
Notes on compact and hyperellipsoidal clusters
The equations presented in the book for estimating
j
and
j
are derived earlier in these
notes, see Page 26.
Note I believe there is a typo in the books more general expression for the M-step in the ex-
pectation maximization (EM) algorithm. The book starts by dening our objective function
Q(; (t)) given by
Q(; (t)) =
N

i=1
m

j=1
P(C
j
[x
i
; (t)) ln(p(x
i
[C
j
; )P
j
) , (228)
and then argues that the parameters of the jth cluster
j
are functionally independent of the
parameters of the kth cluster when k ,= j. Thus when we take the
j
derivative of the above
expression to nd the maximum of Q(; (t)) we loose any reference to any other clusters
k ,= j. Thus the sum over j falls away and we get
N

i=1
P(C
j
[x
i
; (t))

j
ln(p(x
i
[C
j
;
j
) = 0 . (229)
The book has an additional sum over the index j which I believe should not be there.
Even though the EM algorithm for the multidimensional case is derived on Page 26. I found
the derivation given in the Appendix of this chapter informative and wanted to further
elucidate the discussion there. In this derivation we wish to consider Equation 229 where
the elements of
j
are the individual elements of the jth covariance matrix
j
. To this end
we take the derivative of ln() with respect to the (r, s) element of the inverse of
j
, which
we denote as
rs
. This means that

rs
ln(p(x[C
j
;
j
) =

rs
_
ln
_
[
1
j
[
(2)
l/2
_

1
2
(x
j
)
T

1
j
(x
j
)
_
=
1
2
1
[
1
j
[

rs
[
1
j
[
1
2
(x
r

jr
)(x
s

js
)
=
1
2
[
j
[

rs
[
1
j
[
1
2
(x
r

jr
)(x
s

js
) .
To evaluate the partial derivative of [
1
j
[ with respect to one of its elements we will use one
way of computing the determinate [11]. For example with a general matrix A, by using the
cofactor expansion of the determinant about the ith row we can write
[A[ = a
i1
C
i1
+ a
i2
C
i2
+ + a
in
C
in
.
168
Where C
ij
= (1)
i+j
[M
ij
[ is the cofactor of the (i, j)th element and M
ij
is the minor of the
(i, j)th element. In that case we see that the partial derivative of [A[ with respect to one of
its element, say a
ij
is given by
[A[
a
ij
= C
ij
. (230)
From this fact we see that

rs
ln(p(x[C
j
;
j
) =
1
2
[
j
[C
rs

1
2
(x
r

jr
)(x
s

js
) .
Thus letting C
j
be the matrix with cofactor elements C
ij
corresponding to the matrix
1
j
we have that in matrix notation the above is

1
j
ln(p(x[C
j
;
j
) =
1
2
[
j
[C
j

1
2
(x
j
)(x
j
)
T
.
The cofactor matrix C
j
is special in that it is related to the inverse of the generating matrix
(here
1
j
). One can show [11] that
(
1
j
)
1
=
C
T
j
[
1
j
[
.
Thus C
T
j
= [
1
j
[
j
and since
j
is a symmetric matrix this gives that the product [
j
[C
j
in

rs
ln(p(x[C
j
;
j
) above simplies to [
j
[C =
j
and we have

1
j
ln(p(x[C
j
;
j
) =
1
2

j

1
2
(x
j
)(x
j
)
T
. (231)
Now when we put this into Equation 229 we get
1
2

j
N

i=1
P(C
j
[x
i
; (t))
1
2
N

i=1
P(C
j
[x
i
; (t))(x
i

j
)(x
i

j
)
T
= 0 ,
or when we solve for
j
we get

j
=

N
i=1
P(C
j
[x
i
; (t))(x
i

j
)(x
i

j
)
T

N
i=1
P(C
j
[x
i
; (t))
. (232)
The expression given in the book.
Notes on Example 14.4 (hard clustering vs. fuzzy clustering)
Recall the expression for the fuzzy objective function J
q
(, U) which is given by
J
q
(, U) =
N

i=1
m

j=1
u
q
ij
d(x
i
,
j
) .
169
In this example for the hard clustering we take U
hard
=
_

_
1 0
1 0
0 1
0 1
_

_
so that J becomes
J
hard
q
(, U) =
4

i=1
2

j=1
u
q
ij
d(x
i
,
j
) = d(x
1
,
1
) + d(x
2
,
1
) + d(x
3
,
2
) + d(x
4
,
2
)
= 1 + 1 + 1 + 1 = 4 ,
which has a value independent of q. Now take q = 1 and fuzzy clustering where we nd
J
fuzzy
1
(, U) = u
11
d(x
1
,
1
) + u
12
d(x
1
,
2
)
+ u
21
d(x
2
,
1
) + u
22
d(x
2
,
2
)
+ u
31
d(x
3
,
1
) + u
32
d(x
3
,
2
)
+ u
41
d(x
4
,
1
) + u
42
d(x
4
,
2
) .
From facts like d(x
1
,
1
) = d(x
2
,
1
) = 1 and d(x
1
,
2
) =

1 + 3
2
=

10 = d(x
2
,
2
) the
above is given by
J
fuzzy
1
(, U) = u
11
+ u
12

10 + u
21
+ u
22

10 + u
3

10 + u
32
+ u
41

10 + u
42
=
2

i=1
(u
i1
+ u
i2

10) +
4

i=3
(u
i1

10 + u
i2
) .
Since 0 u
i1
1 and u
i2
= 1 u
i2
we can write the argument of the rst summation as
u
i1
+ u
i2

10 =

10 + (1

10)u
i1
.
Since 1

10 < 0 to make this expression as small as possible we take u


i1
as large as
possible. Thus take u
i1
= 1 and we get
u
i1
+ u
i2

10 1 .
For the argument of the second summation we have
u
i1

10 + u
i2
= u
i1

10 + (1 u
i1
) = 1 + (

10 1)u
i1
.
Since

10 1 > 0 to make this expression as small as possible we take u


i1
as small as
possible. Thus take u
i1
= 0 and we get
u
i1

10 + u
i2
1 .
Thus we have shown that
J
fuzzy
1
(, U)
2

i=1
1 +
4

i=3
1 = 4 .
If we next take q = 2 then our fuzzy objective function is given by
J
fuzzy
2
(, U) =
2

i=1
(u
2
i1
+ u
2
i2

10) +
4

i=3
(u
2
i1

10 + u
2
i2
) .
170
Consider the argument of the rst sum u
2
i1
+ u
2
i2

10 as a function of u
i2
or the expression
(1u
i2
)
2
+u
2
i2

10. If we seek to nd the extrema of this function by taking the u


i2
derivative
of it we see that we need to solve
2(1 u
i2
)(1) + 2u
i2

10 = 0 ,
for u
i2
. A second derivative of this expression is given by
2 + 2

10 > 0 ,
showing that the extrema found would be a minimum. Thus the maximum of this expression
happens at the end points of the u
i2
domain. If we consider the two end points u
i2
= 0 and
u
i2
= 0.48 we get
(1 u
i2
)
2
+ u
2
i2

10

u
i2
=0
= 1
(1 u
i2
)
2
+ u
2
i2

10

u
i2
=0.48
= 0.998 ,
where we see that we have a maximum value of one over the interval u
i2
[0, 0.48]. If the
same expression holds for the argument of the second sum we have
J
fuzzy
2
(, U)
2

i=1
1 +
4

i=3
1 4 ,
as we were to show. Thus fuzzy clustering with q = 2 produces an objective function of
lesser value that of hard clustering.
If we next take q = 3 then our fuzzy objective function is given by
J
fuzzy
3
(, U) =
2

i=1
(u
3
i1
+ u
3
i2

10) +
4

i=3
(u
3
i1

10 + u
3
i2
) .
Consider the argument of the rst sum u
3
i1
+ u
3
i2

10 as a function of u
i2
or the expression
(1u
i2
)
3
+u
3
i2

10. If we seek to nd the extrema of this function by taking the u


i2
derivative
of it we see that we need to solve
3(1 u
i2
)
2
(1) + 3u
2
i2

10 = 0 ,
for u
i2
. A second derivative of this expression is given by
6(1 u
i2
) + 6

10u
i2
= 6 + 6(

10 1)u
i2
> 0 ,
showing that the extrema found would be a minimum. Thus the maximum of this expression
happens at the end points of the u
i2
domain. If we consider the two end points u
i2
= 0 and
u
i2
= 0.67 we get
(1 u
i2
)
3
+ u
3
i2

10

u
i2
=0
= 1
(1 u
i2
)
3
+ u
3
i2

10

u
i2
=0.67
= 0.987 ,
again showing that the maximum is given by the value 1. The same expression holds for the
argument of the second sum and in the same way as before we have
J
fuzzy
3
(, U) 4 ,
as we were to show.
171
Notes on the minimization of J
q
(, U))
Recall that the objective function J
q
that we want to minimize is given by
J
q
(; U) =
N

i=1
m

j=1
u
q
ij
d(x
i
,
j
) . (233)
where
j
are cluster representatives (numerical parameters that determine the type of
cluster) and U is a matrix with (i, j)th element u
j
(x
i
) or the membership of the x
i
sample
i = 1, 2, , N in the jth cluster j = 1, 2, m. We would like to minimize this with respect
to both the cluster representatives
j
and the sample memberships U. Since the cluster
memberships are constrained such that u
ij
[0, 1] and
m

j=1
u
ij
= 1 for i = 1, 2, N ,
we must use the methods of constrained optimizing. In this direction we introduce Lagrange
multipliers
i
(one for each sample) and the Lagrangian dened by
(, U) =
N

i=1
m

j=1
u
q
ij
d(x
i
;
j
)
N

i=1

i
_
m

j=1
u
ij
1
_
. (234)
With this Lagrangian we rst take the derivative of with respect to the (r, s) element of
U, set the result equal to zero and solve for u
rs
. We nd the derivative set equal to zero
given by

u
rs
= qu
q1
rs
d(x
r
,
s
)
r
= 0 .
or u
rs
given by
u
rs
=
_

r
qd(x
r
,
s
)
_ 1
q1
. (235)
When we put this into the constraints
m

j=1
u
ij
= 1
_

r
q
_ 1
q1
m

j=1
1
d(x
r
,
j
)
1
q1
= 1 ,
or
_

r
q
_ 1
q1
=
1

m
j=1
_
1
d(xr,
j
)
_ 1
q1
, (236)
and solving for
r
we get

r
=
q
_

m
j=1
_
1
d(xr,
j
)
_ 1
q1
_
q1
(237)
172
When we put this expression for
r
in the form of Equation 236 into Equation 235 we see
that u
rs
is given by
u
rs
=
1
d(x
r
,
s
)
1
q1
_
_
_
1

m
j=1
_
1
d(xr,
j
)
_ 1
q1
_
_
_
=
1

m
j=1
_
d(xr,s
d(xr,
j
)
_ 1
q1
(238)
which holds for r = 1, N and s = 1, 2, m. Now that we have found the optimal U
given a xed values for
j
we now search for the optimal
j
given values of U. To do this we
need to solve
J

j
= 0 for
j
. We nd this last equation given by

j
=
N

i=1
u
q
ij
d(x
i
,
j
)

j
= 0 . (239)
Unless we specify a functional form for d(, ) we cannot go further.
The algorithm for nding the full solution (both U and
j
for j = 1, 2, , m) then becomes
to iterate between the two routines above. One way to do this is to pick initial values for the
cluster representatives
j
(0) for each j and then use Equation 238 to compute u
ij
(1). With
these new values for u
ij
(1) we solve for
j
(1) in Equation 239. This procedure is iterated by
stepping from
j
(t) to u
ij
(t) to
j
(t + 1) to u
ij
(t + 1) etc. until convergence.
Notes on the minimization of J
q
(, U) with point represented clusters)
We can now specify Equation 239 to some special cluster types and representatives. As a
rst case we consider
j
to be a point representation of a cluster (and thus it is simply a
vector of dimension l) and take d(x
i
,
j
) to be a typical dissimilarity metric. Two simple
cases are
A Mahalanobis type distance for d(x
i
,
j
)
d(x
i
,
j
) = (
j
x
i
)
T
A(
j
x
i
) . (240)
Then the derivative of d(x
i
,
j
) with respect to
j
is
d(x
i
,
j
)

j
= 2A(
j
x
i
) .
With this Equation 239 is
N

i=1
u
q
ij
(t 1)A(
j
x
i
) = 0 .
173
or by multiplying by A
1
we get
_
N

i=1
u
q
ij
(t 1)
_

j

N

i=1
u
q
ij
(t 1)x
i
= 0 ,
so

j
=

N
i=1
u
q
ij
(t 1)x
i

N
i=1
u
q
ij
(t 1)
. (241)
A Minkowski distance for d(x
i
,
j
)
d(x
i
,
j
) =
_
l

k=1
[x
ik

jk
[
p
_
1
p
. (242)
Then the derivative of d(x
i
,
j
) with respect to the rth component of
j
is
d(x
i
,
j
)

jr
=
1
p
_
l

k=1
(x
ik

jk
)
p
_
1
p
1
p (x
ir

jr
)
p1
=
(
jr
x
ir
)
p1
_

l
k=1
(x
ik

jk
)
p
_1
p
1
. (243)
for r = 1, 2, , l. This means that using Equation 239 specied to the
jr
derivative
we must solve
N

i=1
u
q
ij
(t 1)
_

_
(
jr
x
ir
)
p1
_

l
k=1
(x
ik

jk
)
p
_1
p
1
_

_
= 0 for r = 1, 2, , l .
Since there are l equations above and l components of
j
we expect there to be a unique
solution.
Notes on quadratic surfaces as representatives
In the quadratic surface representation
x
T
Ax + b
T
x + c = 0 , (244)
since x is of dimension l and the matrix A is symmetric it therefore has
1
2
l(l 1) unique
elements in its upper (or lower) triangular part. There are l additional elements on its
diagonal. Thus to specify the unique values of the matrix A we have to specify
l +
1
2
l(l 1) =
1
2
l(l + 1) ,
numbers. There are l numbers needed to specify the vector b and 1 number needed to specify
the number c. Thus if we recast the quadratic surface representation above into the form
q(x)
T
p = 0 , (245)
174
the vector p must have
1
2
l(l + 1) + l + 1 ,
numbers.
Notes on computing the perpendicular distance
In this section of these notes we discuss how to evaluate the perpendicular distance between
a point x and a quadratic surface Q dened by
d
2
p
(x, Q) = min
z
[[x z[[
2
, (246)
subject to the constraint on z such that z
T
Az + b
T
z + c = 0. We form the Lagrangian T
T(x, Q) = [[x z[[
2
(z
T
Az + b
T
z + c) . (247)
and take derivatives in the normal way. The z derivative gives
T
z
= 2(x z) 2Az b = 0 ,
On expanding
2x (2I + 2A)z b = 0 ,
or
z = (2I + 2A)
1
(2x b) =
1
2
(I + A)
1
(2x b) . (248)
We then put this into z
T
Az +b
T
z +c = 0 to get a polynomial in which gives several roots
for
k
. For each root
k
we can evaluate z
k
= z(
k
) using Equation 248 and then select the
value for d
2
p
(x, Q) that gives the smallest value
d
2
p
(x, Q) = min

k
[[x z(
k
)[[
2
.
Notes on adaptive fuzzy C-shells (AFCS) clustering algorithms
We start with our objective function
J
nr
(, U) =
N

i=1
m

j=1
u
q
ij
d
2
nr
(x
i
, Q
j
) , (249)
175
and set derivatives equal to zero to get the equations we must solve for optimal solutions.
We start with

c
j
of d
2
nr
(x, ; c
j
, A
j
) where we get

c
j
d
2
nr
(x; c
j
, A
j
) = 2
_
((x c
j
)
T
A
j
(x c
j
))
1/2
1
_

c
j
[(x c
j
)A
j
(x c
j
)]
1/2
= d
nr
(x; c
j
, A
j
) [(x c
j
)A
j
(x c
j
)]
1/2

c
j
(x c
j
)
T
A
j
(x c
j
)
=
d
nr
(x; c
j
, A
j
)
[(x c
j
)A
j
(x c
j
)]
1/2
(2A
j
(c
j
x))
= 2
d
nr
(x; c
j
, A
j
)
(x; c
j
, A
j
)
A(x c
j
) . (250)
Using the denition of
2
(x; c
j
, A
j
). Next we let a
rs
be the (r, s) element of A
j
. Then

ars
d
2
nr
(x; c
j
, A
j
) is given by

a
rs
d
2
nr
(x; c
j
, A
j
) = 2d
nr
(x; c
j
, A
j
)
_
1
2
_
1
(x; c
j
, A
j
)

a
rs
(x c
j
)A
j
(x c
j
)
=
d
nr
(x; c
j
, A
j
)
(x; c
j
, A
j
)
(x
r
c
jr
)(x
s
c
js
) .
When we write this in matrix form we get

A
j
d
2
nr
(x; c
j
, A
j
) =
d
nr
(x, c
j
, A
j
)
(x; c
j
, A
j
)
(x c
j
)(x c
j
)
T
. (251)
We then put Equation 250 and 251 into the parameter update step in the Generalized
Fuzzy Algorithmic Scheme (GFAS) which for reminder is the expression
N

i=1
u
q
ij
(t 1)

j
d(x
i
;
j
) = 0 ,
we get the parameter update step for this algorithm quoted in the book.
Notes on the fuzzy C-ellipsoid shells (FCES) clustering algorithms
Using the denition of
2
= (x c)
T
A(x c) with Equations 267 and 268 developed below
we have that
d
2
r
(x; c, A) = (1 a)
2
[[x c[[
2
=
_
1
1

_
2
[[x c[[
2
.
Using this expression we will take the derivatives needed for the parameter updating algo-
rithm. We nd

c
d
2
r
(x; c, A) = 2
_
1
1

__
1

2
_

c
[[x c[[
2
+
_
1
1

_
2
(2(x c))
=
2

2
_
1
1

c
[[x c[[
2
2
_
1
1

_
2
(x c) .
176
Now from the denition of we have that

c
=
1
2
1

(2A(c x)) =
1

A(x c) .
Using this we get for the derivative

c
d
2
r
(x; c, A)

c
d
2
r
(x; c, A) =
2

3
_
1
1

_
[[x c[[
2
A(x c) 2
_
1
1

_
(x c)
=
2

4
(1 ) [[x c[[
2
A(x c) 2
_
1
1

_
(x c) .
Thus one of the parameter updating equations
N

i=1
u
q
ij
(t 1)

c
d
2
r
(x; c, A) = 0 ,
when we divide by 2 and put back in the index j specifying the cluster becomes
N

i=1
u
q
ij
(t 1)
_
[[x c[[
2
(1 )

4
A
j

_
1
1

_
2
I
_
(x c
j
) = 0 , (252)
the same equation as in the book. Next we need to evaluate

A
d
2
r
(x; c, A) where we nd

A
d
2
r
(x; c, A) = 2
_
1
1

__
1

2
_

A
[[x c[[
2
.
Since

A
=
1
2
(
2
)
1/2

A
((x c)
T
A(x c)) =
1
2
1

(x c)(x c)
T
,
we have that

A
d
2
r
(x; c, A) =
_
1
1

__
1

3
_
[[x c[[
2
(x c)
T
(x c)
T
.
Thus the second parameter updating equations
N

i=1
u
q
ij
(t 1)

A
d
2
r
(x; c, A) = 0 ,
with the index j specifying the cluster becomes
N

i=1
u
q
ij
(t 1)
_
1

4
_
[[x c[[
2
(x c)(x c)
T
= 0 , (253)
the same equation as in the book.
177
Notes on the fuzzy C-quadric shells (FCQS) algorithm
For this clustering our distance function for a point x and a cluster Q is given by the algebraic
distance
d
2
a
(x; Q) = (x
T
Ax + b
T
x + c)
2
= p
T
M(x)p ,
where we have written M as a function of x since it depends on the point x where we want
to evaluate this distance. Here p is a parameter vector that determines the shape of the
quadric that we are considering. We want to impose the constraint on the vector p
j
of the
form

k=1
p
2
jk
+
1
2
r

k=l+1
p
2
jk

2
= 1 . (254)
Since the quadratic we seek to describe is given by the equation q(x)
T
p = 0 we can modify
the denitions of q and p by introducing

2 so that the inner product remains unchanged


and so that we can explicitly introduce the constraint Equation 254. To this end we introduce
the vector a, b, r, and t such that
p =
_
a
T
b
T

T
and q =
_
r
T
t
T

T
,
then q
T
p = q
T
p = r
T
a + t
T
b and p
T
j
M
i
p
j
= p
j

M
i
p
j
. The cost function (without any
constraint) for the FCQS algorithm can then be written as
J =
N

i=1
m

j=1
u
q
ij
p
j

M(x
i
) p
j
=
N

i=1
m

j=1
u
q
ij
_
a
T
j
b
T
j

_
r
i
r
T
i
r
i
t
T
i
t
i
r
T
i
t
i
t
T
i
_ _
a
j
b
j
_
. (255)
To enforce the constraint from Equation 254 we need to modify J to include this constraint
by adding

j=1

j
([[a
j
[[
2
1) ,
to get
a
(, J). Expanding the block inner product in Equation 255 we get
N

i=1
m

j=1
u
q
ij
_
a
T
j
r
i
r
T
i
a
j
+ b
T
j
t
i
t
T
i
b
j
+ 2a
T
j
r
i
t
T
i
b
j

.
Consider now

b
j

a
. When we recall that for symmetric A

x
(y
T
Ax) = A
T
y and

x
(x
T
Ax) = 2Ax,
we then nd

b
j

a
given by

b
j

a
=
N

i=1
u
q
ij
(2T
i
b
j
+ 2S
i
a
j
) .
178
Let
H
j

N

i=1
u
q
ij
T
i
and G
j

N

i=1
u
q
ij
S
i
,
and setting

b
j

a
equal to zero we get for b
j
b
j
= H
1
j
G
j
a
j
. (256)
Now we need to evaluate

a
j

a
. When we recall that

x
(x
T
Ay) = Ay ,
we get for this derivative

a
j

a
=
N

i=1
u
q
ij
_
2R
i
a
j
+ 2r
i
t
T
i
b
j

j
(2a
j
) =
N

i=1
u
q
ij
_
2R
i
a
j
+ 2S
T
i
b
j

2
j
a
j
.
Let
F
j

N

i=1
u
q
ij
R
i
,
and set

a
j

a
equal to zero we get F
j
a
j

j
a
j
= G
T
j
b
j
. Since we know b
j
using Equation 256
we get F
j
a
j

j
a
j
= G
T
j
H
1
j
G
j
a
j
or
(F
j
G
T
j
H
1
j
G
j
)a
j
=
j
a
j
. (257)
Thus
j
is an eigenvalue of the matrix F
j
G
T
j
H
1
j
G
j
and a
j
is the corresponding eigenvector
with length 1 due to the constraint Equation 254. We now specify how to pick
j
from all
of the eigenvalues of F
j
G
T
j
H
1
j
G
j
. Since we know that b
j
= H
1
j
G
j
a
j
when we are at
the optimum solution the value of
a
will be given by the value of J at this optimal solution
where J is given by Equation 255. This is because the constraints must all be satised
(and therefore vanish) at the optimum solution and wont contribute to the value of the cost
function. The argument of the summation in Equation 255 using the value for b
j
calculated
above is given by
a
T
j
R
i
a
j
+ b
T
j
T
j
b
j
+ 2a
T
j
S
T
i
b
j
= a
T
j
R
j
a
j
+ a
T
j
G
T
j
H
T
j
T
i
H
1
j
G
j
a
j
2a
T
j
S
T
i
H
1
j
G
j
a
j
.
When we multiply this by u
q
ij
and sum over i we get
a
T
j
__
N

i=1
u
q
ij
R
i
_
+ G
T
j
H
T
j
_
N

i=1
u
q
ij
T
i
_
H
1
j
G
j
2
_
N

i=1
u
q
ij
S
T
i
_
H
1
j
G
j
_
a
j
,
or recalling our previous denitions of F
j
, G
j
, and H
j
we have
a
T
j
_
F
j
+ G
T
j
H
T
j
H
j
H
1
j
G
j
2G
T
j
H
1
j
G
j
_
a
j
.
Since H
j
is a symmetric matrix this becomes
a
T
j
(F
j
G
T
j
H
1
j
G
j
)a
j
.
179
If a
j
is an eigenvector (with unit norm) of the matrix F
j
G
j
H
1
j
G
j
then this inner product
is given by

j
a
T
j
a
j
=
j
.
Thus to make the sum of these terms over j as small as possible (to minimize J) we pick

j
as small as possible. This motivates picking the smallest values for the eigenvalues of
F
j
G
j
H
1
j
G
j
in this algorithm.
Notes on hyperplane representatives (the Gustafson-Kessel algorithm)
In this formulation the distance we use is given by
d
2
GK
(x;
j
) = [
j
[
1/l
(x c
j
)
T

1
j
(x c
j
) , (258)
and our objective function is given by
J
GK
(; U) =
N

i=1
m

j=1
u
q
ij
d
2
GK
(x
i
;
j
) .
To nd the minimum of this expression we take derivatives with respect to c
j
and
j
, set
the results equal to zero and solve for these expressions. Taking the derivative of J
GK
(; U)
with respect to c
j
we have

c
j
J
GK
(; U) =
N

i=1
u
q
ij

c
j
d
2
GK
(x
i
; c
j
,
j
) .
Note in the above expression that since we are explicitly specifying the jth cluster in this
derivative (and in the subsequent
j
derivative) the derivative of the other terms with
dierent indices are zero. Thus we can drop the j index on c and and only consider how
to evaluate

c
d
2
GK
(x; c, ). This procedure makes the notation cleaner. Thus

c
d
2
GK
(x; c, ) = [[
1/l
(2
1
(c x)) = 2[[
1/l

1
(x c) . (259)
When we put this last expression into the previous one, equate the result to zero and cancel
common terms, we get
N

i=1
u
q
ij
(x
i
c) = 0 ,
or solving for c we nd
c =

N
i=1
u
q
ij
x
i

N
i=1
u
q
ij
. (260)
This depends on j via the right-hand-side. We now need to evaluate the optimal value for
via taking the derivative of J
GK
with respect to . Rather than evaluate

d
2
GK
(x; c, )
directly we will evaluate

1
d
2
GK
(x; c, ) or the derivative of d
2
GK
with respect to
1
. To
do this we rst write d
2
GK
(x; c, ) as
d
2
GK
(x; c, ) = [
1
[
1/l
(x c)
T

1
(x c) .
180
Let f
rs
be the (r, s) element of
1
. Then

f
rs
d
2
GK
(x; c, ) =
1
l
[
1
[

1
l
1
[
1
[
f
rs
(x c)
T

1
(x c) +[
1
[
1/l
(x
r
c
r
)(x
s
c
s
) .
As we discussed on Page 168 and expressed via Equation 230 we have
[
1
[
f
rs
=
rs
,
where
rs
is the (r, s) cofactor of the matrix
1
. When we put this into the above and then
consider the matrix form of the above expression we get

1
d
2
GK
(x; c, ) =
1
l
[
1
[

1
l
1
C(x c)
T

1
(x c) +[
1
[
1/l
(x c)(x c)
T
,
where C is the matrix of cofactors of
1
i.e. the (r, s) element of C is
rs
. Then again from
earlier we know that the cofactor matrix C and the inverse of
1
are related as
(
1
)
1
=
C
T
[
1
[
or C
T
= [
1
[.
Since is symmetric so is C (just take the transpose of the previous equation) and we have

1
d
2
GK
(x; c, ) = [
1
[
1/l
_

1
l
(x c)
T

1
(x c) + (x c)(x c)
T
_
.
Setting

1
J
2
GK
(; U) equal to zero using this result we get
1
l
N

i=1
u
q
ij
(x
i
c)
T

1
(x
i
c) =
N

i=1
u
q
ij
(x
i
c)(x
i
c)
T
. (261)
The book then presents
=

N
i=1
u
q
ij
(x
i
c)(x
i
c)
T

N
i=1
u
q
ij
, (262)
as the solution to Equation 261.
Warning: Note I was not able to derive the given expression for . If anyone knows how
to get this expression please email me.
Notes on possibilistic clustering
For the cost function in the possibilistic framework of
J(; U) =
N

i=1
m

j=1
u
q
ij
d(x
i
;
j
) +
m

j=1

j
N

i=1
(1 u
ij
)
q
, (263)
181
setting the u
ij
derivative equal to zero gives

u
ij
J(; U) = qu
q1
ij
d(x
i
;
j
) q
j
(1 u
ij
)
q1
= 0 .
Dividing this by u
q1
ij
and by q we get
d(x
i
;
j
)
j
_
1
u
ij
1
_
q1
= 0 . (264)
Solving for u
ij
gives
u
ij
=
1
1 +
_
d(x
i
;
j
)

j
_ 1
q1
. (265)
When we solve Equation 264 for d(x
i
;
j
) we get
d(x
i
;
j
) =
j
_
1 u
ij
u
ij
_
q1
.
When we put this into
J
j
=
N

i=1
u
q
ij
d(x
i
;
j
) +
j
N

i=1
(1 u
ij
)
q
,
we get
J
j
=
j
N

i=1
u
ij
(1 u
ij
)
q1
+
j
N

i=1
(1 u
ij
)
q
=
j
N

i=1
[u
ij
+ (1 u
ij
)](1 u
ij
)
q1
=
j
N

i=1
(1 u
ij
)
q1
. (266)
Problem Solutions
Problem 14.1 (a known covariance matrix in the GMDAS)
If the covariance matrix is known then we dont need to take the derivative with respect to

i
in the M-step of the expectation maximization (EM) algorithm. Thus the
i
update step
drops away and there is only the
i
update step.
Problem 14.2 (GMDAS when the covariance matrices are diagonal)
If the covariance matrix is diagonal then
[
j
[ =
l

k=1

2
jk
,
182
so
ln(p(x
i
[C
j
;
j
)) =
l
2
ln(2)
l

k=1
ln(
jk
)
1
2
l

k=1
(x
ik

jk
)
2

2
jk
.
The M-step for estimating
j
(where
j
is a vector representing the mean
j
and the elements
of the covariance matrix) is given by (see the notes on Page 168 around the Equation 229).
N

i=1
P(C
j
[x
i
; (t))

j
ln(p(x
i
[C
j
;
j
) = 0 .
The evaluation of

j
does not change for the elements of the mean vector
j
from before
and we need to evaluate

j
for the elements of the covariance matrix. Consider just one
term

jk
where we get

jk
ln(p(x
i
[C
j
;
j
) =
1

jk
+
(x
ik

jk
)
2

3
jk
.
Thus in Equation 229 we get
N

i=1
P(C
j
[x
i
; (t))
_

jk
+
(x
ik

jk
)
2

3
jk
_
= 0 for 1 k l .
If we solve for
2
jk
in the above expression we get

2
jk
=

N
i=1
P(C
j
[x
i
; (t))(x
ik

jk
)
2

N
i=1
P(C
j
[x
i
; (t))
for 1 k l .
Note that this gives the same result for the diagonal elements as does Equation 232 which
computes the full covariance matrix.
Problem 14.4 (running GMDAS on a given data set)
For this problem I considered the second set of points x
i
for i = 9, 10, , 16 to be generated
by
x
i
= x
16i+1
+ 6 for i = 9, 10, , 16 .
Thus x
9
= x
8
+ 6, x
10
= x
7
+ 6, etc. This problem is implemented in the MATLAB script
chap 14 prob 4.m. For this problem we use MATLAB code from the NETLAB toolbox for
pattern recognition [1]. The EM algorithm nds

1
=
_
6.0069
0.0053
_

2
=
_
0.0225
0.0052
_
,
for the means and for
i
it nds

1
=
_
2.0047 1.4131
1.4131 2.0016
_

2
=
_
2.0886 0.0232
0.0232 1.9984
_
.
If one looks at a scatter plot of the initial points one sees that the returned EM results look
like they t the generated data shown in Figure 27 (left).
183
2 1 0 1 2 3 4 5 6 7 8
2
1.5
1
0.5
0
0.5
1
1.5
2
2 1 0 1 2 3 4
2
1.5
1
0.5
0
0.5
1
1.5
2
Figure 27: Left: Sample data for Problem 4. Right: Sample data for Problem 5. Green
points correspond to the rst eight samples while red points correspond to the remaining
eight points.
Problem 14.5 (running GMDAS on another data set)
This problem is implemented in the MATLAB script chap 14 prob 5.m. For this problem
we again use MATLAB code from the NETLAB toolbox for pattern recognition [1]. The EM
algorithm nds

1
=
_
0.4761
0.0
_

2
=
_
3.6173
0
_
.
and for
i

1
=
_
1.9393 0
0 2.1388
_

2
=
_
0.0777 0
0 1.3067
_
.
The data for this problem is shown in Figure 27 (right). In this case the value found dont
exactly correspond to the centers of the generated data. This error is compounded the
closer the clusters are to each other (and how much over lap they have).
Problem 14.7 (the objective function J after clustering)
See the notes on Page 169 for this exercise.
Problem 14.8 (an equivalent relationship to x
T
Ax + b
T
x + c = 0)
When we write out in components the relationship given by Equation 244 we have
l

i=1
l

j=1
a
ij
x
i
x
j
+
l

i=1
b
i
x
l
+ c = 0 .
184
or factoring out the x
2
i
terms
l

i=1
a
ii
x
2
i
+
l

i,j;i=j
a
ij
x
i
x
j
+
l

i=1
b
i
x
l
+ c = 0 .
If we expand the second sum by taking i = 1 with j = 2, 3, . . . l, then taking i = 2 with
j = 1, 3, , l, then take i = 3 and j = 1, 2, 4, , l etc we can group the sum of the terms
a
ij
x
i
x
j
where i ,= j (i.e. the second sum above) as
l

i=1
l

j=l+1
(a
ij
+ a
ji
)x
i
x
j
.
This gives the representation for the vector p as
p =
_
a
11
a
22
a
33
a
ll
a
12
+ a
21
a
13
+ a
31
a
l1,l
+ a
l,l1
b
1
b
2
b
l
c

.
Problem 14.9 (nding d
2
p
(x, Q) via polynomial roots)
When l = 2 then A is 2 2 symmetric matrix A =
_
a
11
a
12
a
12
a
22
_
, b is a 2 1 vector, x is a
2 1 vector and then
1
2
(I + A)
1
=
_
1
(1 + a
11
)(1 + a
22
)
2
a
2
12
__
1 + a
22
a
12

a
12
1 + a
11

_
.
Thus the expression used for z given by Equation 248 is given by
z =
1
2
(I + A)
1
(2x b)
=
_
1
2((1 + a
11
)(1 + a
22
)
2
a
2
12
)
__
(1 + a
22
)(2x
1
b
1
) a
12
(2x
2
b
2
)
a
12
(2x
1
b
1
) + (1 + a
11
)(2x
2
b
2
)
_
.
When we put this into Equation 244 or z
T
Az +b
T
z +c = 0 and multiply by the denominator
(1 + a
11
)(1 + a
22
)
2
a
2
12
,
squared (because of the quadratic term z
T
Az) we will obtain a fourth order polynomial in
.
Problem 14.10 (a relationship between d
2
nr
(x, Q) and d
2
r
(x, Q))
Since d
2
r
(x, Q) = [[xz[[
2
with z on a line from x to c on the hyperellipsoid i.e. zc = a(xc)
and (z c)
T
A(z c) = 1. When we put this rst equation into the second equation we see
that
a
2
(x c)
T
A(x c) = 1 or a
2
=
1
(x c)
T
A(x c)
. (267)
185
Then since z c = a(x c) we have
[[z c[[
2
= a
2
[[x c[[
2
or [[x c[[
2
=
1
a
2
[[z c[[
2
,
with a
2
given by Equation 267. Now consider
d
2
r
(x, Q) = [[x z[[
2
= [[x c a(x c)[[
2
= (1 a)
2
[[x c[[
2
(268)
=
_
1
a
1
_
2
[[z c[[
2
= (((x c)
T
A(x c))
1/2
1)[[z c[[
2
, (269)
as we were to show.
Problem 14.11 (deriving the fuzzy C-ellipsoidal shells algorithm)
See the notes on this algorithm on Page 176.
Problem 14.12 (deriving the fuzzy C-quadric shells algorithm)
See the notes on this algorithm on Page 178.
Problem 14.13 (the modied fuzzy C quadratic shells algorithm)
In this scheme the goal is to use the generalized fuzzy algorithmic scheme (GFAS) with
the perpendicular distance, d
p
(x, ), for the degree of membership. Rather than use this
distance measure everywhere in the GFAS, in the parameter updating step we replace it
with a distance measure that is easier to calculate. Recall that the perpendicular distance is
computationally dicult to compute since it relies on nding roots of polynomial equations.
Due to the iterative nature of many root nding algorithms that would be used in the
parameter updating step we would need to compute d
p
(x,

) for many values of

. To avoid
this computational diculty in the parameter updating step we will use the algebraic cluster-
point distance instead. This distance is given by
d
2
a
(x, Q) = (x
T
Ax + b
T
x + c)
2
= p
T
Mp .
Problem 14.14 (relationships between the radian and perpendicular distance)
In general the perpendicular distance will be the smaller distance. That is d
p
(x; Q) d
r
(x; Q)
will hold.
186
Problem 14.15 (spherical clusters)
The AFCS algorithm was derived on Page 175. Here we modify the arguments there to
account for the new distance measure for the jth cluster is d
2
s
(x;
j
) = ([[xc
j
[[ r
j
)
2
. Thus
the parameters
j
are given by the vector c
j
and the scalar r
j
. We start with out criterion
function to minimize
J(; U) =
N

i=1
m

j=1
u
q
ij
d
2
s
(x
i
;
j
) .
Then to minimize this expression we take the derivatives with respect to c
j
and r
j
, set the
results equal to zero and then solve (numerically or analytically) for c
j
and r
j
. We nd the
c derivative of d
2
s
given by

c
d
2
s
(x; ) = 2([[x c[[ r)

c
[[x c[[
= 2([[x c[[ r)

c
((x c)
T
(x c))
1/2
= 2([[x c[[ r)
1
2
((x c)
T
(x c))
1/2

c
(x c)
T
(x c)
=
([[x c[[ r)
[[x c[[
(2(x c)) = 2
([[x c[[ r)
[[x c[[
(x c) .
We nd the r derivative of d
2
s
given by

c
d
2
s
(x; ) = 2([[x c[[ r)(1) = 2([[x c[[ r) .
Then setting
J
r
j
equal to zero we have to solve
N

i=1
u
q
ij
([[x
i
c
j
[[ r
j
) = 0 ,
for r
j
. This gives
r
j
=

N
i=1
u
q
ij
[[x
i
c
j
[[

N
i=1
u
q
ij
.
Setting
J
c
j
equal to zero we need to solve
N

i=1
u
q
ij
_
([[x
i
c
j
[[ r
j
)
[[x
i
c
j
[[
_
(x
i
c
j
) = 0 ,
for c
j
and r
j
given the equation on r
j
above. Once we have solved these equations for c
j
and r
j
we can update the value of u
ij
(t) as in the Generalized Fuzzy Algorithmic Scheme
(GFAS).
187
Problem 14.16 (the possibilistic algorithm)
If J
1
(, U) given by
J
1
(, U) =
N

i=1
m

j=1
u
ij
d(x
i
,
j
) +
m

j=1

j
N

i=1
(u
ij
ln(u
ij
) u
ij
) .
Then taking the u
ij
derivative of J
1
and setting it equal to zero gives
J
1
u
ij
= d(x
i
,
j
) +
j
[ln(u
ij
) + 1 1] = 0 .
When we solve for u
ij
we get
u
ij
= exp
_

d(x
i
,
j
)

j
_
. (270)
This is the update step of u
ij
for xed parameters
j
then we update the parameters
j
via
a parameter updating step by taking the

j
of J
1
(, J), setting the result equal to zero and
solving for
j
i.e. solving
N

i=1
u
ij
(t 1)

j
d(x
i
;
j
) = 0 ,
this last set depends the type of clustering desired.
Problem 14.17 (plots of u
ij
vs. d(x
i
,
j
)/
j
See the MATLAB script chap 14 prob 17_ m where these expressions for u
ij
are plotted. When
that script is run we get the plot shown in Figure 28.
188
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
d(x,theta)/eta
u
i
j
Figure 28: The plots of u
ij
given by Equation 265 for various value of q (in blue) and by
Equation 270 (in red).
189
Clustering Algorithms IV
Notes on the text
Notes on Competitive Learning-Like Algorithms
We are to consider the objective function J(W) dened by
J(W) =
1
2m
N

i=1
m

j=1
z
j
(x
i
)[[x
i
w
j
[[
2
(271)
=
1
2m
N

i=1
m

j=1
_
[[x
i
w
j
[[
2

m
r=1
[[x
i
w
r
[[
2
_
[[x
i
w
j
[[
2
=
1
2m
N

i=1
_
1

m
r=1
[[x
i
w
r
[[
2
_
=
1
2
N

i=1
_
m

r=1
[[x
i
w
r
[[
2
_
1
. (272)
Now to take the derivative of the above expression with respect to the vector w
k
we get
J
w
k
=
1
2
N

i=1
1
_
m

r=1
[[x
i
w
r
[[
2
_
2


w
k
_
[[x
i
w
k
[[
2
_
=
1
2
N

i=1
(z
2
k
(x
i
)[[x
i
w
k
[[
4
)

w
k
([[x
i
w
k
[[
2
)
=
1
2
N

i=1
(z
2
k
(x
i
)[[x
i
w
k
[[
4
)(2)[[x
i
w
k
[[
3

w
k
([[x
i
w
k
[[)
=
N

i=1
z
k
(x
i
)
2
[[x
i
w
k
[[

w
k
[[x
i
w
k
[[ .
To continue, we recall that the vector derivative of the vector norm is given by

w
k
[[x
i
w
k
[[ =
(x
i
w
r
)
[[x
i
w
k
[[
,
which we can be shown by taking the derivative of [[x
i
w
k
[[ with respect to each component
one at a time. Thus we get
J
w
k
=
N

i=1
z
2
k
(x
i
)(x
i
w
k
) , (273)
which is the result given in the book.
190
Notes on the branch and bound clustering algorithms
We are given (
r
= [c
1
, c
2
, . . . , c
r
] or an assignment of the rst r points from the data set X
into the m clusters c
i
1, 2, . . . , m. Note that in this section there are two objects that
are denoted via the c character. The rst, c
i
, represents is the cluster that the point x
i
is assigned to. The second, (
r
, is all assignments to clusters for the rst r points from X.
With these denitions this we can dene an objective function for this cluster assignment as
follows
J((
r
) =
r

i=1
[[x
i
m
c
i
((
r
)[[
2
. (274)
Here m
j
((
r
) is dened as
m
j
((
r
) =
1
n
j
((
r
)

q=1,...,r:Cq=j
x
q
. (275)
This is a more complicated way of writing the fact that m
j
((
r
) is the mean of all vectors
assigned to the jth cluster. Based on the above and assuming that we assign the point x
r+1
to cluster j we can write
J((
r+1
) =
r+1

i=1
[[x
i
m
c
i
((
r+1
)[[
2
=
r

i=1
[[x
i
m
c
i
((
r+1
)[[
2
+[[x
r+1
m
j
((
r+1
)[[
2
=
r

i=1:c
i
=j
[[x
i
m
c
i
((
r+1
)[[
2
+
r

i=1:c
i
=j
[[x
i
m
c
i
((
r+1
)[[
2
+[[x
r+1
m
j
((
r+1
)[[
2
.
In the last step we have broken the original sum up into two additional sums. The rst is
the sum over all the points x
i
that are not assigned to the cluster j and the second is the
sum over all the points x
i
that are assigned to cluster j. Now with these two new sum, in
the rst sum since we are ignoring the cluster j it can be written as
r

i=1:c
i
=j
[[x
i
m
c
i
((
r
)[[
2
,
where we now have m
c
j
((
r
) rather than m
c
j
((
r+1
) since the means over (
r
and (
r+1
are the
same for all clusters that are not equal to j. With this we now have
J((
r+1
) =
r

i=1:c
i
=j
[[x
i
m
c
i
((
r
)[[
2
+
r

i=1:c
i
=j
[[x
i
m
j
((
r+1
)[[
2
+[[x
r+1
m
j
((
r+1
)[[
2
. (276)
191
Now lets consider the mean vector of the j cluster or m
j
((
r+1
) which shows up in two places
above. Since the new point x
r+1
is placed in that cluster we have
m
c
j
((
r+1
) =
1
n
j
(C
r
) + 1
_
_

q=1, ,r:cq=j
x
q
+ x
r+1
_
_
=
n
j
((
r
)
n
j
((
r
) + 1
m
j
((
r
) +
1
n
j
((
r
) + 1
x
r+1
(277)
= m
j
((
r
)
1
n
j
((
r
) + 1
(x
r+1
m
j
((
r
)) . (278)
Then with this we nd x
i
m
j
((
r+1
) can be written as
x
i
m
j
((
r+1
) = x
i
m
j
((
r
) +
1
n
j
((
r
) + 1
(x
r+1
m
j
((
r
)) .
Thus the norm needed in the second sum in Equation 276 is
[[x
i
m
j
((
r
)[[
2
= [[x
i
m
j
((
r
)[[
2
+
2
n
j
((
r
) + 1
(x
i
m
j
((
r
))(x
r+1
m
j
((
r
))
+
1
(n
j
((
r
) + 1)
2
[[x
r+1
m
j
((
r
)[[
2
.
Now when we sum this expression over

r
i=1:c
i
=j
the middle term vanishes due to the fact
that

r
i=1:c
i
=j
(x
i
m
j
((
r
)) = 0. Thus we nd for the second sum in Equation 276 the terms
r

i=1:c
i
=j
[[x
i
m
j
((
r
)[[
2
+
n
j
((
r
)
n
j
((
r
) + 1)
2
[[x
r+1
m
j
((
r
)[[
2
.
Now for the lone term [[x
r+1
m
j
((
r+1
)[[
2
in Equation 276 we nd
x
r+1
m
j
((
r+1
) =
_
1
1
n
j
((
r
) + 1
_
x
r+1

n
j
((
r
)
n
j
((
r
) + 1
m
j
((
r
) =
n
j
((
r
)
n
j
((
r
) + 1
(x
r+1
m
j
((
r
)) .
Thus
[[x
r+1
m
j
((
j+1
)[[
2
=
n
j
((
r
)
2
(n
j
((
r
) + 1)
2
[[x
r+1
m
j
((
r
)[[
2
.
Thus combining these we nd
J((
r+1
) = J((
r
) +
n
j
((
r
)
n
j
((
r
) + 1)
2
[[x
r+1
m
j
((
r
)[[
2
+
n
j
((
r
)
2
(n
j
((
r
) + 1)
2
[[x
r+1
m
j
((
r
)[[
2
= J((
r
) +
n
j
((
r
)
n
j
((
r
) + 1
[[x
r+1
m
j
((
r
)[[
2
.
This last expression veries the books expression for J((
r
).
192
Notes on the boundary detection algorithm
Recall that the form of J() given in this section is
J() =
1
N
N

i=1
f
2
(g(x
i
; ))
_
1
N
N

i=1
f(g(x
i
; ))
_
2q
. (279)
Then if we consider the positive expression given in the book (denoted as E)
E =
1
N
N

i=1
_
f(g(x
i
; ))
1
N
N

k=1
f(g(x
k
; ))
_
2
,
by expanding we have
E =
1
N
N

i=1
_
_
f
2
g(x
i
; ))
2
N
f(g(x
i
; ))
N

k=1
f(g(x
i
; )) +
_
1
N
N

k=1
f(g(x
i
; ))
_
2
_
_
=
1
N
N

i=1
f
2
g(x
i
; ))
2
N
2
_
N

k=1
f(g(x
i
; ))
_
2
+
1
N
2
_
N

k=1
f(g(x
i
; ))
_
2
=
1
N
N

i=1
f
2
g(x
i
; ))
1
N
2
_
N

k=1
f(g(x
i
; ))
_
2
. (280)
As q is a positive integer and the sum
1
N

N
i=1
f(g(x
i
; )) is inside [1, +1] we have that
_
1
N
N

i=1
f(g(x
i
; ))
_
2q

_
1
N
N

i=1
f(g(x
i
; ))
_
2
When we negate this expression and add
1
N

N
i=1
f
2
(g(x
i
; )) to both sides we get using
Equation 280 that
1
N
N

i=1
f
2
(g(x
i
; ))
_
1
N
N

i=1
f(g(x
i
; ))
_
2q

1
N
N

i=1
f
2
(g(x
i
; ))
_
1
N
N

i=1
f(g(x
i
; ))
_
2
,
or
J() E ,
the expression stated in the book.
Problem Solutions
Problem 15.3 (leaky learning with
w
=
l
)
In this case every cluster representative w
j
gets updated via
w
j
(t) = w
j
(t 1) + (x w
j
(t 1)) .
193
Since each cluster representative w
j
is initialized randomly (perhaps with a random sample
from X) each of these cluster centers is a particular step in a Robbins-Monro iterations for
solving for w in E
X
[h(X, w)] = 0 where h(X, w) = X w. For this h(X, w) the limiting
value of w
j
(t) (for all j) should be the mean of all the samples in X.
Problem 15.4 (the von Malsburg learning rule)
Part (b): If w
j
looses the competition for x then it does not change its value so if

k
w
jk
= 1
before the assignment of a sample it will still hold afterwards. If w
j
wins the competition
for x then

k
w
new
jk
=

k
w
jk
+
_

k
x
k
n
k

k
w
jk
_
.
But

k
x
k
n
k
= 1 and

k
w
jk
= 1 so

k
w
new
jk
= 1.
Problem 15.5 (deriving the expression for J((
r
)
See the notes on Page 191 where this problem is worked.
Problem 15.9 (a derivative)
The given expression can have the same value for g(x; ) but with dierent values for w
i
.
This is due to the symmetry in the products x
s
x
r
. Thus it should be written as
g(x; ) = w
0
+
l

i=1
w
i
x
i
+
l

s=1

r>s
w
sr
x
s
x
r
.
Where we have
1
2
l(l + 1) terms in the second sum. Derivatives of this expression can then
be computed with respect to the components of w
0
, w
i
and w
sr
.
Problem 15.13 (time till convergence)
If we take T
max
= 5 and T
min
= 0.5 then using the equation suggested in the book we have
ln(1 + t
end
) =
T
max
T
min
=
5
0.5
= 10 .
Thus solve we nd t
end
= 22025.46. A large number of iterations.
194
Cluster Validity
Notes on the text
Notes on comparing T and (
These are some simple notes on bootstrapping statistics when imposing an external clustering
criterion. In this section we assume that we have some external clustering (represented by
T) and we desire to see if the computed clustering (represented by () duplicates/describes
the same phenomena as T. Note that to compute the Rand statistics, Jaccard coecient, or
the Fowlkes & Mallows index we need two clusterings (

and T

. For the hypothesis testing


for cluster structure discussed in this section we need to generate these two clusterings and
then construct many samples of the measure (Rand statistic, Jaccard coecient, etc). Thus
we need (

from our algorithm and T from our external criterion. We thus need to generate
bootstrap data samples of both (

and T

. From these samples we can compute a distribution


over the given measure. We can then test whether any given sample of the measure comes
from this distribution or is an outlier.
Problem Solutions
Problem 16.1 (Rand, Jaccard, Fowlkes & Mallows)
Recall that the Rand statistic is given by
R =
a + d
a + d + b + c
. (281)
As all of the variables a, b, c, d are nonnegative the rand statistic will be less than one if
b + c > 0. The smallest value that b + c can be is 0. In order for b + c = 0 we must have
both b = 0 and c = 0. Since b is the number points of the samedierent (SD) category
and c is the number points in the dierentsame (DS) category both b and c cannot as
long as the number of m clusters in ( and the number q partitions in T are not the same,
there must be points in at least one of these two groups. In other words not both b and c
can be zero. Thus b +c > 0 and the rand coecient is less than one. Because the forms for
the Jaccard coecient
J =
a
a + b + c
, (282)
and the Fowlkes & Mallows index
FM =
_
a
a + b
a
a + c
, (283)
have fractions that are less than one if either b or c is nonzero we have that both these
expressions are less than one.
195
Problem 16.2 (an expression for

)
Recall that X(i, j) = 1 if x
i
and x
j
are in the same cluster in (, and Y (i, j) = 1 if x
i
and x
j
are in the same group in T and are zero otherwise. Now note that the denitions of
X
and

Y
can be simplied as

X

1
M
N1

i=1
N

j=i+1
X(i, j) =
1
M
m
1
and

Y

1
M
N1

i=1
N

j=i+1
Y (i, j) =
1
M
m
2
.
Using these the expressions for
2
X
and
2
Y
can be simplied as

2
X

1
M
N1

i=1
N

j=i+1
X(i, j)
2

2
X
=
1
M
m
1

1
M
2
m
2
1
and

2
Y
=
1
M
m
2

1
M
2
m
2
2
.
Now note that we can write the double sum in the expression for

(denoted by E for
expression) as
E =
1
M
N1

i=1
N

j=i+1
(X(i, j)
X
)(Y (i, j)
Y
)
=
1
M
N1

i=1
N

j=i+1
X(i, j)Y (i, j)

X
M
N1

i=1
N

j=i+1
Y (i, j)


Y
M
N1

i=1
N

j=i+1
X(i, j) +

X

Y
M
N1

i=1
N

j=i+1
1
=
X

Y

X

Y
+
X

Y
=
X

Y
.
Where we have use the denition of Huberts statistic

1
M
N1

i=1
N

j=i+1
X(i, j)Y (i, j) . (284)
Note that since

N1
i=1

N
j=i+1
X(i, j)Y (i, j) = a we can write =
a
M
. Thus when we use
these expressions to evaluate

we nd

Y
=
a
M

1
M
2
m
1
m
2
_
_
1
M
m
1

1
M
2
m
2
1
_ _
1
M
m
2

1
M
2
m
2
2
_
=
(Ma m
1
m
2
)
_
(Mm
1
m
2
1
)(Mm
2
m
2
2
)
=
(Ma m
1
m
2
)
_
m
1
m
2
(M m
1
)(M m
2
)
, (285)
the desired expression.
196
Problem 16.4 (the CPCC is bounded between [1, +1])
Note that the expression for CPCC is a correlation between two vectors. One vector has
values from the elements of the upper diagonal cophenetic matrix P
c
and the other has
elements from the upper diagonal of the proximity matrix P. As correlations are always
bounded [[ 1 so must this measure.
Problem 16.6 (The modied Hubert statistics)
Recall that to dene the modied Hubert statistic, we start from the samples x
i
directly by
rst computing the proximity matrix T. From the hard clustering centers w
i
for i = 1, . . . , m,
we dene the cluster index c
i
to be c
i
= k if the sample x
i
is a member of the kth cluster (
k
.
Then for each of the N x
i
data points we dene the matrix Q(i, j) to have elements equal
to d(w
c
i
, w
c
j
) where w
i
is the hard cluster representative/center.
Note that if we already have a algorithm or subroutine that takes as input data samples
x
i
and computes proximity matrices T we can use it to create the matrix Q by creating a
surrogate derived data set. This derived set is obtained by listing the cluster centers w
c
i
associated with each data sample x
i
. We then call our proximity matrix subroutine on the
derived data set. Then using T and Q the modied Hubert statistic for general symmetric
matrices X(i, j) and Y (i, j) is obtained by computing
M =
1
2
N(N 1)

X
=
1
M
N1

i=1
N

j=i+1
X(i, j) the same for
Y

2
X
=
1
M
N1

i=1
N

j=i+1
X(i, j)
2

2
X
the same for
2
Y
=
1
M
N

i=1
N

j=i+1
X(i, j)Y (i, j) and

=
1

Y
N

i=1
N

j=i+1
(X(i, j)
X
)(Y (i, j)
Y
) .
Part (a): In this part of this problem we have
c
i
= 1 for i 1, 2, . . . , 8
c
i
= 2 for i 9, 10, . . . , 16 .
197
Problem 16.7 (computing Dunns index)
We let the distance between two clusters be given by
d(C
i
, C
j
) = min
xC
i
,yC
j
d(x, y) .
and the cluster diameter as
diam(C) = max
x,yC
d(x, y) .
Then with these, the Dunn index for a xed number of clusters m is given by
D
m
= min
i=1,2,...,m
_
min
j=i+1,i+2,...,m
_
d(C
i
, C
j
)
max
k=1,2,...,m
diam(C
k
)
__
. (286)
Now based on the above formula and for a xed value of m in the numerator we see
that we need to compute d(C
i
, C
j
) for i = 1, 2, . . . , m (all clusters) and j = i + 1, i +
2, . . . , m (all other clusters). While for the denominator we need to compute diam(C
k
) =
max
x,yC
k
d(x, y) over all m. Each of these calculations involves the pairwise distances be-
tween all the samples in the two clusters. If we extend the limit of j to include the j = i
case we will have all of the pairwise distances needed to evaluate diam(C). Thus we need
the evaluate d(C
i
, C
j
) for i = 1, . . . , n and j = i, i + 1, . . . , m (note the index j starts at i).
Thus there are O(
m(m+1)
2
) pairwise cluster distances we need to calculate to compute the
Dunn index for a xed m. Each of these calculations takes O(
1
2
n
i
n
j
) distance calculations
between data points, where n
i
and n
j
are the number of data points in the ith and jth
cluster respectively. We assume that with m clusters there will be O(
N
m
) data points in each
cluster and thus we have
O
_
N
m

m
2
(m + 1)
_
= O
_
N
2
(m+ 1)
_
,
distance calculations for each m. If we do this for m = 1, 2, . . . , N we need to sum these
numbers and nd the total number of computations given by
N

m=1
O
_
N
2
(m+ 1)
_
=
N
2
O
_
N

m=1
m
_
=
N
2
(N + 1)
4
= O(N
3
) ,
which can be a large number of calculations.
Problem 16.8 (two more Dunn like indices)
In the same way that E
MST
i
is the minimum spanning graph (MSG) derived from the com-
plete graph G
i
from on the samples in the ith cluster C
i
, we dene the graphs E
RNG
i
to be
the relative neighborhood graph (RNG) and E
GG
i
to be the Gabriel graph (GG) based on the
clusters complete graph G
i
. Given these two graphs we will dene the RNG or GG diameter
of the given cluster to be the length of the largest edge in the relative neighborhood or
Gabriel graphs respectively. Once we have dened the GG and RNG diameters as above, we
198
can compute Dunn like indices using a denition similar to Equation 286. We have assumed
the dissimilarity between the two clusters C
i
and C
j
is related to the distance between the
cluster representatives m
i
and m
j
i.e.
d(C
i
, C
j
) = d(m
i
, m
j
) ,
Problem 16.9 (bounds on various Dunn indices)
Since we are told that for a cluster C
i
that
E
MST
i
E
RNG
i
E
GG
i
, (287)
based on this we know that the graph diameters must satisfy a similar ordering
diam
MST
i
diam
RNG
i
diam
GG
i
. (288)
Thus the maximum in the denominator of the Dunn index Equation 286, will get sequentially
larger as we consider the MST, the RNG, and nally the GG graph. Thus the Dunn index
will get smaller and we have
D
GG
m
D
RNG
m
D
MST
m
.
Problem 16.10 (conditions C1-C5)
Part (a): Take the diameter to be the measure of dispersion or spread s
i
around a clusters
mean value. Then we dene R
MST
ij
as
R
MST
ij
=
s
MST
i
+ s
MST
j
d
ij
=
diam
MST
(C
i
) + diam
MST
(C
j
)
d
ij
. (289)
From this we see that C1, C2, C3 are satised. If s
MST
i
> s
MST
k
and d
ij
= d
ik
then we have
R
MST
ij
=
s
MST
j
+ s
MST
i
d
ij
>
s
MST
k
+ s
MST
i
d
ik
= R
MST
ik
,
showing that C4 is true. Given the condition for C5 we have
R
MST
ij
=
s
MST
i
+ s
MST
j
d
ij
>
s
MST
i
+ s
MST
k
d
ik
= R
MST
ik
,
showing C5.
Part (b): The only change to compute R
RNG
ij
and R
GG
ij
is to compute the diameter of
the graph based on the relative neighborhood graph (RNG) or the Gabriel graph (GG)
respectively and use that number to evaluate the spread of a cluster around its center. Thus
R
RNG
ij
and R
GG
ij
should satisfy C1-C5 as R
MST
ij
does.
199
Problem 16.11 (inequalities of DB
m
)
Using Equation 288 we see that when s
method
i
diam
method
i
for the methods MST, RNG, and
GG we have
s
MST
i
s
RNG
i
s
GG
i
.
So form Equation 289 we have
R
MST
ij
R
RNG
ij
R
GG
i
.
Finally since DB
method
m
=
1
m

m
i=1
R
method
i
we thus get
DB
MST
m
DB
RNG
m
DB
GG
m
,
as we were to show.
Problem 16.12 (robustness of MST DB)
Recall that the minimum spanning tree (MST) graph looks only at the smallest tree that
we can construct from the given complete graph G
i
of the points belonging to the i cluster.
Even if cluster i has some outliers if we dene s
MST
i
to be the diameter (the length of
the longest edge in the MST) these outlying points will not aect the value of s
MST
i
, since
the MST is considering the smallest tree. In general, another form of s
i
to be used in R
ij
(not the MST version) would have its value changed due to these outliers. For example, if
we are using a direct cluster diameter diam(C
i
) = max
x,yC
d(x, y) as the denition of s
i
we
expect outliers to aect its value. Since the values of R
MST
ij
are less susceptible to outliers,
minimizing DB
MST
m
=

m
i=1
R
MST
i
as a function of m should be also.
Problem 16.13 (PC and PE as a function of the fuzzier q)
Part (a): As stated in the book in the chapter on fuzzy clustering as q 1
+
then no
fuzzy clustering is better than the best hard clustering. Thus u
ij
= 1 when j = k where the
kth cluster is the one that the best hard clustering would put the sample x
i
into and while
u
ij
= 0 for all other js. Based on this we see that
PC =
1
N
N

i=1
m

j=1
u
2
ij

1
N
N

i=1
1 = 1 ,
and
PE =
1
N
N

i=1
m

j=1
u
ij
log
a
(u
ij
)
1
N
N

i=1
0 = 0 ,
since lim
u0
u log(u) = 0.
200
Part (b): Now as q we have that u
ij

1
m
as each sample has an equal weight in all
clusters and we thus get
PC
1
N
N

i=1
m

j=1
1
m
2
=
1
m
PE
1
N
N

i=1
m

j=1
1
m
log
a
_
1
m
_
=
log
a
(m)
mN
(mN) = log
a
(m) .
Problem 16.14 (limits of XB with respect to q)
We are told that when q + we have lim
q
w
i
= w where w is the mean vector over
the set of data X. Then because of this we see that
d
min
= min
i,j=1,...,m;i=j
[[w
i
w
j
[[ 0 .
At the same time as q we get u
ij

1
m
thus

2
j
=
N

i=1
u
2
ij
[[x
i
w
j
[[
2

i=1
_
1
m
_
2
[[x
i
w[[
2
,
which is a positive constant independent of j. Thus the total variation or the sum of the m
of these
2
j
is also a constant say C. Thus we have shown that as q that
XB
C
0
.
When we want to consider the XB
q
case we recall that
XB
q
=

q
Nd
dim
. (290)
We have already shown that d
dim
0 as q . Consider now the value of
q
as q .
From the denitions given in the book we have

q
=
m

j=1

q
j
=
m

j=1
N

i=1
u
q
ij
[[x
i
w
j
[[ .
As u
ij

1
m
as q we see that u
q
ij
0 as q . Thus each term in the expression for

q
goes to zero. Thus we have XB
q

0
0
which is indeterminate.
Problem 16.15 (limits of FS
q
)
To begin, we rst recall that FS
q
is given by
FS
q
=
N

i=1
m

j=1
u
q
ij
([[x
i
w
j
[[
2
A
[[w
j
w[[
2
A
) . (291)
201
Part (a): If q 1
+
then u
ij
= 1 when the index j corresponds to the cluster k that x
i
is a
member of and u
ij
= 0 for all other j. Thus when q 1
+
we have a hard clustering. If we
let j(i) be the cluster index that the point x
i
is a member of we get
FS
q
=
N

i=1
([[x
i
w
j(i)
[[
2
A
[[w
j(i)
w[[
2
A
) =
N

i=1
[[x
i
w
j(i)
[[
2
A

i=1
[[w
j(i)
w[[
2
A
.
Note that the rst sum in the above is the sum of the data samples x
i
around the individual
cluster representatives w
j
, and the second sum is the sum of cluster representatives w
j
around
the global center w. If we change the sums above, which are over the points x
i
to sums over
the m clusters and the n
j
points inside each we get
FS
q
=
m

j=1
n
j

i=1
[[x
i
w
j
[[
2
A

j=1
n
j
[[w
j
w[[
2
A
= N
m

j=1
n
j
N
_
1
n
j
n
i

i=1
[[x
i
w
j
[[
2
A
_
N
m

j=1
n
j
N
[[w
j
w[[
2
A
= Ntrace(S
w
) Ntrace(S
b
) ,
where we have introduced the within S
w
and between scatter matrices S
b
as
S
w

m

j=1
n
j
N
_
1
n
j
n
j

i=1
(x
i
w
j
)A(x
i
w
j
)
T
_
S
b

m

j=1
n
j
N
(w
j
w)A(w
j
w)
T
.
From an earlier chapter in the book we can write the between scatter matrix S
b
as S
b
=
S
m
S
w
where S
m
is
S
m

1
N
N

i=1
(x
i
w)A(x
i
w)
T
,
to get
FS
q
= Ntrace(S
w
) Ntrace(S
b
) = Ntrace(S
w
) N(trace(S
m
) trace(S
w
))
= 2Ntrace(S
w
) Ntrace(S
m
) ,
the result we wanted to show.
Part (b): If q + then earlier we have shown that u
ij

1
m
so u
q
ij
0 and w
j
w
as q +. Thus FS
q
given by Equation 291 is the sum of terms all of which are going to
zero and is therefore equal to zero in this limit.
Problem 16.16 (distance to the closest point in a sphere)
Our sphere is dened as the points x such that [[x c
j
[[
2
= r
2
j
. We want to nd the point
x

that is on the sphere and closest to some exterior point x


i
. Let the distance (squared)
202
between x
i
and x

be denoted by d
2
= [[x
i
x

[[
2
. We can phrase this problem as a
constrained optimization problem where we want to minimize d
2
as a function of x

subject
to [[x

c
j
[[
2
= r
2
j
. To do this we form the Lagrangian
/ = [[x

x
i
[[
2
([[x

c
j
[[
2
r
2
j
) .
Then the two needed derivatives (and set equal to zero) are
/
x

= 2(x

x
i
) 2(x

c
j
) = 0
/

= [[x

c
j
[[
2
r
2
j
= 0 .
The rst equation states that the vectors x

x
i
is a scalar multiple of the vector x

c
j
meaning that they two vectors are parallel. Thus x

is on the line between the point x


i
and
the center of the sphere c
j
. Solving the rst equation for x

gives the point


x

=
1
1
(x
i
c
j
) . (292)
If we put this point into the constraint [[x

c
j
[[
2
= r
2
j
we get

1
1
(x
i
c
j
) c
j

2
= r
2
j
,
or simplifying some

1
1
x
i

1
1

2
= r
2
j
.
If we solve this equation for we get
= 1
[[x
i
c
j
[[
r
j
.
Now that we know we can use its value in Equation 292 to compute the dierence x
i
x

,
where we nd
x
i
x

= x
1
1
(x
i
c
j
) =

1
x
i
+

1
c
j
.
From what is we can also compute that

1
=
r
j
[[x c
j
[[
1 ,
so the above dierence x
i
x

equals
x
i
x

= x
i

r
j
[[x c
j
[[
x
i
c
j
+
r
j
[[x c
j
[[
c
j
= x
i
c
j

r
j
[[x
i
c
j
[[
(x
i
c
j
) , (293)
which is dened to be the vector
ij
and is the desired expression
203
Problem 16.17 (some moments)
We are told that is dened as
=
1
L

_
/2
/2
xx
T
dl mm
T
.
With x
T
=
_
r cos() r sin()

, dl = rd and L

an arc length. First we have the value of


L

as
L

=

2
(2r) = r .
Next we have m given by
m =
1
L

_
/2
/2
xdl =
1
r
_
/2
/2
_
r cos()
r sin()
_
rd
=
r

_
sin()[
/2
/2
cos()[
/2
/2
_
=
r

_
2 sin(/2)
cos(/2) + cos(/2)
_
=
r

_
2 sin(/2)
0
_
.
Thus
mm
T
=
r
2

2
_
4 sin
2
(/2) 0
0 0
_
.
Next we compute the second moment
1
L

_
/2
/2
xx
T
dl =
1
r
_
/2
/2
_
r cos()
r sin()
_
_
r cos() r sin()

rd
=
r
2

_
/2
/2
_
cos
2
() cos() sin()
cos() sin() sin
2
()
_
d
=
r
2

_
1
2
( + sin()) 0
0
1
2
( sin())
_
,
Thus using this, we nd for the following
= r
2
_
1
2
+
sin()
2
0
0
1
2

sin()
2
_
r
2
_
4
sin
2
(/2)

2
0
0 0
_
= r
2
_
1
2
+
1
2
sin()


4 sin
2
(/2)

2
0
0
1
2

1
2
sin()

_
.
Since r
2
e
= trace() we get
r
2
e
= r
2
_
1
4 sin
2
(/2)

2
_
.
If S =

j:x
j
X

u
j
= r then we get
=
S
2r
e
=
r
2
_
trace()
=

2
_
1
4 sin
2
(/2)

2
which is the result we wanted to show. If = 2 then since sin
2
(/2) = sin
2
() = 0 we nd
= 1.
204
Hints from Probability and Statistics
Moments of a Quadratic Form
Suppose x is a l 1 random vector with E[x] = and Cov(x) = and let A be a l l
symmetric matrix not dependent on x then the quadratic expectation E[x
T
Ax] is given by
E[x
T
Ax] =
T
A + trace(A) . (294)
205
Optimization for constrained problems
Notes on the text
We can show the expression
(A)

= A
T
is true, by explicitly computing the vector derivative
on the left-hand-side. We begin by considering the expression A. Recall that it can be
expressed in component form as
A =
_

_
a
11

1
+ a
12

2
+ a
13

3
+ + a
1l

l
a
21

1
+ a
22

2
+ a
23

3
+ + a
2l

l
.
.
.
a
m1

1
+ a
m2

2
+ a
m3

3
+ + a
ml

l
_

_
.
Using the above expression the vector derivative of A with respect to the vector is then
given by
(A)

=
_

_
(A)
1

1
(A)
2

1
(A)
3

1

(A)m

1
(A)
1

2
(A)
2

2
(A)
3

2

(A)m

2
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
(A)
1

l
(A)
2

l
(A)
3

l

(A)m

l
_

_
=
_

_
a
11
a
21
a
31
a
m1
a
12
a
22
a
32
a
m2
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
a
1l
a
2l
a
3l
a
ml
_

_
= A
T
. (295)
In the rst equation above the notation
(A)
i

j
means the
j
s derivative of the ith row of
A. Now that we have shown that the vector derivative of A with respect to is A
T
we
will use this result in discussing the rst order optimality conditions under minimization of
a function J() subject to linear constraints on .
The rst order optimality constraint for constrained optimization where the constraints are
linear say given by A = b, states that at the optimum value of (denoted by

) there is a
vector such that
J()

= A
T
. (296)
Since A
T
is a linear combination of the rows of A this equation states that at the optimum
point

the vector direction of maximum increase of the objective J is in a direction spanned


by the rows of A. The rows of A (by denition) are also in the directions of the linear
constraints in A = b. Since the vector derivative of the expression
T
A is given by
(
T
A)

= (
T
A)
T
= A
T
,
we can write the rst order optimality constraint expressed by Equation 296 as

_
J()
T
A
_
= 0 .
206
To this expression we can add the term
T
b since it does not depend on and has a derivative
that is zero. With this we get

_
J()
T
(A b)
_
= 0 . (297)
Now if we dene a function /(; ) as
/(; ) J()
T
(A b) ,
we see that our rst order constrained optimality condition given by Equation 297 in terms
of the function / is given by

/(; )) = 0 ,
which looks like an unconstrained optimality condition. Note that because /(; ) is a scalar
we can take the transpose of it to write it as
/(; ) J() (A b)
T
.
From this using Equation 295 we see that the constraint given by A b = 0 in terms of the
function / is equivalent to the vector derivative set equal to zero or

/(; )) = 0 ,
which is another expression that looks like a rst order unconstrained optimality condition.
Thus the functional expression /(; ) provides a convenient way to represent the solution
to linearly constrained optimization problem in the exact same form as an unconstrained
optimization problem but with a larger set of independent variables given by (, ).
Notes on optimization with inequality constraints
In this section of these notes we document at a very high level (without much motivation
or background) how to solve constrained optimization problems. These notes can then
be referenced, as needed, when working with specic optimization problems. The general
optimization problem with inequality constraints is given by
minimize J()
subject to f
i
() 0 for i = 1, 2, , m.
To solve this problem we rst form the Lagrangian, /, dened by
/(; ) J()
m

i=1

i
f
i
() . (298)
The variables
i
in the above expression are called Lagrange multipliers. Using this denition,
a set of necessary conditions for a local minimizer

to exist is the following:


1.

/(

; ) = 0.
207
2.
i
0 for i = 1, 2, , m.
3.
i
f
i
(

) = 0 for i = 1, 2, , m.
These three conditions are called the Karush-Kuhn-Tucker or KKT conditions. The third
conditions are called the complementary slackness conditions. A given complementary slack-
ness condition say
i
f
i
(

) = 0 mean that when this product is zero and


i
,= 0 we have the
original nonlinear constraint f
i
(

) 0 active i.e. at the optimal point

it is the hard con-


straint f
i
(

) = 0. Given these conditions we next ask how to use them to actually nd the
optimal point

. One approach, that might work for small problems, is to explicitly specify
which nonlinear constraints we want to have active that is assume f
i
(

) = 0, from some set


of i. We can than solve the remaining equations for the respective Lagrange multipliers. To
verify that we indeed have a solution we would then need to check that the values computed
for these Lagrange multipliers were non-negative. This can be hard to do in general when
there are many constraints, since there are many possible sets f
i
(

) = 0 to consider. An
alternative approach is to express the problem in its Wolfe Dual Form. This later form
expresses the fact that in the situation where the objective function J() is convex while the
constraint functions f
i
() are concave then the above programming problem is equivalent to
a simpler convex maximization programming problem
maximize
0
/(; )
subject to

/(; ) = 0
and 0 .
The benet of this later formulation is that the relatively complicated nonlinear inequality
constraints of the original problem, f
i
() 0, are replaced with the simpler equality con-
straint

/(; ) = 0 and a maximization over 0. This later problem (if needed) can be
solved with more standard convex programming codes.
208
References
[1] NETLAB: algorithms for pattern recognition. Springer-Verlag New York, Inc., New
York, NY, USA, 2002.
[2] M. H. DeGroot. Optimal Statistical Decisions. 2004.
[3] P. A. Devijver and J. Kittler. Pattern recognition: A statistical approach. Prentice Hall,
1982.
[4] R. C. Gonzalez and R. E. Woods. Digital Image Processing. Addison-Wesley Longman
Publishing Co., Inc., Boston, MA, USA, 2001.
[5] I. S. Gradshteyn and I. M. Ryzhik. Table of Integrals, Series, and Products. Academic
Press, New York, fourth edition, 1965.
[6] W. G. Kelley and A. C. Peterson. Dierence Equations. An Introduction with Applica-
tions. Academic Press, New York, 1991.
[7] F. Kuhl and C. Giardina. Elliptic Fourier Features of a Closed Contour. Computer
Graphics and Image Processing, 18:236258, 1982.
[8] A. V. Oppenheim and R. W. Schafer. Digital Signal Processing. PrenticeHall, 1975.
[9] C. Rorres and H. Anton. Applications of Linear Algebra. Wiley, 1st edition, 1977.
[10] S. Ross. A First Course in Probability. Macmillan, 3rd edition, 1988.
[11] G. Strang. Linear Algebra and Its Applications. Brooks/Cole, 3 edition, 1988.
209

You might also like