Skip to content

Commit 8a9c708

Browse files
committed
Some cleaning
1 parent a1b7911 commit 8a9c708

2 files changed

Lines changed: 12 additions & 75 deletions

File tree

.github/workflows/check-standard.yaml

Lines changed: 0 additions & 58 deletions
This file was deleted.

R/fdakmeans.R

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -195,25 +195,28 @@ fdakmeans <- function(
195195
centroid_name <- centroid_type_args$name
196196
centroid_extra <- centroid_type_args$extra
197197

198-
if (centroid_name != "medoid" && parallel_method == 1L)
198+
if (centroid_name != "medoid" && parallel_method == 1L) {
199199
cli::cli_abort(
200200
"Parallelization on the distance calculation loop is only available for computing medoids."
201201
)
202+
}
202203

203204
callargs$centroid_type <- centroid_name
204205
callargs$centroid_extra <- centroid_extra
205206

206-
if (warping_class == "none" && cluster_on_phase)
207+
if (warping_class == "none" && cluster_on_phase) {
207208
cli::cli_abort(
208209
"It makes no sense to cluster based on phase variability if no alignment is performed."
209210
)
211+
}
210212

211213
# Handle seeds
212214
if (is.null(seeds)) {
213-
if (use_verbose)
215+
if (use_verbose) {
214216
cli::cli_alert_info(
215217
"Computing initial centroids using {seeding_strategy} strategy..."
216218
)
219+
}
217220
if (seeding_strategy == "hclust") {
218221
out <- fdahclust(
219222
x = x,
@@ -340,10 +343,11 @@ fdakmeans <- function(
340343
}
341344
} else {
342345
n_centroids <- length(seeds)
343-
if (n_centroids != n_clusters && n_centroids != 1L)
346+
if (n_centroids != n_clusters && n_centroids != 1L) {
344347
cli::cli_abort(
345348
"The number of initial centroid indices provided by the {.arg seeds} argument should be either 1 or {n_clusters}."
346349
)
350+
}
347351
if (n_centroids == 1L && n_clusters > 1L) {
348352
D <- fdadist(
349353
x = x,
@@ -368,26 +372,16 @@ fdakmeans <- function(
368372
seeds <- seeds - 1
369373

370374
if (transformation == "srvf" && warping_class %in% c("none", "bpd")) {
371-
if (!(centroid_name %in% c("mean", "medoid")))
375+
if (!(centroid_name %in% c("mean", "medoid"))) {
372376
cli::cli_abort(
373377
"Only mean and medoid centroids are available for SRVFs using the {.fn fdasrvf::kmeans_align} function."
374378
)
379+
}
375380

376381
yperm <- aperm(y, c(2, 3, 1))
377382
common_grid <- x[1, ]
378383

379384
# AST: nonempty should be 1 but badly handled in fdasrvf
380-
save(
381-
seeds,
382-
common_grid,
383-
yperm,
384-
n_clusters,
385-
centroid_type,
386-
maximum_number_of_iterations,
387-
use_verbose,
388-
warping_class,
389-
file = "~/Downloads/fdasrvf_kmeans_align.RData"
390-
)
391385
res <- fdasrvf::kmeans_align(
392386
f = yperm,
393387
time = common_grid,
@@ -434,9 +428,10 @@ fdakmeans <- function(
434428
# clustering is still performed on amplitude for SRVF, only distances to
435429
# centers are transformed in the output
436430
q0 <- res$q0
437-
if (length(dim(q0)) == 2L)
431+
if (length(dim(q0)) == 2L) {
438432
# This should be done in fdasrvf package
439433
dim(q0) <- c(1, dim(q0))
434+
}
440435
amplitude_variation <- sum(res$distances_to_center^2)
441436
total_variation <- sum(sapply(1:N, \(n) {
442437
sum(sapply(1:L, \(l) {

0 commit comments

Comments
 (0)