Skip to content

Commit

Permalink
Change cluster assignment.
Browse files Browse the repository at this point in the history
  • Loading branch information
sjmgarnier committed Jul 13, 2024
1 parent 0190a52 commit 093ef6a
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions R/gravitree.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,23 @@ gravitree <- function(x, m, k = NULL, sample = 1, na_rm = FALSE) {
ix <- cluster == i
.wcov(xx[ix, , drop = FALSE], mm[ix])
})
tmp <- rep(NA, nr)
tmp[ix] <- cluster
tmp[notix] <- Rfast::rowMins(sapply(1:k, function(i) {
.Mahalanobis(x[notix, , drop = FALSE], centers[[i]]$center, centers[[i]]$cov)
}))
cluster <- tmp
# tmp <- rep(NA, nr)
# tmp[ix] <- cluster
# tmp[notix] <- Rfast::rowMins(sapply(1:k, function(i) {
# .Mahalanobis(x[notix, , drop = FALSE], centers[[i]]$center, centers[[i]]$cov)
# }))
# cluster <- tmp
} else {
centers <- lapply(1:k, function(i) {
ix <- cluster == i
.wcov(x[ix, , drop = FALSE], m[ix])
})
}

cluster <- Rfast::rowMins(sapply(1:k, function(i) {
.Mahalanobis(x, centers[[i]]$center, centers[[i]]$cov)
}))

list(
tree = tree,
cluster = cluster,
Expand Down

0 comments on commit 093ef6a

Please sign in to comment.