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