|
Revision 116, 1.1 kB
(checked in by smidl, 17 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 |
|---|
| 2 | x = 0.1:0.1:1; |
|---|
| 3 | Data = x.^3 - 0.1*x + 1; |
|---|
| 4 | %DataC = Data+0.02*randn(1,10); |
|---|
| 5 | |
|---|
| 6 | xP = 0:0.01:1.2; |
|---|
| 7 | |
|---|
| 8 | close all |
|---|
| 9 | figure(1); |
|---|
| 10 | %subplot(2,2,1); |
|---|
| 11 | plot(x,DataC,'+'); |
|---|
| 12 | set(gca,'XLim',[0,1.4]); |
|---|
| 13 | title('y=x^3-0.1x+1 + 0.1 N(0,1)'); |
|---|
| 14 | set(gcf,'Position',[100 100 350 250]); |
|---|
| 15 | set(gcf,'PaperPositionMode','auto'); |
|---|
| 16 | print -depsc2 f0 |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | ind = 2; |
|---|
| 20 | for 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; |
|---|
| 37 | end |
|---|
| 38 | |
|---|
| 39 | for 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; |
|---|
| 46 | end |
|---|
| 47 | emar = exp(marll); |
|---|
| 48 | figure; |
|---|
| 49 | subplot(1,2,1); |
|---|
| 50 | bar(emar/sum(emar)); |
|---|
| 51 | title('Probability of the correct order'); |
|---|
| 52 | |
|---|
| 53 | subplot(1,2,2); |
|---|
| 54 | plot(-marll/100); |
|---|
| 55 | hold on |
|---|
| 56 | plot(1:5,mse*10,'r'); |
|---|
| 57 | title('Bayes factor and MSE') |
|---|
| 58 | |
|---|
| 59 | set(gcf,'Position',[100 100 600 250]); |
|---|
| 60 | set(gcf,'PaperPositionMode','auto'); |
|---|
| 61 | |
|---|
| 62 | print -depsc2 prob |
|---|