Skip to content

Commit

Permalink
Support nEig > nL
Browse files Browse the repository at this point in the history
  • Loading branch information
ms609 committed Aug 14, 2024
1 parent 0fac77b commit 908cd46
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: TreeDist
Type: Package
Title: Calculate and Map Distances Between Phylogenetic Trees
Version: 2.8.0
Version: 2.8.0.9000
Authors@R: c(person("Martin R.", "Smith",
email = "martin.smith@durham.ac.uk",
role = c("aut", "cre", "cph", "prg"),
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# TreeDist 2.8.0.9000 (development)

- `SpectralEigens()` survives values of nEig larger than the input

# TreeDist 2.8.0 (2024-07-25)

- `Islands()` allows the identification of islands of trees.
Expand Down
10 changes: 8 additions & 2 deletions R/spectral_clustering.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,14 @@ SpectralEigens <- function(D, nn = 10L, nEig = 2L) {
L <- GraphLaplacian(W) # 2. compute graph laplacian
ei <- eigen(L, symmetric = TRUE) # 3. Compute the eigenvectors and values of L

# Return the eigenvectors of the n_eig smallest eigenvalues:
ei[["vectors"]][, nrow(L) - rev(seq_len(nEig))]
nL <- dim(L)[[1]]

if (nL > nEig) {
# Return the eigenvectors of the n_eig smallest eigenvalues:
ei[["vectors"]][, nL - rev(seq_len(nEig))]
} else {
ei[["vectors"]]
}
}

#' @export
Expand Down

0 comments on commit 908cd46

Please sign in to comment.