
%It uses http://www.imm.dtu.dk/~mm/downloads/PCHA.zip from M. Mørup and L. K. Hansen, Archetypal Analysis for Data Mining, Neural Computing 2012.

%X=rbind(c(1,2),c(5,NaN),c(6,6),c(4,7))

%Nan as zero
X=[1 2
5 0
6 6
4 7]

XM=X'
noc=1
nrep=20
SSEv=[]

for i=1:nrep
s = RandStream('mt19937ar','Seed',i);
RandStream.setGlobalStream(s);

[XC,S,C,SSE,varexpl]=PCHAsparse(XM,noc);
SSEv(i)=SSE;
end

SSEv 

  

min(SSEv)

%ans =   29.7147
	
	i=19
	
	s = RandStream('mt19937ar','Seed',i);
RandStream.setGlobalStream(s);
noc=1
[XC,S,C,SSE,varexpl]=PCHAsparse(XM,noc);



%XC =

%    2.6089
%    4.0598

		
		%%%%%%%%%%%%%%%%%
		noc=2
		nrep=20
SSEv=[]

for i=1:nrep
s = RandStream('mt19937ar','Seed',i);
RandStream.setGlobalStream(s);

[XC,S,C,SSE,varexpl]=PCHAsparse(XM,noc);
SSEv(i)=SSE;
end


SSEv

min(SSEv)

		


		
		
		i=1
		s = RandStream('mt19937ar','Seed',i);
RandStream.setGlobalStream(s);

[XC,S,C,SSE,varexpl]=PCHAsparse(XM,noc);

		
		

%XC =

 %   5.0606    1.0061
 %  6.4607    2.0099


		%%%%%%%%%%%%%%%%
		

