# Assignment 1 : Probability

- Due Feb 15, 2016 by 11:59pm
- Points 10
- Submitting a file upload
- Available Feb 8, 2016 at 12am - Feb 20, 2016 at 11:59pm 13 days

# Assignment 1: Probability

**CLPS 1291: Computational Cognitive Science Assignment 1**

Due: ** 11:59PM** on

*Feb, 15*Before you get started:

Look at the Assignment Guidelines for formatting and coding style information, submission guidelines, etc. If you have any questions related to the assignment, please post them in this Discussion.

**As a reminder, we will neither accept answers that fail to follow the given template, nor consider code written outside of the allotted space. We will only review functions that follow our conventions and results documents submitted in the requested form.**

If you are not familiar with MATLAB and programming, this first assignment might take you some time and we would therefore recommend that you start working on it early. We also encourage you to come to the optional tutorials and office hours.

You will need to use this skeleton code to complete the assignment.

We expect you to turn in the following:

- results.pdf - a pdf containing your calculations for problem a) and your responses to problems c) and d)
- answers.zip - a zip file containing:

- answers.m - a MATLAB script with the appropriate sections filled in with your code
- postprob.m - a MATLAB function filled in for problem d).

## Coin Flips (10 points, 2.5 each)

*This question is adapted from a problem set devised and generously provided by Tom Griffiths*

Suppose you found a coin, and wanted to know whether it was fair or biased. Let $\theta $θ denote the probability that the coin produces heads each time you flip it, and assume that successive flips are independent. You have two hypotheses: ${h}_{0}$h0 is the hypothesis that the coin is fair, with $\theta =0.5$θ05; ${h}_{1}$h1 is the hypothesis that the coin is biased, with $\theta =0.9$θ09. A priori, you consider these two hypotheses equally likely, so $p\left({h}_{0}\right)=p\left({h}_{1}\right)=0.5$ph0ph105

#### Problem a)

Imagine you flip the coin once, and it produces heads. Let d denote these data. What is the likelihood of these data under ${h}_{0}$h0 and ${h}_{1}$h1 (i.e., what is $p(d|h0)$pdh0 and $p(d|h1)$pdh1)? Use Bayes rule to compute the posterior probability of ${h}_{1}$h1. Work it out by hand, and show the steps in your calculation.

#### Problem b)

Write a MATLAB script that computes the answer to problem a), and check the results you obtained in problem a) against the output of your script.

#### Problem c)

Now, imagine you flipped the coin $N$N times, and produced a sequence containing ${N}_{H}$NH heads. For instance imagine we flipped a coin 10 times and got 6 heads. What is the likelihood of these data under ${h}_{0}$h0 and ${h}_{1}$h1?

#### Problem d)

Generalize your script from problem b) into a function that takes the number of heads and the number of tails in a sequence, and returns the posterior probability of ${h}_{1}$h1. It should have inputs *heads *(the number of heads observed) and *tails* (the number of tails observed). The output should be *pprob, *the posterior probability of ${h}_{1}$h1.

Plot this posterior probability for sequences with $N={N}_{H}$NNH ranging from 1 to 10. (That is, from one to ten heads in a row.) Describe what happens, and explain intuitively why this is the case. (Please include the graph in results.pdf.)