Docsity

Estimating Gaussian PDF in Machine Learning: Max Likelihood & Max A Posteriori, Assignments of Programming Languages

Toggle sidebar
bg1
CS591: Intro to Machine Learning, F’03
1
Homework 3
Due: Oct 14, 2003
1. (Note that this problem should have originally appeared with iranging from 1 to d, not 0, so I
have followed that in this solution. Adding the 0-order term doesn’t change anythinging sig-
nificant, however—it only adds a factor of ewhich can be incorporated into the normalizing
constant.)
Consider the function
g(x) = ke−(x−θ1)−(x−θ2)2−(x−θ3)3−···−(x−θd)d
=ke−Pd
i=1(x−θi)i
for some even dand θd6= 0.
(a) Show that there exists a ksuch that g(x)is a valid PDF. (Hint: you do not need to find
that k— you merely need to show that it must exist. Consider the behavior of this
function for large x, as compared to the behavior for other PDFs that you’ve seen.)
They key to this problem is to realize that only two criteria need to be established to
show that g(x)is a valid PDF:
i. g(x)≥0∀x
ii. R∞
x=−∞ g(x)dx = 1
The first property is clearly true (though it does need to be stated explicitly), but the
second is harder to establish. Note that, because I did not require you to find the kthat
normalizes g(x), it suffices to show simply that
eg(x) = e−(x−θ1)−(x−θ2)2−(x−θ3)3−···−(x−θd)d
has a finite integral. It’s clear that eg(x)is finite for any finite x, so for any finite range,
say, [xl, xu],Rxu
xleg(x)dx is also finite. Therefore, the critical behavior of eg(x)is in
the tails: as x→ ±∞, does eg(x)remain bounded and, if so, does it possess a finite
integral in the tails?
Observe that for an odd p,limx→−∞ e−xp=∞, while for an even p,limx→±∞ e−xp=
0. Because dis specified to be even in this case, we know that the final term of the
exponent will go to zero at the tails. It turns out that, asymptotically, this term will
dominate the other terms in the exponent, and all of eg(x)will approach 0 in both tails
(specifically, eg(x)∈O(e−xd); you can establish this rigorously via L’Hopital’s rule,
but an asymptotic argument is sufficient for this problem).
So now we know that eg(x)is finite over its entire range and approaches 0 in the tails,
but we have not yet established that it has a finite integral over its entire range. We
know that it has a finite integral over an (arbitrary) finite range, [xl, xu], but not that
the (infinitely long) tails have a finite volume. You could attack this directly with series
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Partial preview of the text

Download Estimating Gaussian PDF in Machine Learning: Max Likelihood & Max A Posteriori and more Assignments Programming Languages in PDF only on Docsity!

Homework 3

Due: Oct 14, 2003

  1. (Note that this problem should have originally appeared with i ranging from 1 to d , not 0 , so I have followed that in this solution. Adding the 0-order term doesn’t change anythinging sig- nificant, however—it only adds a factor of e which can be incorporated into the normalizing constant.) Consider the function

g(x) = ke−(x−θ^1 )−(x−θ^2 ) (^2) −(x−θ 3 ) (^3) −···−(x−θd)d

= ke−^

Pd i=1(x−θi)i

for some even d and θd 6 = 0.

(a) Show that there exists a k such that g(x) is a valid PDF. (Hint: you do not need to find that k — you merely need to show that it must exist. Consider the behavior of this function for large x, as compared to the behavior for other PDFs that you’ve seen.) They key to this problem is to realize that only two criteria need to be established to show that g(x) is a valid PDF: i. g(x) ≥ 0 ∀x ii.

x=−∞ g(x)dx^ = 1 The first property is clearly true (though it does need to be stated explicitly), but the second is harder to establish. Note that, because I did not require you to find the k that normalizes g(x) , it suffices to show simply that

˜g(x) = e−(x−θ^1 )−(x−θ^2 )

(^2) −(x−θ 3 ) (^3) −···−(x−θd)d

has a finite integral. It’s clear that ˜g(x) is finite for any finite x , so for any finite range, say, [xl, xu] ,

