function [partitionpairweighted] = partition_pairweighted(class_sizes)

% PARTITION_PAIRWEIGHTED produces a symmetric paroximty matrix of size $n
% \times n$ (with zero main diagonal) that contains K on-diagonal blocks
% each of size $n_{k} \times n_{k}$ for $k = 1,...,K (the sum of the class
% sizes is $n$), with values (to produce average within-class proximities)
% of $1/n_{k}*(n_{k}-1)$; all other matrix entries are zero.  CLASS_SIZES
% is a $K \times 1$ vector containing the class class sizes $n_{1},...,n_{K}$
%
% syntax:  [partitionpairweighted] = partition_pairweighted(class_sizes)

K = length(class_sizes);

n = sum(class_sizes);

partitionpairweighted = zeros(n,n);

lower_limit = 1;
upper_limit = class_sizes(1);

divider = class_sizes(1)*(class_sizes(1) - 1);

for i = 1:K
    
    for u = lower_limit:upper_limit
        for v = lower_limit:upper_limit
            
            if ( u ~= v)
                
                partitionpairweighted(u,v) = 1/divider;
            end
        end
    end
    
    if (i < K)
    
    lower_limit = upper_limit + 1;
    upper_limit = upper_limit + class_sizes(i+1);
    
    divider = class_sizes(i+1)*(class_sizes(i+1) - 1);
    
    end
end