Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why does rSPR generate multifurcating trees sometimes? #181

Open
teng-gao opened this issue Dec 9, 2024 · 1 comment
Open

Why does rSPR generate multifurcating trees sometimes? #181

teng-gao opened this issue Dec 9, 2024 · 1 comment
Assignees
Labels

Comments

@teng-gao
Copy link

teng-gao commented Dec 9, 2024

Reproducible example:

run_chain = function(tree_init, max_iter = 100, propose_tree = TreeSearch::NNI, seed = 0) {
    set.seed(seed)
    trees = list()
    tree = tree_init
    for (i in 1:max_iter) {
        message(i)
        trees[[i]] = tree
        tree = propose_tree(tree)
    }
    class(trees) = 'multiPhylo'
    return(trees)
}

set.seed(0)
ntips = 4
tree_init = rtree(ntips)

trees = run_chain(tree_init, max_iter = 16, propose_tree = phangorn::rSPR)

output:

1

2

3

Error in oneOf4(tree, ind[2], ind[1], sample(c(1, 2), 1), sample(c(1, : trees must be binary
Traceback:

1. propose_tree(tree)
2. kSPR(trees, k = k)
3. oneOf4(tree, ind[2], ind[1], sample(c(1, 2), 1), sample(c(1, 
 .     2), 1), root)
4. stop("trees must be binary")
5. .handleSimpleError(function (cnd) 
 . {
 .     watcher$capture_plot_and_output()
 .     cnd <- sanitize_call(cnd)
 .     watcher$push(cnd)
 .     switch(on_error, continue = invokeRestart("eval_continue"), 
 .         stop = invokeRestart("eval_stop"), error = invokeRestart("eval_error", 
 .             cnd))
 . }, "trees must be binary", base::quote(oneOf4(tree, ind[2], ind[1], 
 .     sample(c(1, 2), 1), sample(c(1, 2), 1), root)))
@KlausVigo KlausVigo added the bug label Feb 4, 2025
@KlausVigo KlausVigo self-assigned this Feb 4, 2025
@KlausVigo
Copy link
Owner

Hi @teng-gao,
sorry it took me so long. I looked into the code and the function was originally intended for unrooted trees. So for now I will add a test for this and add a version for rooted trees later on.
Kind regards,
Klaus

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants