Bayesian Problem: What is the Expected number of mattresses that the Princess slept on? It's been a while since I've done some Bayesian problems but I'm looking for some help with the following:

"Each night, a princess is equally likely to sleep on anything from six to twelve mattresses. > On half of the nights of the year, a pea is placed underneath the lowest mattress. She never falls asleep if a pea is placed underneath a pile of six mattresses. If the pea is placed underneath seven mattresses, she sleeps wonderfully one night out of ten; under eight mattresses, she sleeps well two out of ten nights; and so on, until if the pea is placed underneath the full twelve mattresses, she sleeps well six out of ten nights. One morning, when her good friend Bayes woke her up, she said that she had slept incredibly well that night! What is the expected number of mattresses upon which she slept?"

What I've done so far:
the princesses quality of sleep is predicated on the whether a pea is present and the number of mattresses she chooses, therefore conditional probability would allow for the use of Bayes Theorem. We are asked for the Expected number of mattresses she slept on based on the fact that she had a good night's sleep, so I've structured the question as such:
$$P(mattress.stack|slept.well) = \frac{P(slept.well|mattress.stack).P(mattress.stack)}{P(slept.well)}$$ 
where:


*

*P(slept.well|mattress.stack) = 0.1,0.2,0.3,0.4,0.5,0.6

*P(mattress.stack) = 1/7

*P(slept.well) = 180/360 (assuming there are 360 days in a year)


Calculating values for each of the entries in P(slept.well|matress.stack) for each set of mattresses I get:


*

*6: 0

*7: 0,03

*8: 0,05

*9: 0,08

*10: 0,11

*11: 0,14

*12: 0,17


$$Expected number of mattresses = 6(0)+7(0,03)+8(0,05)+9(0,08)+10(0,11)+11(0,14)+12(0,17) = 6 mattresses$$
and this is for sure wrong. Please, any help would be much appreciated. Any intuitive explanation or guidance would also be awesome. Thanks
 A: First, notice that P(slept.well|mattress.stack=6)=0.5 and not 0. If there is no pea, she sleeps well no matter the number of matrices. Then, 
$$P(\text{slept.well}|\text{mattress.stack}=7) =\frac{1}{2}+\frac{1}{2}\frac{1}{10}=\frac{11}{20},$$
and in general, for $6\leq m\leq 12$,
$$P(\text{slept.well}|\text{mattress.stack}=m) =\frac{1}{2}+\frac{1}{2}\frac{m-6}{10}=\frac{4+m}{20}.$$
Similarly, by assuming that P(slept.well)=1/2, you disregard that she may sleep well even if there is a pea under her mattresses. In fact the unconditonal probability that she sleeps well a night is
\begin{align}
P(\text{slept.well}) &=\sum_{m=6}^{12}\frac{1}{7}\left(\frac{1}{2}+\frac{1}{2}\frac{m-6}{10}\right)\\
&=\frac{1}{2}+\frac{1}{7}\sum_{k=0}^{6}\frac{k}{10}\\
&=\frac{13}{20}.
\end{align}
With this in mind, you can recalculate correctly the values of the conditional probability distribution P(mattress.stack|slept.well), and then the conditional expectated value that you are after.
A: Let $X\in\{6,7,8,9,10,11,12\}$ and denotes the number of mattresses.  Let $Y\in\{TRUE,FALSE\}$ denote whether a pea is present.  Let $Z\in\{True,False\}$ denote sleeping well or not.  
Your parameter space is $X\times{Y}$.  To solve for the expected number of mattresses, given that you know she slept well, you must first find the posterior probability for each parameter.  You have fourteen possible combinations of parameters.
Your sample space is binary.
Note the following things.
$$P(X=x)=\frac{1}{7}$$
$$P(Y=y)=\frac{1}{2}$$
$$f(Z=z|X=x;Y=y)=\left\{
  \begin{array}{lr}
    1 & : \text{y is true}\\
    (x-6)/10 & : \text{y is false}  \end{array}
\right.$$
So, the posterior probability for each case is $$P(X=x;Y=y|Z=z)=\frac{f(Z=z|X=x;Y=y)P(Y=y)P(X=x)}{\sum_{x\in\{6,7,8,9,10,11,12\}}\sum_{y\in\{TRUE,FALSE\}}f(Z=z|X=x;Y=y)P(Y=y)P(X=x)}$$
This is step one because you need to remove the effect of the unknown status of the pea.
For example, if Z=1 and X=7 and Y=FALSE, then the calculation of the numerator is $$1\times\frac{1}{7}\times\frac{1}{2}.$$  If Y had been true, then the calculation of the numerator would have been $$(7-6)/10\times\frac{1}{7}\times\frac{1}{2}.$$  The denominator is the sum of the set of possible numerators.
The denominator ends up being $$7\times\frac{1}{14}+\sum_{x=6}^{12}\frac{x-6}{10\times{7}\times{2}}=.65.$$
That gives you 14 posterior probabilities, but you need there to be seven because you do not care about the state of the pea.
To find the posterior probability of each mattress state, given both the data and the state of the pea, we need to marginalize out the effect of the pea.
$$P(X=x|Z=z)=\sum_{Y\in\{True,False\}}P(X=x;Y=y|Z=z).$$
So, for example, $P(X=6|Z=TRUE)\approx{.11}+0.$  There is an approximately 11% chance that the true parameter state was that there were six mattresses and no pea and a zero percent chance there were six mattresses and a pea.  The total probability of there being six mattresses is the sum of the two possible cases.
As a calculation, $$P(X=6|Z=True)=\frac{\frac{1}{14}}{\frac{13}{20}}+\frac{0}{\frac{13}{20}}.$$
The expectation is $$E(X=x|Z=z)=\sum_{x=6}^{12}(x\times{}P(X=x|Z=z)),$$ which, in this case, equals approximately 9.3.
There are some other things to note about this posterior expectation.  If you knew that no pea was present, then the posterior expectation would be 9 mattresses.  So sleeping is a strong indicator that no pea was present.  Indeed, the effect of no pea being present strongly dominates the cases so that knowing she slept tells you that there is a $\frac{10}{13}$ chance that there was no pea.
The effect is that the number of mattresses is barely pulled away from 9, given you do not know the state of the pea.  The maximum a posteriori estimator, however, is 12 mattresses.
Knowing the princess slept is not a lot of information in this case.  The posterior variance is 3.9.  That is because sleeping provides very little information.  Graphically, the posterior is below:

