bayesbay.parameterization.ParameterSpace
- class bayesbay.parameterization.ParameterSpace(name, n_dimensions=None, n_dimensions_min=1, n_dimensions_max=10, n_dimensions_init_range=0.3, parameters=None)
Utility class to parameterize the Bayesian inference problem
- Parameters:
name (str) – name of the parameter space, for display and storing purposes
n_dimensions (Number, optional) – number of dimensions defining the parameter space. None (default) results in a trans-dimensional space.
n_dimensions_min (Number, optional) – minimum and maximum number of dimensions, by default 1 and 10. These parameters are ignored if
n_dimensions
is not None, i.e. if the parameter space is not trans-dimensionaln_dimensions_max (Number, optional) – minimum and maximum number of dimensions, by default 1 and 10. These parameters are ignored if
n_dimensions
is not None, i.e. if the parameter space is not trans-dimensionaln_dimensions_init_range (Number, optional) –
percentage of the range
n_dimensions_min
-n_dimensions_max
used to initialize the number of dimensions (0.3. by default). For example, ifn_dimensions_min
= 1,n_dimensions_max
= 10, andn_dimensions_init_range
= 0.5, the maximum number of dimensions at the initialization isint((n_dimensions_max - n_dimensions_min) * n_dimensions_init_range + n_dimensions_max)
parameters (List[Prior], optional) – a list of free parameters, by default None
Reference Details
- is_leaf
- name
name of the parameter space
- parameters
all the free parameters defined in this parameter space
- perturbation_funcs
a list of perturbation functions allowed in the current parameter space. Each function takes in a state (see
State
) and returns a new state along with the corresponding partial acceptance probability,\[\begin{split}\underbrace{\alpha_{p}}_{\begin{array}{c} \text{Partial} \\ \text{acceptance} \\ \text{probability} \end{array}} = \underbrace{\frac{p\left({\bf m'}\right)}{p\left({\bf m}\right)}}_{\text{Prior ratio}} \underbrace{\frac{q\left({\bf m} \mid {\bf m'}\right)}{q\left({\bf m'} \mid {\bf m}\right)}}_{\text{Proposal ratio}} \underbrace{\lvert \mathbf{J} \rvert}_{\begin{array}{c} \text{Jacobian} \\ \text{determinant} \end{array}},\end{split}\]
- perturbation_weights
a list of perturbation weights, corresponding to each of the
perturbation_funcs()
that determines the probability of each of them to be chosen during each stepThe weights are not normalized and have the following default values:
Birth/Death perturbations: 3
Parameter values perturbation: 6
- trans_d
indicates whether the current configuration allows changes in dimensionality
- birth(ps_state)
adds a dimension to the current parameter space and returns the thus obtained new state along with the log of the corresponding partial acceptance probability,
\[\begin{split}\underbrace{\alpha_{p}}_{\begin{array}{c} \text{Partial} \\ \text{acceptance} \\ \text{probability} \end{array}} = \underbrace{\frac{p\left({\bf m'}\right)}{p\left({\bf m}\right)}}_{\text{Prior ratio}} \underbrace{\frac{q\left({\bf m} \mid {\bf m'}\right)}{q\left({\bf m'} \mid {\bf m}\right)}}_{\text{Proposal ratio}} \underbrace{\lvert \mathbf{J} \rvert}_{\begin{array}{c} \text{Jacobian} \\ \text{determinant} \end{array}}.\end{split}\]In this case, we have
\[\frac{p\left({\bf m'}\right)}{p\left({\bf m}\right)} = \prod_i{p\left({m_i^{k+1}}\right)},\]because all entries of the \(i\)th free parameter, \(\mathbf{m}_i\), are equal to those of \(\mathbf{m'}_i\) except for the newly born \(m_i^{k+1}\), with \(k\) denoting the number of dimensions in the parameter space prior to the birth perturbation.
Furthermore, since \(m_i^{k+1}\) is drawn from the prior and there are \(k+1\) positions available to randomly remove a dimension or add a new one,
\[\frac{q\left({\bf m} \mid {\bf m'}\right)}{q\left({\bf m'} \mid {\bf m}\right)} = \frac{1}{k+1} \frac{\prod_i{p\left({m_i^{k+1}}\right)}}{\frac{1}{(k+1)}} = \frac{1}{\prod_i{p\left({m_i^{k+1}}\right)}}.\]Finally, it is easy to shown that in this case \(\lvert \mathbf{J} \rvert = 1\). It follows that
\[\alpha_{p} = \frac{p\left({\bf m'}\right)}{p\left({\bf m}\right)} \frac{q\left({\bf m} \mid {\bf m'}\right)}{q\left({\bf m'} \mid {\bf m}\right)} = \prod_i{p\left({\mathbf{m}_i^{k+1}}\right)} \frac{1}{\prod_i{p\left({m_i^{k+1}}\right)}} = 1,\]and \(\log(\alpha_{p}) = 0\).
- Parameters:
ParameterSpaceState – initial parameter space state
- Returns:
ParameterSpaceState – new parameter space state
Number – log of the partial acceptance probability, \(\alpha_{p} = \log( \frac{p({\bf m'})}{p({\bf m})} \frac{q\left({\bf m} \mid {\bf m'}\right)}{q\left({\bf m'} \mid {\bf m}\right)} \lvert \mathbf{J} \rvert) = 0\)
- death(ps_state)
removes a dimension from the given parameter space and returns the thus obtained new state along with the log of the corresponding partial acceptance probability,
\[\begin{split}\underbrace{\alpha_{p}}_{\begin{array}{c} \text{Partial} \\ \text{acceptance} \\ \text{probability} \end{array}} = \underbrace{\frac{p\left({\bf m'}\right)}{p\left({\bf m}\right)}}_{\text{Prior ratio}} \underbrace{\frac{q\left({\bf m} \mid {\bf m'}\right)}{q\left({\bf m'} \mid {\bf m}\right)}}_{\text{Proposal ratio}} \underbrace{\lvert \mathbf{J} \rvert}_{\begin{array}{c} \text{Jacobian} \\ \text{determinant} \end{array}}.\end{split}\]Following a reasoning similar to that explained in the documentation of
birth()
, in this case \(\log(\alpha_{p}) = 0\).- Parameters:
ParameterSpaceState – initial parameter space state
- Returns:
ParameterSpaceState – new parameter space state
Number – log of the partial acceptance probability, \(\alpha_{p} = \log( \frac{p({\bf m'})}{p({\bf m})} \frac{q\left({\bf m} \mid {\bf m'}\right)}{q\left({\bf m'} \mid {\bf m}\right)} \lvert \mathbf{J} \rvert) = 0\)
- initialize(position=None)
initializes the parameter space including its parameter values
If
position
is None, a single parameter space state is initialized; otherwise, a list of parameter space states is initialized randomly.If
self._n_dimensions_init_range
is not None, the number of dimensions will be initialized randomly within the range defined by the init range.Paramters
- positionnp.ndarray, optional
initial position of the parameter space, by default None. The type is np.ndarray so as to align with other instances to be initialized, such as the priors; here only the length of
position
is used.
- returns:
an initial parameter space state
- rtype:
ParameterSpaceState
- log_prior(param_space_state)
- sample(*args)
Randomly generate a new parameter space state
The new value is sampled from (the full range of) the prior distribution of each parameter, regardless of the value of
self._n_dimensions_init_range
set during initialization.- Returns:
randomly generated parameter space state
- Return type: