% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/update_M.R
\name{update_M}
\alias{update_M}
\title{Update Cluster Embeddings in Matrix M}
\usage{
update_M(data_train)
}
\arguments{
\item{data_train}{A list containing the training data. The list must include the following components:
\itemize{
\item \code{M}: A matrix where each column corresponds to a cluster's embedding vector.
\item \code{n_cat}: An integer representing the number of clusters (or categories).
\item \code{rep}: A matrix of representations (embeddings) for the training data.
\item \code{C}: An integer vector indicating the cluster assignment for each training sample.
}}
}
\value{
The function updates the \code{M} matrix in-place within the \code{data_train} list, reflecting the new average embeddings for each cluster.
}
\description{
This function updates the matrix \code{M}, which contains cluster embeddings, based on the current cluster assignments and representations in the training data.
}
\details{
The \code{update_M} function works as follows:
\enumerate{
\item It first checks that the number of columns in the \code{M} matrix matches the number of clusters (\code{n_cat}). If not, an error is thrown.
\item It then initializes a list of lists, \code{dict_c_embedding}, where each sublist will hold the embeddings for samples belonging to a specific cluster.
\item The function iterates over all samples, adding their representations to the corresponding cluster sublist in \code{dict_c_embedding}.
\item For each cluster, the function computes the mean of the embeddings across all samples assigned to that cluster.
\item The computed mean embedding is then used to update the corresponding column in the \code{M} matrix.
}
}
\examples{
\donttest{
## Called internally by DICEr() to refresh cluster centroids each iteration.
## Requires a data_train list with rep, C, n_cat, and M fields; see ?DICEr.
}
}
