% Spiral with approximately uniform density and outliers
N=1000;a=pi/2;b=8*pi;t=((b-a)*(linspace(0,1,N).^0.65)+a)';
X=[t.*sin(t) t.*cos(t)];X=X+randn(size(X))/1.2;X=[X;60*rand(100,2)-30];
figure(1);plot(X(:,1),X(:,2),'bo');
set(gca,'DataAspectRatio',[1 1 1]);ax=axis;
KNN=10; s=1.5; L=1;
[P,Its,evs] = mbms(X,s,KNN,L,0,400);
[Pg,Its,evs] = mbms(X,s,KNN,L,1,400);
[P0,Its,evs] = mbms(X,s,KNN,0,0,400);
[Pi,Its,evs] = ltp(X,KNN,L,0,400);


for i=1:Its
  figure(2);plot(P{i}(:,1),P{i}(:,2),'bo');set(gca,'DataAspectRatio',[1 1 1]);
  axis(ax);
  figure(3);plot(Pg{i}(:,1),Pg{i}(:,2),'bo');set(gca,'DataAspectRatio',[1 1 1]);
  axis(ax);
  figure(4);plot(Pi{i}(:,1),Pi{i}(:,2),'bo');set(gca,'DataAspectRatio',[1 1 1]);
  axis(ax);
  figure(5);plot(P0{i}(:,1),P0{i}(:,2),'bo');set(gca,'DataAspectRatio',[1 1 1]);
  axis(ax);
  pause
end


%% Animations
%figure(10); clf; set(10,'Position',[0 0 800 800],'PaperPositionMode','auto');
%subplot(2,2,1); plot(X(:,1),X(:,2),'bo');
%set(gca,'DataAspectRatio',[1 1 1]); axis(ax);
%title(['(\sigma=' num2str(s) ', k=' num2str(KNN) ...
%       ', L=1), full graph, it=0']);
%subplot(2,2,2); plot(X(:,1),X(:,2),'bo');
%set(gca,'DataAspectRatio',[1 1 1]); axis(ax);
%title(['(\sigma=' num2str(s) ', k=' num2str(KNN) ...
%       ', L=0), full graph (GBMS), it=0']);
%subplot(2,2,3); plot(X(:,1),X(:,2),'bo');
%set(gca,'DataAspectRatio',[1 1 1]); axis(ax);
%title(['(\sigma=' num2str(s) ', k=' num2str(KNN) ...
%       ', L=1), k-nn graph, it=0']);
%subplot(2,2,4); plot(X(:,1),X(:,2),'bo');
%set(gca,'DataAspectRatio',[1 1 1]); axis(ax);
%title(['(\sigma=\infty' ', k=' num2str(KNN) ...
%       ', L=1), k-nn graph (LTP), it=0']);
%print('-dpng','-r0','spiral_outliers000.png');
%for i=1:Its
%  subplot(2,2,1); plot(P{i}(:,1),P{i}(:,2),'bo');
%  set(gca,'DataAspectRatio',[1 1 1]); axis(ax);
%  title(['(\sigma=' num2str(s) ', k=' num2str(KNN) ...
%         ', L=1), full graph, it=' num2str(i,'%03d')]);
%  subplot(2,2,2); plot(P0{i}(:,1),P0{i}(:,2),'bo');
%  set(gca,'DataAspectRatio',[1 1 1]); axis(ax);
%  title(['(\sigma=' num2str(s) ', k=' num2str(KNN) ...
%         ', L=0), full graph (GBMS), it=' num2str(i,'%03d')]);
%  subplot(2,2,3); plot(Pg{i}(:,1),Pg{i}(:,2),'bo');
%  set(gca,'DataAspectRatio',[1 1 1]); axis(ax);
%  title(['(\sigma=' num2str(s) ', k=' num2str(KNN) ...
%         ', L=1), k-nn graph, it=' num2str(i,'%03d')]);
%  subplot(2,2,4); plot(Pi{i}(:,1),Pi{i}(:,2),'bo');
%  set(gca,'DataAspectRatio',[1 1 1]); axis(ax);
%  title(['(\sigma=\infty' ', k=' num2str(KNN) ...
%         ', L=1), k-nn graph (LTP), it=' num2str(i)]);
%  print('-dpng','-r0',['spiral_outliers' num2str(i,'%03d') '.png']);
%end
%
%
%% create histograms
