maxSize=6;

mseAutoenc=zeros([maxSize,1]);
for i=1:maxSize
    ae=trainAutoencoder(trainingData,i,'ShowProgressWindow',false);
    predicted=predict(ae,trainingData);
    mseAutoenc(i)=mse(trainingData-predicted);
end

fig=figure();
subplot(1,3,1);
plot(mseAutoenc)
title('Autoencoder')
xlabel('number of syergies')
ylabel('mse')

%PCA
[COEFF,SCORE,latent] = pca(trainingData,'Centered',false);
msePCA=zeros([maxSize,1]);
for i=1:maxSize
    predicted=SCORE(:,1:i)*COEFF(:,1:i)';
    msePCA(i)=mse(trainingData-predicted);
end
subplot(1,3,2);
plot(msePCA)
title('PCA')
xlabel('number of syergies')
ylabel('mse')

%NNMF
mseNNMF=zeros([maxSize,1]);
for i=1:maxSize
    [W,H]=nnmf(trainingData,i);
    predicted=W*H;
    mseNNMF(i)=mse(trainingData-predicted);
end

subplot(1,3,3);
plot(mseNNMF)
title('NNMF')
xlabel('number of syergies')
ylabel('mse')