From ffce3d2eabc7e7eaead9986df0bd878f7601b93e Mon Sep 17 00:00:00 2001 From: Karin Dorman Date: Tue, 14 May 2024 20:27:29 -0500 Subject: [PATCH] Updating R code to return as best.ari, the ari observed at the optimum; max.ari contains the best ari observed. --- R/kmodes.R | 4 +++- src/kmodes_r.c | 9 ++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/R/kmodes.R b/R/kmodes.R index 524f26f..5d62fe7 100644 --- a/R/kmodes.R +++ b/R/kmodes.R @@ -62,7 +62,9 @@ #' \item average.criterion - The average objective function achieved across #' multiple initializations. #' \item number.initializations - The number of initializations performed. -#' \item best.ari - If true clusters provided, then the best achieved ARI, +#' \item best.ari - If true clusters provided, then the achieved ARI, from +#' the best solution, as measured by the objective function. +#' \item max.ari - If true clusters provided, then the maximum achieved ARI, #' perhaps not from the best solution, as measured by the objective function. #' \item average.ari - If true clusters provided, then the average ARI achieved #' across all initializations. diff --git a/src/kmodes_r.c b/src/kmodes_r.c index e3acbda..25096bf 100644 --- a/src/kmodes_r.c +++ b/src/kmodes_r.c @@ -19,6 +19,7 @@ enum RETURN_SLOT { AVERAGE_CRITERION_SLOT, NUMBER_INITIALIZATIONS_SLOT, BEST_RAND_SLOT, + MAX_RAND_SLOT, AVERAGE_RAND_SLOT, NUMBER_SLOTS, }; @@ -28,7 +29,7 @@ char const *slot_names[NUMBER_SLOTS] = { "cluster.sizes", "partition", "modes", "average.criterion", "number.initializations", - "best.ari", "average.ari" + "best.ari", "max.ari", "average.ari" }; int load_data(data *dat, options *opt, SEXP data_r, int *); @@ -281,12 +282,16 @@ SEXP run_kmodes_r( SEXP data_r, ScalarInteger(dat->n_init)); if (opt->simulate || opt->true_cluster) { SET_VECTOR_ELT(return_list, BEST_RAND_SLOT, + ScalarReal(dat->best_rand_at_opt)); + SET_VECTOR_ELT(return_list, MAX_RAND_SLOT, ScalarReal(dat->best_rand)); SET_VECTOR_ELT(return_list, AVERAGE_RAND_SLOT, ScalarReal(dat->avg_ar)); } else { SET_VECTOR_ELT(return_list, BEST_RAND_SLOT, ScalarReal(NA_REAL)); + SET_VECTOR_ELT(return_list, MAX_RAND_SLOT, + ScalarReal(NA_REAL)); SET_VECTOR_ELT(return_list, AVERAGE_RAND_SLOT, ScalarReal(NA_REAL)); } @@ -297,6 +302,8 @@ SEXP run_kmodes_r( SEXP data_r, ScalarInteger(NA_INTEGER)); SET_VECTOR_ELT(return_list, BEST_RAND_SLOT, ScalarReal(NA_REAL)); + SET_VECTOR_ELT(return_list, MAX_RAND_SLOT, + ScalarReal(NA_REAL)); SET_VECTOR_ELT(return_list, AVERAGE_RAND_SLOT, ScalarReal(NA_REAL)); }