∫ (^) xu xl ˜g(x)dx^ is also finite.^ Therefore, the critical behavior of^ ˜g(x)^ is in the tails: as x → ±∞ , does ˜g(x) remain bounded and, if so, does it possess a finite integral in the tails? Observe that for an odd p , limx→−∞ e−x p = ∞ , while for an even p , limx→±∞ e−x p = 0_. Because_ d is specified to be even in this case, we know that the final term of the exponent will go to zero at the tails. It turns out that, asymptotically, this term will dominate the other terms in the exponent, and all of ˜g(x) will approach 0 in both tails (specifically, ˜g(x) ∈ O(e−x d ) ; you can establish this rigorously via L’Hopital’s rule, but an asymptotic argument is sufficient for this problem). So now we know that g˜(x) is finite over its entire range and approaches 0 in the tails, but we have not yet established that it has a finite integral over its entire range. We know that it has a finite integral over an (arbitrary) finite range, [xl, xu] , but not that the (infinitely long) tails have a finite volume. You could attack this directly with series

arguments from calculus or analysis, but it’s simpler in this case to note that g(x) can be written as:

g(x) = ke−(x−θ^2 )

e−(x−θ^1 )e−^

Pd i=3(xi−θi)

= ke−(x−θ^2 )

2 f (x)

that is, as (effectively) a Gaussian component multiplied by another function of x_. We know that_ f (x) itself asymptotically approaches 0 in both tails, so there must exist some xl and xu such that f (x) ≤ 1 for all x ≤ xl or ≥ xu_. Thus, in the region beyond_ xl and xu , ˜g(x) is bounded above by the tails of some Gaussian. Because the Gaussian is a PDF, its tails have finite volume, so the tails of some function bounded below it must also have finite volume. Ergo, ˜g(x) has a finite integral and there must exist some constant k that normalizes it to 1, making g(x) a proper PDF.

(b) Find a maximum likelihood estimator for θi. You may leave your answer in the form “the roots of the following polynomial... ” without actually finding the roots explicitly, but you must give the correct polynomial. Begin by writing down the likelihood and log-likelihood functions. For a sample

{x 1 , x 2 ,... , xN } ,

L(Θ;

) =

∏^ N

j=

g(xj )

= kN^ e

PN j=1 (−^

Pd i=1(xj^ −θi)i)

L(Θ;

) = N log k −

∑^ N

j=

∑^ d

i=

(xj − θi)i)

where Θ denotes the entire set of parameters θ 1 ,... , θd_. The MLE for_ θi is just θ̂i = arg max θi

L(Θ;

) :

∂θi

L(Θ;

) =

∂θi

N log k −

∂θi

∑N

j=

∑^ d

i=

(xj − θi)i)

∑^ N

j=

i(xj − θi)i−^1

= i

∑^ i−^1

m=

i − 1 m

θmi (

∑^ N

j=

xii− 1 −m)

where the second-to-last line is simply the binomial expansion of the previous expres- sion. The desired MLE, then, is one of the zeros of the polynomial given by the last two lines. Note, however, that this equation has up to d unique roots in θi , some (or all!) of which may be complex and, furthermore, a second derivative test will be needed to

For the moment, let’s work purely with the exponent (and neglect the factor of − 1 / 2 ):

(μ − ν)^2 τ 2

∑N

i=1(xi^ −^ μ)

2 σ^2

=

σ^2 τ 2

σ^2 (μ − ν)^2 + τ 2

i

(xi − μ)^2

σ^2 τ 2

σ^2 μ^2 − 2 σ^2 νμ + σ^2 ν^2 + Nτ 2 μ^2 − 2 τ 2

i

xi

μ + τ 2

i

x^2 i

σ^2 τ 2

(σ^2 + Nτ 2 )μ^2 − 2

σ^2 ν + τ 2

i

xi

μ +

σ^2 ν^2 + τ 2

i

x^2 i

Completing the square (recall that ax^2 + by + c = a(x − − 2 ab )^2 + c − b 2 4 a ), we find:

1 σ^2 τ 2

