Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue in Optimal_Clusters_GMM #40

Closed
carversh opened this issue Dec 7, 2022 · 4 comments
Closed

Issue in Optimal_Clusters_GMM #40

carversh opened this issue Dec 7, 2022 · 4 comments

Comments

@carversh
Copy link

carversh commented Dec 7, 2022

Hi, I'm not sure exactly what the error is, however, I am using the Optimal_Clusters_GMM function and returning an error. When I do the same thing with the GMM function, everything works fine, however, I run into issues then optimizing.

Here is the function I'm using:
Optimal_Clusters_GMM(dat, max_clusters=10, criterion = 'BIC', dist_mode = 'maha_dist', seed_mode = 'random_subset', km_iter = 10, em_iter=10, var_floor = 1e-10, plot_data=T, verbose=T)

And here is the error message (note that all 10 iteration are completed:

ERROR while rich displaying an object: Error: $ operator is invalid for atomic vectors

Traceback:

1. tryCatch(withCallingHandlers({
 .     if (!mime %in% names(repr::mime2repr)) 
 .         stop("No repr_* for mimetype ", mime, " in repr::mime2repr")
 .     rpr <- repr::mime2repr[[mime]](obj)
 .     if (is.null(rpr)) 
 .         return(NULL)
 .     prepare_content(is.raw(rpr), rpr)
 . }, error = error_handler), error = outer_handler)
2. tryCatchList(expr, classes, parentenv, handlers)
3. tryCatchOne(expr, names, parentenv, handlers[[1L]])
4. doTryCatch(return(expr), name, parentenv, handler)
5. withCallingHandlers({
 .     if (!mime %in% names(repr::mime2repr)) 
 .         stop("No repr_* for mimetype ", mime, " in repr::mime2repr")
 .     rpr <- repr::mime2repr[[mime]](obj)
 .     if (is.null(rpr)) 
 .         return(NULL)
 .     prepare_content(is.raw(rpr), rpr)
 . }, error = error_handler)
6. repr::mime2repr[[mime]](obj)
7. repr_text.default(obj)
8. paste(capture.output(print(obj)), collapse = "\n")
9. capture.output(print(obj))
10. withVisible(...elt(i))
11. print(obj)
12. print.GMMCluster(obj)
13. cat("GMM Cluster\n", "Call:", deparse(x$call), "\n", "Data cols:", 
  .     ncol(x$centroids), "\n", "Centroids:", nrow(x$centroids), 
  .     "\n")
14. deparse(x$call)
@mlampros
Copy link
Owner

mlampros commented Dec 8, 2022

@carversh can you add a reproducible example? What is 'dat' that you use in 'Optimal_Clusters_GMM'?

@mlampros
Copy link
Owner

mlampros commented Dec 10, 2022

I can reproduce the error using the documentation example data and your parameter setting,

require(ClusterR)

data(dietary_survey_IBS)
dat = dietary_survey_IBS[, -ncol(dietary_survey_IBS)]
dat = center_scale(dat)

opt_gmm = Optimal_Clusters_GMM(data = dat, 
                               max_clusters = 10, 
                               criterion = "AIC",
                               dist_mode = 'maha_dist', 
                               seed_mode = 'random_subset',
                               km_iter = 10,
                               em_iter = 10,
                               var_floor = 1e-10, 
                               plot_data = TRUE,
                               verbose = TRUE)

opt_gmm
# Error: $ operator is invalid for atomic vectors

It seems that the error comes from the the following line

class(res) = c("GMMCluster", 'Gaussian Mixture Models')

if I modify this line to

class(res) =  'Gaussian Mixture Models'

then the function returns as expected. From what I understand it is related to "GMMCluster". The later appears in "predict.GMMCluster" and "print.GMMCluster"

@vspinu do you happen to know why this error appears and is related to "GMMCluster"? You've added this additional class in #24

Can we simply omit it here and keep only 'Gaussian Mixture Models'?

@vspinu
Copy link
Contributor

vspinu commented Dec 12, 2022

I have added "GMMCluster" to all those models which where classed with the old 'Gaussian Mixture Models' and I didn't realize that this particular instance does not return a model. The documentation states that the returned value is a vector with either the AIC or BIC for each iteration. So it's not a model and that class should not even be there.

Let me PR to fix that.

mlampros added a commit that referenced this issue Dec 12, 2022
[Fix #40] Don't class the output of Optimal_Clusters_GMM
@carversh
Copy link
Author

Thanks so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants