1919# '
2020# ' sse_within(kmeans_fit)
2121# ' @export
22- sse_within <- function (object , new_data = NULL , dist_fun = Rfast :: dista ) {
22+ sse_within <- function (
23+ object ,
24+ new_data = NULL ,
25+ dist_fun = function (x , y ) {
26+ philentropy :: dist_many_many(x , y , method = " euclidean" )
27+ }
28+ ) {
2329 if (inherits(object , " cluster_spec" )) {
2430 rlang :: abort(
2531 paste(
@@ -43,7 +49,12 @@ sse_within <- function(object, new_data = NULL, dist_fun = Rfast::dista) {
4349 n_members = summ $ n_members
4450 )
4551 } else {
46- dist_to_centroids <- dist_fun(summ $ centroids , new_data )
52+ suppressMessages(
53+ dist_to_centroids <- dist_fun(
54+ as.matrix(summ $ centroids ),
55+ as.matrix(new_data )
56+ )
57+ )
4758
4859 res <- dist_to_centroids %> %
4960 tibble :: as_tibble(.name_repair = " minimal" ) %> %
@@ -121,7 +132,9 @@ sse_within_total.cluster_fit <- function(
121132 ...
122133) {
123134 if (is.null(dist_fun )) {
124- dist_fun <- Rfast :: dista
135+ dist_fun <- function (x , y ) {
136+ philentropy :: dist_many_many(x , y , method = " euclidean" )
137+ }
125138 }
126139
127140 res <- sse_within_total_impl(object , new_data , dist_fun , ... )
@@ -142,7 +155,9 @@ sse_within_total.workflow <- sse_within_total.cluster_fit
142155sse_within_total_vec <- function (
143156 object ,
144157 new_data = NULL ,
145- dist_fun = Rfast :: dista ,
158+ dist_fun = function (x , y ) {
159+ philentropy :: dist_many_many(x , y , method = " euclidean" )
160+ },
146161 ...
147162) {
148163 sse_within_total_impl(object , new_data , dist_fun , ... )
@@ -151,7 +166,9 @@ sse_within_total_vec <- function(
151166sse_within_total_impl <- function (
152167 object ,
153168 new_data = NULL ,
154- dist_fun = Rfast :: dista ,
169+ dist_fun = function (x , y ) {
170+ philentropy :: dist_many_many(x , y , method = " euclidean" )
171+ },
155172 ...
156173) {
157174 sum(sse_within(object , new_data , dist_fun , ... )$ wss , na.rm = TRUE )
@@ -208,7 +225,9 @@ sse_total.cluster_fit <- function(
208225 ...
209226) {
210227 if (is.null(dist_fun )) {
211- dist_fun <- Rfast :: dista
228+ dist_fun <- function (x , y ) {
229+ philentropy :: dist_many_many(x , y , method = " euclidean" )
230+ }
212231 }
213232
214233 res <- sse_total_impl(object , new_data , dist_fun , ... )
@@ -229,7 +248,9 @@ sse_total.workflow <- sse_total.cluster_fit
229248sse_total_vec <- function (
230249 object ,
231250 new_data = NULL ,
232- dist_fun = Rfast :: dista ,
251+ dist_fun = function (x , y ) {
252+ philentropy :: dist_many_many(x , y , method = " euclidean" )
253+ },
233254 ...
234255) {
235256 sse_total_impl(object , new_data , dist_fun , ... )
@@ -238,7 +259,9 @@ sse_total_vec <- function(
238259sse_total_impl <- function (
239260 object ,
240261 new_data = NULL ,
241- dist_fun = Rfast :: dista ,
262+ dist_fun = function (x , y ) {
263+ philentropy :: dist_many_many(x , y , method = " euclidean" )
264+ },
242265 ...
243266) {
244267 # Preprocess data before computing distances if appropriate
@@ -253,7 +276,10 @@ sse_total_impl <- function(
253276 } else {
254277 overall_mean <- colSums(summ $ centroids * summ $ n_members ) /
255278 sum(summ $ n_members )
256- tot <- dist_fun(t(as.matrix(overall_mean )), new_data )^ 2 %> % sum()
279+ suppressMessages(
280+ tot <- dist_fun(t(as.matrix(overall_mean )), as.matrix(new_data ))^ 2 %> %
281+ sum()
282+ )
257283 }
258284
259285 return (tot )
@@ -310,7 +336,9 @@ sse_ratio.cluster_fit <- function(
310336 ...
311337) {
312338 if (is.null(dist_fun )) {
313- dist_fun <- Rfast :: dista
339+ dist_fun <- function (x , y ) {
340+ philentropy :: dist_many_many(x , y , method = " euclidean" )
341+ }
314342 }
315343 res <- sse_ratio_impl(object , new_data , dist_fun , ... )
316344
@@ -330,7 +358,9 @@ sse_ratio.workflow <- sse_ratio.cluster_fit
330358sse_ratio_vec <- function (
331359 object ,
332360 new_data = NULL ,
333- dist_fun = Rfast :: dista ,
361+ dist_fun = function (x , y ) {
362+ philentropy :: dist_many_many(x , y , method = " euclidean" )
363+ },
334364 ...
335365) {
336366 sse_ratio_impl(object , new_data , dist_fun , ... )
@@ -339,7 +369,9 @@ sse_ratio_vec <- function(
339369sse_ratio_impl <- function (
340370 object ,
341371 new_data = NULL ,
342- dist_fun = Rfast :: dista ,
372+ dist_fun = function (x , y ) {
373+ philentropy :: dist_many_many(x , y , method = " euclidean" )
374+ },
343375 ...
344376) {
345377 sse_within_total_vec(object , new_data , dist_fun ) /
0 commit comments