([

(σ^2 + Nτ 2 )

μ −

σ^2 ν + τ 2

i xi σ^2 + Nτ 2

) 2 ]

  • (σ^2 ν^2 + τ 2

i

x^2 i ) −

(σ^2 ν + τ 2

i xi)

2 2(σ^2 + Nτ 2 )

[

σ^2 τ 2 (σ^2 +N τ 2 )

μ −

σ^2 ν + τ 2

i xi σ^2 + Nτ 2

) 2 ]

σ^2 τ 2

[

(σ^2 ν^2 + τ 2

i

x^2 i ) −

(σ^2 ν + τ 2

i xi)

2 2(σ^2 + Nτ 2 )

]

from which we see that LMAP(μ|

) , regarded purely as a function of μ , is itself a Gaussian with mean and variance:

mean(μ) =

σ^2 ν + τ 2

i xi σ^2 + Nτ 2

var(μ) =

σ^2 τ 2 (σ^2 + Nτ 2 )

It turns out that when you take the derivative of the MAP log-likelihood, most of the terms in the above drop out and you get:

∂ ∂μ

LMAP(μ|

) = −

σ^2 τ 2 (σ^2 +N τ 2 )

μ −

σ^2 ν + τ 2

i xi σ^2 + Nτ 2

μ̂ MAP =

σ^2 ν + τ 2

i xi σ^2 + Nτ 2

=

τ 2 σ^2 + Nτ 2

i

xi +

σ^2 σ^2 + Nτ 2

ν

, i.e., the MAP estimate of the mean of the data is, perhaps unsurprisingly, the mean of the posterior distribution. This expression can be seen as a weighted mean between the ML estimate ( (^) N^1

i xi ) and the prior estimate of the mean ( ν ). There are two special cases worth considering:

  • σ^2  Nτ 2 : Here the variance of the data is much greater than the variance of your prior estimate and the coefficient of

i xi^ in the first term goes to 0, while the coefficient of the second term goes to 1. In this case, the data has almost no influence and your new estimate of the mean ( μ̂ MAP ) is largely the prior estimate ν.

  • Nτ 2  σ^2 : This is the converse of the previous case—the first term dominates and the second term is negligible and ̂μMAP is almost entirely formed from the data, i.e., is almost exactly ̂μML_._ (b) Suppose that you take a radar gun (these are metallic African swallows) and measure the airspeed of nine swallows as X = { 106 , 85 , 77 , 81 , 100 , 53 , 100 , 62 , 73 }. What are the respective ML and MAP estimates of μ after you see this data, given the prior beliefs ν = 50 and τ = 10? What about if ν = 50 and τ = 1, ν = 50 and τ = 150, or ν = 125 and τ = 5? In each case, plot (on a single plot) the prior belief, the ML estimate, and the MAP estimate. First, find ̂μML = 81. 89 and σ = 17. 96 using the ML estimator for μ and the standard estimate of σ.^1 Now, using the result from part (a), we can find: ν = 50; τ = 10

̂ μMAP =

τ 2 σ^2 + Nτ 2

i

xi +

σ^2 σ^2 + Nτ 2

ν

17. 962 + (9)(10^2 )

17. 962 + (9)(10^2 )

(the plots will be available when I’m back at a terminal that supports matlab.) ν = 50; τ = 1 μ̂ MAP ≈ 50. 9 ν = 50; τ = 150 μ̂ MAP ≈ 81. 8 ν = 125; τ = 5 μ̂ MAP ≈ 107. 3 Clearly, the choice of prior can have a large impact on your estimate of μ , especially for small N_. If you’re not careful with your prior, it can totally wash out the data. On the other hand, when_ N is small, the variance of ̂μML can itself be quite large and the prior is quite a stabilizing effect. It’s a difficult tradeoff, so most often people choose priors to influence the data very little. I.e., they choose a nearly uniform prior so as to provide some estimate of what’s going on when the data is very sparse (e.g., N ≤ 1 ), but so that the prior is easily washed out by any significant amount of data at all. (^1) Actually, taking a separate estimate of σ from μ is something of an abuse—to do this exactly right requires

