function cluster_variance = cluster_variance_compute ( dim_num, point_num, ...
  cluster_num, point, cluster, cluster_center )

%*****************************************************************************80
%
%% cluster_variance_compute() computes the variance of the clusters.
%
%  Discussion:
%
%    The cluster variance (from the cluster center) is the average of the
%    sum of the squares of the distances of each point in the cluster to the
%    cluster center.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    06 October 2009
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer DIM_NUM, the number of spatial dimensions.
%
%    integer POINT_NUM, the number of data points.
%
%    integer CLUSTER_NUM, the number of clusters.
%
%    real POINT(POINT_NUM,DIM_NUM), the data points.
%
%    integer CLUSTER(POINT_NUM), the cluster to which each
%    data point belongs.
%
%    real CLUSTER_CENTER(CLUSTER_NUM,DIM_NUM), the
%    centers associated with the minimal energy clustering.
%
%  Output:
%
%    real CLUSTER_VARIANCE(CLUSTER_NUM), the variance of each cluster.
%
  cluster_population(1:cluster_num) = 0;
  cluster_variance(1:cluster_num) = 0.0;

  for i = 1 : point_num

    j = cluster(i);

    point_variance = sum ( ...
      ( point(i,1:dim_num) - cluster_center(j,1:dim_num) ).^2 );

    cluster_variance(j) = cluster_variance(j) + point_variance;
    cluster_population(j) = cluster_population(j) + 1;

  end

  cluster_variance(1:cluster_num) = cluster_variance(1:cluster_num) ...
    ./ cluster_population(1:cluster_num);

  return
end
