Skip to content

fix_num_points

Certify that the values in the clu_num_points array, i.e. the number of points in each cluster, add up to num_points.

num_points_fixed = fix_num_points(clu_num_points, num_points)

If the values in the clu_num_points array, i.e. the number of points in each cluster, don't add up to num_points, this function increments the number of points in the smallest cluster while sum(clu_num_points) < num_points, or decrements the largest cluster while sum(clu_num_points) > num_points.

This function is used internally by clusizes() and might be useful for custom cluster sizing implementations given as the clusizes_fn parameter of the main clugen() function.

Arguments

  • clu_num_points - Number of points in each cluster (vector of size \(c\)), where \(c\) is the number of clusters.
  • num_points - The expected total number of points.

Return values

  • num_points_fixed - Number of points in each cluster, after being fixed by this function (vector of size \(c\)).

Examples

clusters = [1, 6, 3];
fix_num_points(clusters, 12)
% ans =
%
%    3   6   3