%d \n', K)
    model{i}  = mixDiscreteFit(Xtrain, K, options{:});
    logp(i)   = sum(mixDiscreteLogprob(model{i}, Xtest));
    nParams   = K*d + K-1;
    bicVal(i) = -2*logp(i) + nParams*log(n);
end
%% Plot
for i=1:NK
    K = Kvalues(i);
    figure();
    [ynum, xnum] = nsubplots(K);
    if K==10
        ynum = 2; xnum = 5;
    end
    TK = model{i}.cpd.T; 
    mixweightK = model{i}.mixWeight;
    for j=1:K
        subplot(ynum, xnum, j);
        imagesc(reshape(TK(j, 2, :), 28, 28)); 
        colormap('gr