From d36fc1766076288bd8842e4900d689d1563ddf6f Mon Sep 17 00:00:00 2001 From: Lampros Mouselimis Date: Sun, 16 Jun 2024 19:33:46 +0300 Subject: [PATCH] fixes the issue in #54 --- DESCRIPTION | 6 +-- NEWS.md | 5 ++ src/export_inst_folder_headers.cpp | 79 ++++++++++++++++++++++++------ 3 files changed, 72 insertions(+), 18 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 730abfd..d799479 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: ClusterR Type: Package Title: Gaussian Mixture Models, K-Means, Mini-Batch-Kmeans, K-Medoids and Affinity Propagation Clustering -Version: 1.3.2 -Date: 2023-12-04 +Version: 1.3.3 +Date: 2024-06-16 Authors@R: c( person(given = "Lampros", family = "Mouselimis", email = "mouselimislampros@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "https://orcid.org/0000-0002-8024-1546")), person(given = "Conrad", family = "Sanderson", role = "cph", comment = "Author of the C++ Armadillo library"), person(given = "Ryan", family = "Curtin", role = "cph", comment = "Author of the C++ Armadillo library"), person(given = "Siddharth", family = "Agrawal", role = "cph", comment = "Author of the C code of the Mini-Batch-Kmeans algorithm (https://github.com/siddharth-agrawal/Mini-Batch-K-Means)"), person(given = "Brendan", family = "Frey", email = "frey@psi.toronto.edu", role = "cph", comment = "Author of the matlab code of the Affinity propagation algorithm (for commercial use please contact the author of the matlab code)"), person(given = "Delbert", family = "Dueck", role = "cph", comment = "Author of the matlab code of the Affinity propagation algorithm"), person(given = "Vitalie", family = "Spinu", email = "spinuvit@gmail.com", role = "ctb", comment = c(Github = "Github Contributor")) ) Maintainer: Lampros Mouselimis BugReports: https://github.com/mlampros/ClusterR/issues @@ -32,4 +32,4 @@ Suggests: knitr, rmarkdown VignetteBuilder: knitr -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.0 diff --git a/NEWS.md b/NEWS.md index 5725c53..cd3c872 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,9 @@ +## Cluster 1.3.3 + +* I fixed an issue related to the *R_NilValue* of the *'KMEANS_rcpp()'* Rcpp function in the *src/export_inst_folder_headers.cpp* file. I mistakenly used as input the *R_NilValue* whereas I should have used the *CENTROIDS* argument (see issue: https://github.com/mlampros/ClusterR/issues/54) + + ## Cluster 1.3.2 * I've fixed the CRAN *warning: format specifies type 'double' but the argument has type 'int''* in the following files & lines by replacing the `%g` expression with `%d`: diff --git a/src/export_inst_folder_headers.cpp b/src/export_inst_folder_headers.cpp index 7a78d6d..b9c1cea 100644 --- a/src/export_inst_folder_headers.cpp +++ b/src/export_inst_folder_headers.cpp @@ -63,13 +63,32 @@ arma::mat SCALE(arma::mat data, bool mean_center = true, bool sd_scale = true) { // // [[Rcpp::export]] -Rcpp::List KMEANS_rcpp(arma::mat& data, int clusters, int num_init = 1, int max_iters = 200, std::string initializer = "kmeans++", bool fuzzy = false, bool verbose = false, - - Rcpp::Nullable CENTROIDS = R_NilValue, double tol = 1e-4, double eps = 1.0e-6, double tol_optimal_init = 0.5, int seed = 1) { - +Rcpp::List KMEANS_rcpp(arma::mat& data, + int clusters, + int num_init = 1, + int max_iters = 200, + std::string initializer = "kmeans++", + bool fuzzy = false, + bool verbose = false, + Rcpp::Nullable CENTROIDS = R_NilValue, + double tol = 1e-4, + double eps = 1.0e-6, + double tol_optimal_init = 0.5, + int seed = 1) { ClustHeader CRH; - return CRH.KMEANS_rcpp(data, clusters, num_init, max_iters, initializer, fuzzy, verbose, R_NilValue, tol, eps, tol_optimal_init, seed); + return CRH.KMEANS_rcpp(data, + clusters, + num_init, + max_iters, + initializer, + fuzzy, + verbose, + CENTROIDS, + tol, + eps, + tol_optimal_init, + seed); } @@ -81,13 +100,22 @@ Rcpp::List KMEANS_rcpp(arma::mat& data, int clusters, int num_init = 1, int max_ // // [[Rcpp::export]] -arma::mat KMEANS_arma(arma::mat& data, int clusters, int n_iter, bool verbose, std::string seed_mode = "random_subset", - - Rcpp::Nullable CENTROIDS = R_NilValue, int seed = 1) { - +arma::mat KMEANS_arma(arma::mat& data, + int clusters, + int n_iter, + bool verbose, + std::string seed_mode = "random_subset", + Rcpp::Nullable CENTROIDS = R_NilValue, + int seed = 1) { ClustHeader CRH; - return CRH.KMEANS_arma(data, clusters, n_iter, verbose, seed_mode, CENTROIDS, seed); + return CRH.KMEANS_arma(data, + clusters, + n_iter, + verbose, + seed_mode, + CENTROIDS, + seed); } @@ -159,13 +187,34 @@ Rcpp::List silhouette_clusters(arma::mat& data, arma::vec CLUSTER) { // // [[Rcpp::export]] -Rcpp::List mini_batch_kmeans(arma::mat& data, int clusters, int batch_size, int max_iters, int num_init = 1, double init_fraction = 1.0, std::string initializer = "kmeans++", - - int early_stop_iter = 10, bool verbose = false, Rcpp::Nullable CENTROIDS = R_NilValue, double tol = 1e-4, double tol_optimal_init = 0.5, int seed = 1) { - +Rcpp::List mini_batch_kmeans(arma::mat& data, + int clusters, + int batch_size, + int max_iters, + int num_init = 1, + double init_fraction = 1.0, + std::string initializer = "kmeans++", + int early_stop_iter = 10, + bool verbose = false, + Rcpp::Nullable CENTROIDS = R_NilValue, + double tol = 1e-4, + double tol_optimal_init = 0.5, + int seed = 1) { ClustHeader CRH; - return CRH.mini_batch_kmeans(data, clusters, batch_size, max_iters, num_init, init_fraction, initializer, early_stop_iter, verbose, CENTROIDS, tol, tol_optimal_init, seed); + return CRH.mini_batch_kmeans(data, + clusters, + batch_size, + max_iters, + num_init, + init_fraction, + initializer, + early_stop_iter, + verbose, + CENTROIDS, + tol, + tol_optimal_init, + seed); }