Solution (source code)

= Solution

A <prior distribution> assigns uncertainty to a parameter before observing data. Multiplying its density by the <likelihood> and normalizing gives the <posterior distribution>. A <Bayes estimator> minimizes the posterior expected <loss function> for each observed sample, and therefore minimizes integrated Bayes risk when the expectations exist.

For <quadratic loss> $(d-\theta)^2$, the conditional risk is $\operatorname{Var}(\theta\mid x)+(d-E(\theta\mid x))^2$, so its minimizer is the posterior mean. For <absolute loss> $|d-\theta|$, the one-sided derivatives or subgradients show that a minimizer is any posterior median, characterized by $P(\theta<d\mid x)\le1/2$ and $P(\theta>d\mid x)\le1/2$.

For the stated <uniform distribution> sampling model, let $x_{\min}=\min_i x_i$, $x_{\max}=\max_i x_i$. The <likelihood> is $2^{-n}$ on $x_{\max}-1<\theta<x_{\min}+1$ and zero elsewhere. Intersecting this interval with the <uniform prior> gives
$$
A=\max(20,x_{\max}-1),\qquad B=\min(50,x_{\min}+1).
$$
When $A<B$, the <bounded uniform-location posterior> is
$$
\boxed{\pi(\theta\mid\mathbf x)=\frac1{B-A}\mathbf1_{(A,B)}(\theta),\qquad \widehat\theta_{\rm quadratic}=\widehat\theta_{\rm absolute}=\frac{A+B}{2}.}
$$
The posterior is symmetric, so its mean and unique median coincide. If $A\ge B$, the data have zero marginal <likelihood> under the stipulated prior/sampling model and this posterior density cannot be normalized. An empty or singleton intersection is not an ordinary uniform posterior of positive width.