handling them simultaneously—but that’s tangential to this problem, so we’ll take the easy way out for the moment.

(ii) Give the moralized graph.

(iii) Give a triangulated graph.

(iv) Give the junction tree.

(v) Describe the sequence of eliminations/messages (i.e., marginalizations and joint proba- bility tables) necessary to calculate p(C) given evidence at A and E.

(a)

C

A B D E

This is the na¨ıve Bayes model—possibly the simplest possible learning model for cat- egorical data. It asserts that the features ( A, B, D, and E ) are conditionally indepen- dent, given the class. Specifically, the joint probability is given by

p(A, B, C, D, E) = p(C)p(A|C)p(B|C)p(D|C)p(E|C)

which requires O(k^2 ) space to represent. For this model, the moralized and triangulated graphs are the same:

C

A B D E

while the junction tree takes a particularly simple form:

AC

BC

DC

EC

C

C

C

or, equivalently,

AC C BC C DC C EC

To calculate p(C|A = a, E = e) , we calculate

p(C|A = a, E = e) =

B,D p(A^ =^ a, B, C, D, E^ =^ e) p(A = a, E = e)

=

B,D p(C)p(A^ =^ a|C)p(B|C)p(D|C)p(E^ =^ e|C) p(A = a, E = e)

=

p(C)p(A = a|C)p(E = e|C) (

B p(B|C)) (

D p(D|C)) p(A = a, E = e)

=

p(C)p(A = a|C)p(E = e|C) p(A = a, E = e)

The last step occurs because

B p(B|C)^ is just the vector of 1’s (because^ B^ isn’t instantiated), while the term p(A = a|C) yields a vector—the probability that the variable A takes on the observed value a for each of the possible values that C can take on. Nodes such as BC which contribute no information to the sum are said to be barren. The numerator is equivalent to messages sent from the node AC to the node EC via the separator C , followed by the return message from EC to AC_. After both messages, the value of_ p(A = a, C, E = e) can be evaluated at either node, and the denominator can be calculated by marginalizing out C_. Altogether, this requires_ O(k^2 ) operations.

(b)

A B D E

C

This is the converse of the previous model—it’s the richest possible model of categorical data, including all potential statistical relationships between different elements, as seen in its joint probability:

p(A, B, C, D, E) = p(A)p(B)p(D)p(E)p(C|A, B, D, E)

The last factor is, effectively, a complete 5-dimensional table with k^5 elements. The structure is visible in its moralized, undirected graph (recall that every pair of parents of a given node must be connected in the moral graph):

A

B

D

C

E

F

G

which has at least two junction trees, one of which is:

FG CEF

F CF

CDF

CD

ABCD

To calculate p(C|A = a, E = e) , it turns out that F G is a barren node and its messages are unimportant (a vector of 1’s, as in part (a), above), so the only messages are from the nodes CEF and ABCD_. Picking an arbitrary node containing_ C as our root (say, CDF ), we propagate messages in from the leaves to the root and then back out to the leaves. E.g., the message from CEF is the 2-d “slice” of the table p(E = e|C, F ) corresponding to the evidence E = e —i.e., one value for the probability of E = e for every pair of values that C and F can take on. At the end, we maginalize C from any of the nodes containing it and normalize. The entire operation requires time bounded by the largest relevant clique, i.e., O(k^4 ). Note that if the evidence had been F = f instead of A = a , the clique node ABCD would be uninvolved and inference would require only O(k^3 ) in this case.

(d)

E

G

B

F

D

H I J

A C

p(A, B, C, D, E, F, G, H, I, J) = p(A)p(B)p(C)p(D|A, B)p(E|B, C)p(F |D)p(G|E)p(H|F )p(I|F,

which requires O(k^3 ) space (from the terms for D , E , and I , all of which have 2 parents). This graph requires only a little moralization (no node has more than two parents):

E

G

B

F

D

H I J

A C

leaves. After doing so, all nodes reflect the evidence that A = a and E = e , so we can obtain P (C|A = a, E = e) by marginalizing BCE for C and normalizing. The whole process requires time bounded by the largest clique, i.e., O(k^3 ).