Skip to content

Commit e53c258

Browse files
committed
Rfast::Dist -> philentropy::distance
1 parent c9edff9 commit e53c258

File tree

9 files changed

+26
-16
lines changed

9 files changed

+26
-16
lines changed

R/hier_clust.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,11 @@ translate_tidyclust.hier_clust <- function(x, engine = x$engine, ...) {
193193
num_clusters = NULL,
194194
cut_height = NULL,
195195
linkage_method = NULL,
196-
dist_fun = Rfast::Dist
196+
dist_fun = philentropy::distance
197197
) {
198-
dmat <- dist_fun(x)
198+
suppressMessages(
199+
dmat <- dist_fun(x)
200+
)
199201
res <- stats::hclust(stats::as.dist(dmat), method = linkage_method)
200202
attr(res, "num_clusters") <- num_clusters
201203
attr(res, "cut_height") <- cut_height

R/metric-helpers.R

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ prep_data_dist <- function(
1212
object,
1313
new_data = NULL,
1414
dists = NULL,
15-
dist_fun = Rfast::Dist
15+
dist_fun = philentropy::distance
1616
) {
1717
# Sihouettes requires a distance matrix
1818
if (is.null(new_data) && is.null(dists)) {
@@ -46,7 +46,9 @@ prep_data_dist <- function(
4646

4747
# Calculate distances including optionally supplied params
4848
if (is.null(dists)) {
49-
dists <- dist_fun(new_data)
49+
suppressMessages(
50+
dists <- dist_fun(new_data)
51+
)
5052
}
5153

5254
return(
@@ -69,5 +71,7 @@ get_centroid_dists <- function(new_data, centroids, dist_fun = Rfast::dista) {
6971
rlang::abort("Centroids must have same columns as data.")
7072
}
7173

72-
dist_fun(centroids, new_data)
74+
suppressMessages(
75+
dist_fun(centroids, new_data)
76+
)
7377
}

R/metric-silhouette.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ silhouette <- function(
2727
object,
2828
new_data = NULL,
2929
dists = NULL,
30-
dist_fun = Rfast::Dist
30+
dist_fun = philentropy::distance
3131
) {
3232
if (inherits(object, "cluster_spec")) {
3333
rlang::abort(
@@ -126,7 +126,7 @@ silhouette_avg.cluster_fit <- function(
126126
...
127127
) {
128128
if (is.null(dist_fun)) {
129-
dist_fun <- Rfast::Dist
129+
dist_fun <- philentropy::distance
130130
}
131131

132132
res <- silhouette_avg_impl(object, new_data, dists, dist_fun, ...)
@@ -148,7 +148,7 @@ silhouette_avg_vec <- function(
148148
object,
149149
new_data = NULL,
150150
dists = NULL,
151-
dist_fun = Rfast::Dist,
151+
dist_fun = philentropy::distance,
152152
...
153153
) {
154154
silhouette_avg_impl(object, new_data, dists, dist_fun, ...)
@@ -158,7 +158,7 @@ silhouette_avg_impl <- function(
158158
object,
159159
new_data = NULL,
160160
dists = NULL,
161-
dist_fun = Rfast::Dist,
161+
dist_fun = philentropy::distance,
162162
...
163163
) {
164164
mean(silhouette(object, new_data, dists, dist_fun, ...)$sil_width)

R/metric-sse.R

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ sse_within <- function(object, new_data = NULL, dist_fun = Rfast::dista) {
4343
n_members = summ$n_members
4444
)
4545
} else {
46-
dist_to_centroids <- dist_fun(summ$centroids, new_data)
46+
suppressMessages(
47+
dist_to_centroids <- dist_fun(summ$centroids, new_data)
48+
)
4749

4850
res <- dist_to_centroids %>%
4951
tibble::as_tibble(.name_repair = "minimal") %>%
@@ -253,7 +255,9 @@ sse_total_impl <- function(
253255
} else {
254256
overall_mean <- colSums(summ$centroids * summ$n_members) /
255257
sum(summ$n_members)
256-
tot <- dist_fun(t(as.matrix(overall_mean)), new_data)^2 %>% sum()
258+
suppressMessages(
259+
tot <- dist_fun(t(as.matrix(overall_mean)), new_data)^2 %>% sum()
260+
)
257261
}
258262

259263
return(tot)

man/dot-hier_clust_fit_stats.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/prep_data_dist.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/silhouette.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/silhouette_avg.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vignettes/articles/k_means.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ matrix (i.e., all pairwise distances between observations).
291291

292292
```{r}
293293
my_dist_1 <- function(x) {
294-
Rfast::Dist(x, method = "manhattan")
294+
philentropy::distance(x, method = "manhattan")
295295
}
296296
297297
my_dist_2 <- function(x, y) {

0 commit comments

Comments
 (0)