Your Federal Quarterly Tax Payments are due April 15th

# Computer projects from chapter 2 by panniuniu

VIEWS: 0 PAGES: 3

• pg 1
```									              Computer projects from chapter 2
MA8702 Spring 2004

Exercise 1

http://www.math.ntnu.no/~hrue/MA8702/frame45.dat

and display it in R as

>   x = matrix(scan("frame45.dat"),256,256)
>   for(i in 1:256) x[i,1:256] = x[i,256:1]
>   par(pty="s")
>   image(x/256,col=gray(seq(0,1,len=256)))

Note: R display the image where x[1, 1] is lower left corner, x[256, 1] is lower right corner and
x[256, 256] is upper right corner.
Then you obtain this on the screen
1.0
0.8
0.6
0.4
0.2
0.0

0.0     0.2   0.4       0.6   0.8      1.0

You may copy to ﬁle using

> dev.copy2eps(file="frame45.eps")

1
Task: track the outer and upper smooth contour of the head, from a position about (50, 160) to a
position about (200, 160), using dynamic programming.

Hint: You need ﬁrst to deﬁne a model for this task, containing both a prior and the likelihood.
The initial positions, is about here

1.0
0.8
0.6
0.4
0.2
0.0

0.0   0.2    0.4       0.6    0.8      1.0

which was obtained with

>   x[50+ -1:1,160+ -1:1]=500
>   x[200+ -1:1,160+ -1:1]=500
>   image(x/256,col=gray(seq(0,1,len=256)))
>   dev.copy2eps(file="frame45-marks.eps")

You may add a (thick) line to the image with a speciﬁc colour, as for example

> par(fg="white")
> lines(c(0.2,0.4), c(0.5,0.8),lwd=5)

hence you may use this to superimpose your estimate of the contour.

2
Exercise 2

A discrete time two state (0 and 1) Markov chain evolves with this transition matrix

p  1−p
P =
1−p  p

A realisation of xt , t = 1, . . . , 100 is observed as yt , t = 1, . . . , 100, but with probability q = 0.3 the
wrong state is observed, so
xt        prob = 0.7
Prob(yt | xt ) =
1 − xt prob = 0.3

Task 1.    Compute the posterior density π(p|y).

Task 2. Generate exact samples from π(x|y, p∗ ), where p∗ is a chosen value. Plot your estimate of
E(xt |y, p∗ ) as a function of t and quantify the Monte Carlo error as a function of t.