30void compute_wcss(
const Matrix_& data, Cluster_ ncenters,
const Float_* centers,
const Cluster_* clusters, Float_* wcss) {
31 auto nobs = data.num_observations();
32 size_t ndim = data.num_dimensions();
33 std::fill_n(wcss, ncenters, 0);
35 auto work = data.new_extractor(0, nobs);
36 for (Index<Matrix_> obs = 0; obs < nobs; ++obs) {
37 auto curdata = work->get_observation();
38 auto cen = clusters[obs];
39 auto curcenter = centers +
static_cast<size_t>(cen) * ndim;
41 Float_& curwcss = wcss[cen];
42 for (
size_t d = 0; d < ndim; ++d) {
43 Float_ delta =
static_cast<Float_
>(curdata[d]) - curcenter[d];
44 curwcss += delta * delta;