bamojax.marginal_likelihoods.bridge_sampling
¶
apply_bijectors(samples, bijectors)
¶
Transform variables from the real line.
Source code in bamojax/marginal_likelihoods/bridge_sampling.py
13 14 15 16 17 |
|
apply_inverse_bijectors(samples, bijectors)
¶
Transform variables to the real line.
Source code in bamojax/marginal_likelihoods/bridge_sampling.py
20 21 22 23 24 |
|
get_jacobians(samples, bijectors)
¶
Get the Jacobian for the change-of-variables due to the bijector
Source code in bamojax/marginal_likelihoods/bridge_sampling.py
26 27 28 29 30 31 32 33 34 35 36 37 |
|
get_proposal_distribution(transformed_samples)
¶
Create a proposal distribution on the real line.
Also returns an unravel function to transform proposals back to the dicts Bamojax uses for sampling.
Source code in bamojax/marginal_likelihoods/bridge_sampling.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
|
sample_from_proposal_distribution(key, prop_dist, unravel_fn, N)
¶
Sample from the proposal distribution and unravel back into a dictionary.
Source code in bamojax/marginal_likelihoods/bridge_sampling.py
58 59 60 61 62 63 64 65 |
|
proposal_distribution_logprob(prop_dist, samples)
¶
Flatten a sample dictionary and compute the log probability according to the proposal distribution.
Source code in bamojax/marginal_likelihoods/bridge_sampling.py
68 69 70 71 72 73 74 |
|
logposterior_proposals(model, bijectors, samples)
¶
Compute the log joint probability for a sample, and adjusting for the Jacobian
p(D \mid \theta)p(\theta)|J(f(\theta)|
Source code in bamojax/marginal_likelihoods/bridge_sampling.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
|
get_importance_weights(model, bijectors, prop_dist, samples)
¶
Compute the importance weight reflecting the relative probability under the posterior vs the proposal distribution.
Source code in bamojax/marginal_likelihoods/bridge_sampling.py
93 94 95 96 97 |
|
bridge_sampling(key, model, posterior_samples, bijectors, proposal_type='gaussian', N2=1000, max_iter=20, tol=1e-06)
¶
Run the warp-II bridge sampling algorithm, using the optimal bridge function by Meng & Wong (1996).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
- model
|
The bamojax model to get the marginal likelihood for. |
required | |
- posterior_samples
|
Posterior samples of the model, obtained via any suitable way. |
required | |
- bijectors
|
A dictionary of transformations to more closely align the proposal distribution with |
required | |
- proposal_type
|
Indicates the kind of proposals to use. For now, only Gaussians are supported, |
required | |
- N2
|
The number of draws from the proposal distribution. |
required | |
- max_iter
|
The maximum number of bridge sampling iterations. Not often used. |
required | |
- tol
|
The convergence criterion. |
required |
Returns:
- The log marginal likelihood of `model`
- The number of iterations of the bridge sampler (typically small)
References:
- Meng & Wong, 1996, Simulating ratios of normalizing constants via a simple identity: a theoretical
exploration. Statistica Sinica, 831--860.
- Gronau et al., 2017, A tutorial on bridge sampling, Journal of Mathematical Psychology 81, 80--97.
Source code in bamojax/marginal_likelihoods/bridge_sampling.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
|