%cd c:\egsine

load sinedata;load fstart;
%figure(1);
%set(gcf,'resize','on','menubar','none','position',[5 525 451 213]);
figure(1);
set(gcf,'resize','on','menubar','none','position',[463 115 556 623]);
pos = get(0,'ScreenSize');
set(gcf,'position',pos);


%figure(3);
%set(gcf,'resize','on','menubar','none','position',[5 301 452 189]);
thr=0.5;

MFTYPE = 2;
lstep = 1;
NCmax=10;
%figure(2);
subplot(211); plot(d(:,1),d(:,2),'bo','markersize',3);
disp('Press a key to start clustering'); pause

rand('seed',10)
[f,c,P,V,D,J,M] = gkfast(d,5,2,0.02,2);
disp('Press a key to start cluster merging'); pause

rand('seed',10);
[f,c,P,V,D,J,M,NC,S,hist] = amerge(d,9,m,0.02,2,thr,[]);

pause; close(1); clc;

return

% calculate membership functions
makemf

% estimate local linear models
local

% calculate model output on training data
%dof=dofprod(rls,mfs,d(:,1));
%[ym yl ylm] = sugval(p,[d(:,1) ones(size(d,1),1)],dof);
%figure(1); plot(d(:,1),[d(:,2) ym ylm],'o');

% calculate model output on evaluation data
dofe=dofprod(rls,mfs,xe);
[yme yle ylme] = sugval(p,[xe ones(size(xe),1)],dofe);
%figure(3); plot(d(:,1),[d(:,2)],xe,[yme ylme]);
figure(3); plot(d(:,1),[d(:,2)],xe,[yme]);

