%% Test FAMS on 2D data

%% randomize data
max_uniform=100;
vect1 = rand(100,2)*max_uniform; % uniform 
vect2 = randn(120,2);
vect2 = vect2.*repmat([1,1],size(vect2,1),1)+repmat([70,60],size(vect2,1),1);
vect3 = randn(150,2);
vect3 = vect3.*repmat([1,1],size(vect3,1),1)+repmat([30,90],size(vect3,1),1);
data=[vect1;  vect2; vect3];

%% run FAMS
[modes, p_modes, w_modes]=fams(data,20,15,200,'2Ddata','res/');

%% view results

figure(1),clf;
subplot(2,2,1),plot(data(:,1),data(:,2),'.');title('2D data');
subplot(2,2,2),hist(data(:,2));
subplot(2,2,3),hist(data(:,1));

p_modes

figure(2),clf;
subplot(2,2,1),plot(modes(:,1),modes(:,2),'.');title('after FAMS');
hold on; subplot(2,2,1),plot(p_modes(1:2,2),p_modes(1:2,3),'r.');
subplot(2,2,2),hist(modes(:,2));
subplot(2,2,3),hist(modes(:,1));