Skip to content

Potential fixes for #48 (assisted by copilot) - #66

Merged
mlampros merged 9 commits into
mlampros:masterfrom
FMKerckhof:master
Oct 16, 2025
Merged

Potential fixes for #48 (assisted by copilot)#66
mlampros merged 9 commits into
mlampros:masterfrom
FMKerckhof:master

Conversation

@FMKerckhof

Copy link
Copy Markdown
Contributor

Hi @mlampros - I got stuck in trying to resolve #48 so I prompted GitHub Copilot to come up with a fix for the predict function. I tested the proposed solution, and rebuilt the documentation. On the vignette example the code works smoothly, and I will validate this on a larger dataset as well.

The following code works:

library(ClusterR)

data("dietary_survey_IBS")

X <- center_scale(dietary_survey_IBS[, -ncol(dietary_survey_IBS)])

gmm <- GMM(X, gaussian_comps = 3, 
           full_covariance_matrices = TRUE,
           dist_mode = "eucl_dist",
           seed_mode = "random_subset", verbose=TRUE)
           
predictions <- predict_GMM(X, gmm$centroids, 
                           gmm$covariance_matrices, 
                           gmm$weights)

I have created this as a draft PR for now, until I can validate on a larger dataset

Copilot AI and others added 7 commits October 13, 2025 21:06
Co-authored-by: FMKerckhof <2431458+FMKerckhof@users.noreply.github.com>
Co-authored-by: FMKerckhof <2431458+FMKerckhof@users.noreply.github.com>
Co-authored-by: FMKerckhof <2431458+FMKerckhof@users.noreply.github.com>
Co-authored-by: FMKerckhof <2431458+FMKerckhof@users.noreply.github.com>
…dictions

Add support for full covariance matrix prediction in GMM
Copilot AI review requested due to automatic review settings October 14, 2025 19:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR extends the GMM prediction functionality to support full covariance matrices, addressing issue #48. The implementation adds a new C++ function to handle 3D covariance arrays while maintaining backward compatibility with diagonal covariance matrices.

Key changes:

  • Added new C++ function predict_MGausDPDF_full for handling full covariance matrices (3D arrays/cubes)
  • Enhanced predict_GMM function to automatically detect and handle both diagonal and full covariance matrices
  • Added comprehensive test coverage for the new functionality

Reviewed Changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
inst/include/ClusterRHeader.h Implements core C++ logic for full covariance matrix prediction
src/export_inst_folder_headers.cpp Exports the new C++ function to R
R/clustering_functions.R Updates predict_GMM to handle both diagonal and full covariance matrices
tests/testthat/test-gmm.R Adds comprehensive test coverage for full covariance functionality
src/RcppExports.cpp Auto-generated Rcpp exports for new function
src/init.c Registers new C function
R/RcppExports.R Auto-generated R wrapper for new function
man/predict_GMM.Rd Updates documentation to reflect new functionality
DESCRIPTION Version bump for RoxygenNote
.Rbuildignore Adds R project files to ignore list

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread inst/include/ClusterRHeader.h
@mlampros
mlampros self-requested a review October 15, 2025 17:34
@mlampros

Copy link
Copy Markdown
Owner

hi @FMKerckhof and thank you for the pull request. I took a look to the following files (mainly):

  • test-gmm.R
  • clustering_functions.R
  • ClusterRHeader.h

The important changes are in the ClusterRHeader.h inside the

for (unsigned int i = 0; i < WEIGHTS.n_elem; i++) {} loop where both the WEIGHTS vector and the COVARIANCE slices have the same length. Thus, for each i a different slice (matrix) is computed compared to what it happens when full_covariance_matrices is FALSE, where each time the same matrix is used in the computation.

We can proceed and merge your pull request but could you adjust the DESCRIPTION file and add your data as a "Github Contributor"? ( person(given = "", family = "", email = "@email.com", role = "ctb", comment = "Github Contributor"))

I also found a small bug in the normalization constant where the determinant is used, which I'll fix once this pull request is merged.

@FMKerckhof

Copy link
Copy Markdown
Contributor Author

@mlampros - done, feel free to merge 👍

@mlampros
mlampros marked this pull request as ready for review October 16, 2025 16:18
Copilot AI review requested due to automatic review settings October 16, 2025 16:18
@mlampros
mlampros merged commit 12ef013 into mlampros:master Oct 16, 2025
7 of 8 checks passed
@mlampros

Copy link
Copy Markdown
Owner

@FMKerckhof thank you.

@FMKerckhof
FMKerckhof removed the request for review from Copilot March 23, 2026 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] for GMM implement gmm_full covariance type?

4 participants