In this section we learn about how to update parameters that take on
finite numbers of values. Clearly, it does not work to add a Gaussian
step to such a parameter. Instead, we address this problem by sampling
from the full conditional distribution of the discrete parameter.
(This is as yet the only example where we have allowed YADAS to be
polluted with sampling from full conditional distributions.)
YADAS's infrastructure for computing ratios of posterior distributions
serves it well in this situation. Suppose is the unnnormalized
posterior distribution evaluated at a discrete-valued parameter and
the remaining parameters . If the current value of is and
we are contemplating changing the value of this parameter to ,
YADAS is set up to compute the ratio
.
If we compute this ratio for all values of , a sample from the
full conditional distribution of chooses with probability
proportional to .
It is quite easy to use the `FiniteUpdate` class: one simply
inserts a `FiniteUpdate` into the update array. The constructor
of `FiniteUpdate` requires only the name of the parameter and
an array of integers with the same number of elements as the parameter.
The integers list how many possible values each element of the parameter
can take on. (We assume that the possible values of the th element
of the parameter are
, in which case
should be placed inside the integer array.)

We illustrate the use of `FiniteUpdate` with a simple example
in which we sample from the beta-binomial distribution. This example
was inspired by [1].
Click on the buttons to call up the code and the data file.

This is not a statistical problem in that there is no data:
the situation is that a probability is sampled from a
Beta distribution, and conditionally on ,
is sampled from a binomial distribution with sample size
and probability . We estimate the joint distribution
of using MCMC: we alternate between updating and ,
updating when it is its turn using random walk Metropolis,
and updating by sampling from its full conditional.
As noted in the code, the code has
a few annoying features: the input file must contain a
real variable to use as an argument to the `Binomial Likelihood`,
and it also must contain an integer variable to
tell `FiniteUpdate` the number of possible values
of . A sanity check is that the marginal distribution of
turns out to be the beta distribution with the supplied
parameters.
Note that the restriction that the possible values of the
parameter are zero up to some maximum is in fact not a restriction
at all, because such parameters are ideally suited for use as
subscripting variables in `ArgumentMaker`s.

In some cases, the number of possible values of a finite-valued
parameter is large, so it may be inefficient to entertain all possible
values when updating the parameter. In this case,
`IntegerMCMCParameter` can be used to propose a Gaussian-like
step that proposes a discrete move. The constructor of an
`IntegerMCMCParameter` looks exactly like that for an ordinary
`MCMCParameter`, so the step size is the standard deviation of
the Gaussian that is sampled before being converted to an integer.
(The proposal is
, where Z is standard normal.) If you use this
option, there must be a likelihood function that prevents
from taking on disallowed values, using negative infinities.