root/matlab/mex/ill_polyfit.m @ 116

Revision 116, 1.1 kB (checked in by smidl, 16 years ago)

MEX linking with bdm

  • Property svn:eol-style set to native
  • Property svn:keywords set to Rev Author Date
Line 
1% Test example for polynomial regression
2x = 0.1:0.1:1;
3Data = x.^3 - 0.1*x  + 1;
4%DataC = Data+0.02*randn(1,10);
5
6xP = 0:0.01:1.2;
7
8close all
9figure(1);
10%subplot(2,2,1);
11plot(x,DataC,'+');
12set(gca,'XLim',[0,1.4]);
13title('y=x^3-0.1x+1 + 0.1 N(0,1)');
14set(gcf,'Position',[100 100 350 250]);
15set(gcf,'PaperPositionMode','auto');
16print -depsc2 f0
17
18
19ind = 2;
20for n=1:5
21        Pn = polyfit(x,DataC,n);
22        devn = DataC-polyval(Pn,x);
23        Yn = polyval(Pn,xP);
24       
25        %       subplot(2,2,ind);
26        figure
27        ind = ind+1;
28        plot(x,DataC,'+');
29        hold on;
30        plot(xP,Yn);
31        title(['Order=' num2str(n) ', MSE=' num2str(devn*devn'/10)]);
32        set(gcf,'Position',[100 100 350 250]);
33        set(gcf,'PaperPositionMode','auto');
34        eval(['print -depsc2 f' num2str(n)]);
35        close all
36        mse(n) = devn*devn'/10;
37end
38
39for o=1:5
40        D = DataC;
41        for n=1:o
42                D = [D; x.^n];
43        end
44        [th,tll]=arx([D;ones(size(x))]);
45        marll(o) = tll;
46end
47emar = exp(marll);
48figure;
49subplot(1,2,1);
50bar(emar/sum(emar));
51title('Probability of the correct order');
52
53subplot(1,2,2);
54plot(-marll/100);
55hold on
56plot(1:5,mse*10,'r');
57title('Bayes factor and MSE')
58
59set(gcf,'Position',[100 100 600 250]);
60set(gcf,'PaperPositionMode','auto');
61
62print -depsc2 prob
Note: See TracBrowser for help on using the browser.