MCMC Moves¶
Reversible tree moves for Metropolis–Hastings sampling in tree space.
Each move returns (new_tree, log_hastings_ratio).
nni_move
¶
Nearest-neighbor interchange (NNI).
For a randomly chosen internal non-root node u, swaps one of
u's children with u's sibling across the edge connecting u
to its parent.
For a binary tree with n leaves there are always n-2 valid NNI edges
and 2 variants each, giving 2(n-2) moves regardless of topology. The
proposal is therefore symmetric and log_hastings_ratio = 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tree
|
HifukuTree
|
|
required |
taxon_table
|
TaxonTable
|
|
required |
rng
|
Generator
|
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
new_tree |
HifukuTree
|
|
log_hastings_ratio |
float
|
Always 0.0; |
Notes
- Minh et al. (2020) : doNNI, NNIMove struct.
Source code in src/hifuku/moves.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | |
spr_move
¶
Subtree prune-regraft (SPR).
Detaches a random subtree and reattaches it at a random edge in the remaining tree, splitting that edge evenly.
The proposal: (1) pick a prune edge uniformly from n_valid_prune(T)
valid edges (pruned subtree has ≤ n-2 leaves); (2) pick a graft edge
uniformly from the remaining tree. The graft count
n_graft = 2*(n - leaf_count(prune)) - 2 cancels in the Hastings ratio:
.. code-block:: text
log_hastings = log(n_valid_prune(T)) - log(n_valid_prune(T'))
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tree
|
HifukuTree
|
|
required |
taxon_table
|
TaxonTable
|
|
required |
rng
|
Generator
|
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
new_tree |
HifukuTree
|
|
log_hastings_ratio |
float
|
Exact Hastings ratio as above; |
Notes
- Minh et al. (2020) : SPR framework.
Source code in src/hifuku/moves.py
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | |
branch_scale_move
¶
branch_scale_move(tree: HifukuTree, taxon_table: TaxonTable, rng: Generator, width: float = 0.5) -> tuple[HifukuTree, float]
Global branch-length scaling.
Multiplies all finite edge lengths by exp(U),
U ~ Uniform(-width/2, width/2). The Jacobian of the transformation
t → t·exp(U) for each of n_branches independent branches gives
log_hastings_ratio = n_branches · U.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tree
|
HifukuTree
|
|
required |
taxon_table
|
TaxonTable
|
|
required |
rng
|
Generator
|
|
required |
width
|
float
|
Half-width of the uniform proposal window (default 0.5). |
0.5
|
Returns:
| Name | Type | Description |
|---|---|---|
new_tree |
HifukuTree
|
|
log_hastings_ratio |
float
|
|
Source code in src/hifuku/moves.py
branch_slide_move
¶
branch_slide_move(tree: HifukuTree, taxon_table: TaxonTable, rng: Generator, sigma: float = 0.05) -> tuple[HifukuTree, float]
Single-branch additive slide.
Adds a Normal(0, sigma) perturbation to one randomly chosen branch
length, reflecting at zero to maintain positivity. The folded-normal
proposal is symmetric, so log_hastings_ratio = 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tree
|
HifukuTree
|
|
required |
taxon_table
|
TaxonTable
|
|
required |
rng
|
Generator
|
|
required |
sigma
|
float
|
Standard deviation of the Normal proposal (default 0.05). |
0.05
|
Returns:
| Name | Type | Description |
|---|---|---|
new_tree |
HifukuTree
|
|
log_hastings_ratio |
float
|
Always 0.0. |
Notes
- Minh et al. (2020) : single-branch optimization context.
Source code in src/hifuku/moves.py
|