[go: up one dir, main page]

Menu

[r1758]: / es&gmdh / CondNumErr.m  Maximize  Restore  History

Download this file

128 lines (115 with data), 4.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
function CondNumErr();
%%used alexey's code
warning off;%
global PLTOPTSFIGNUM;
PLTOPTSFIGNUM = 1;
THISFOLDER = fileparts(mfilename('fullpath'));
CODEFOLDER = fullfile(THISFOLDER,'code');
REPORTFOLDER = fullfile(THISFOLDER,'report');
LASSOFOLDER = fullfile(THISFOLDER,'lasso');
SWFOLDER = fullfile(THISFOLDER,'fsbox');
DATAFOLDER = fullfile(THISFOLDER,'data');
if nargin < 1, Genname = 'gen.mat'; end
GenFullFname = fullfile(DATAFOLDER, Genname);
load(GenFullFname);
if ~exist(REPORTFOLDER,'dir'), mkdir(REPORTFOLDER); end
addpath(CODEFOLDER);
addpath(SWFOLDER);
addpath(LASSOFOLDER);
%if nargin < 1, PrjFname = 'med.prj.txt'; end
if nargin < 1, PrjFname = 'rom.prj.txt'; end
PrjFullFname = fullfile(DATAFOLDER, PrjFname);
% read the project file
evalstr = textread(PrjFullFname,'%s','commentstyle','matlab','delimiter','%');
for i=1:length(evalstr)
try
eval(evalstr{i});
fprintf(1,'%s\n',evalstr{i});
catch
fprintf(1,'\nError in the project file %s, line = %d, content = %s \n', PrjFname, i, evalstr{i});
end
end
AverNum = 10;
CondNum = [];
n = 150; % number of objects
m =20; % number of varibles
errTest = zeros(length(alg),6);
errLearn = zeros(length(alg),6);
Cond = zeros(length(alg),11);
%legend
for j = 1:length(alg)
CondNum = [];
%errTest = [];
%errLearn = [];
p=0;
for e=0:0.1:1 % e is conditionality measure, not conditionality
p = p+1;
% generate model data
X1 = e*ones(n,m-5) +(1-e)*[diag(ones(m-5,1));zeros(n-m+5,m-5)];
%X(:,m/2+1:end) = X(:,m/2+1:end)+X(:,1:m/2);
X = [X1 eye(n,5)];%; zeros(20,1)]);zeros(n-m,m)];
%X1 = ones(n,m) -[diag(ones(m,1));zeros(n-m,m)];
%X = e*ones(n,m)+ (1-e)* [diag(ones(m,1));zeros(n-m,m)];
%beta = (rand(m,1)-0.5); % linear regression parameters
beta = [zeros(m-10,1); ones(10,1)];%ones(5,1);
y = X*beta;%MN; % get responses
%y = y + (rand(n,1)-0.5)/10;
X = X + randMN(:,1:m);%(rand(n,m) - 0.5)/10; % add noise
[U,L,V]=svd(X);% find condition number for current XA
r = min(size(L));
CondNum(end+1) = L(1,1)/L(r,r);
for i=1:AverNum
[idxA,idxB]=SplitData(n,TRAIN2TEST);
yA=y(idxA);
A=X(idxA,:);
yB=y(idxB);
B=X(idxB,:);
w = lscov(B,yB);
mdlopts.sigma = sumsqr(yB - B*w)/size(B,1);% for Cp-estimation
mdlopts.algoName = alg{j};
fprintf(1,strcat('\n ', mdlopts.algoName));%Call FOS
%learn using chosen method
[b,Qlearn] = eval(strcat(mdlopts.algoName,'( A, yA, mdlopts )'));
%test
% figure;
s1 = sum(b.^2,2).^(0.5);
plot(s1,b);
xlabel(texlabel('|beta_i|'));
ylabel(texlabel('beta_i'));
% hold off
[best,Qtest,Qlearn] = test1(A,yA,B,yB,b);
[Qtest,idx]=sort(Qtest);
Qlearn = Qlearn(idx);
b = b(idx,:);
if ~isempty(b)
[Pop{i}] = CreatePopulation(B,yB,b,Qtest,Qlearn,mdlopts,n);end
end
if ~isempty(Pop)
[PopMean]=MeanCharact(Pop,mdlopts);end
%Population2TeX(PopMean,ReportFilename,mdlopts.algoName);
errLearn(j,p) = PopMean.errTrain;
errTest(j,p) = PopMean.errTest;
% [U,L,V]=svd(X(:,find(PopMean.wFound)));% find condition number for current XA
% r = min(size(L));
% Cond(j,p) = L(1,1)/L(r,r);
end
end
figure;
str = {'.--r' '.-b' '.-g' '.:' '.-m' '.c'};
for j = 1:(length(alg))
hold on;
ylabel('Errors');
xlabel('Condition number');
%title(namealg(j));
% plot(CondNum,errLearn,'--red');
% plot(CondNum,Cond(j,:),str{j});
plot(CondNum,errTest(j,:),str{j});
% legend('Learn','Control',1)
% text(strcat('\leftarrow ',namealg{j}),...
% 'Ho5rizontalAlignment','left')
%hold off
end
legend(str,namealg);
%rmpath(FUNCFOLDER);
rmpath(CODEFOLDER);
return