bayesbay.likelihood.LogLikelihood
- class bayesbay.likelihood.LogLikelihood(targets=None, fwd_functions=None, log_like_ratio_func=None, log_like_func=None)
Helper class to evaluate the log likelihood ratio
One out of the following three sets of input needs to be supplied:
target
andfwd_functions
log_like_ratio_func
log_like_func
The input will be taken in precedence as above. For example, if both
target
andfwd_functions
are supplied, thenlog_like_func
andlog_like_ratio_func
are ignored regardless of their values, and so on.This class then will wrap the input functions properly so that the
log_likelihood_ratio()
is ready for use by the Markov chains.If
targets
are supplied and if any of them have unknown data noise, and if the high level API is used (i.e.BayesianInversion
instead ofBaseBayesianInversion
is used), then the perturbations of the data noises will be taken into account regardless of whetherfwd_functions
is given, and the state for each chain will be initialized accordingly for the unknown data noise.- Parameters:
targets (bayesbay.Target, optional) – a list of data targets, default to None
fwd_functions (List[Callable[[bayesbay.State], np.ndarray]], optional) – a list of forward functions corresponding to each data targets provided above. Each function takes in a state and produces a numpy array of data predictions. Default to None.
log_like_ratio_func (Callable[[Any, Any], Number], optional) –
a function to calculate the log likelihood ratio \(\log(\frac{p(\mathbf{d}_{obs} \mid \mathbf{m}')}{p(\mathbf{d}_{obs} \mid \mathbf{m})})\). It takes the current and proposed models, \(\mathbf{m}\) and \(\mathbf{m'}\), whose type should be consistent with the other arguments of this class, and returns a scalar. This is utilised in the calculation of the 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}\]where \(\mathbf{J}\) denotes the Jacobian of the transformation. If None,
log_like_func
gets used instead. Default to Nonelog_like_func (Callable[[Any], Number], optional) – a function to calculate the log likelihood \(\log(p(\mathbf{d}_{obs} \mid \mathbf{m}))\). It takes in a model \(\mathbf{m}\) (any type is allowed, as long as it is consistent with the other arguments of this class) and returns a scalar. This function is only used when
log_like_ratio_func
is None. Default to None
Reference Details
- fwd_functions
list of forward functions associated with the current log likelihood instance
- perturbation_funcs
A list of perturbation functions associated with the data noise of the provided targets.
Perturbation functions are included in this list only when the data noise of the target(s) is explicitly set to be unknown(s).
- 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 a following default value of 1 for the data noise perturbation that perturbs all the target unknown noises together.
- targets
list of targets associated with the current log likelihood instance
- add_targets(targets=None, fwd_functions=None)
add new target(s) and its/their associated forward function(s)
- Parameters:
- Raises:
TypeError – when the
targets
isn’t a list of Target of a single Target instance, or when thefwd_functions
isn’t a list of functions or a single function
- add_targets_observer(inversion)
add an observer (typically an instance of the high level
BayesianInversion
). When the data targets are extended with new observations, the observers will be notified by being calledupdate_log_likelihood_targets
method- Parameters:
inversion (BayesianInversion) – the observer to be added to the notification list
- initialize(state)
initialize the starting state of data noise associated with the targets in current log likelihood that are hierarchical (i.e. having unknown data noise)
- Parameters:
state (State) – the state to be updated on
- log_likelihood_ratio(old_state, new_state, temperature=1)
Returns the (possibly tempered) log of the likelihood ratio
\[\left[ \frac{p\left(\mathbf{d}_{obs} \mid \mathbf{m'}\right)}{p\left(\mathbf{d}_{obs} \mid \mathbf{m}\right)} \right]^{\frac{1}{T}} = \left[ \frac{\lvert \mathbf{C}_e \rvert}{\lvert \mathbf{C}^{\prime}_e \rvert} \exp\left(- \frac{\Phi(\mathbf{m'}) - \Phi(\mathbf{m})}{2}\right) \right]^{\frac{1}{T}},\]where \(\mathbf{C}_e\) denotes the data covariance matrix, \(\Phi(\mathbf{m})\) the data misfit associated with the model \(\mathbf{m}\), \(T\) the chain temperature, and the prime superscript indicates that the model has been perturbed.
- Parameters:
old_state (bayesbay.State) – the state of the Bayesian inference prior to the model perturbation
new_state (bayesbay.State) – the state of the Bayesian inference after the model perturbation
temperature (Number) – the temperature associated with current chain and iteration
- Returns:
log likelihood ratio
- Return type:
Number