Skip to content

Commit

Permalink
Merge branch 'release/v2.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
steven2358 committed Jan 7, 2020
2 parents c65ce21 + 2592548 commit 694cf94
Show file tree
Hide file tree
Showing 78 changed files with 275 additions and 215 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,12 @@ If you use this toolbox in your research please cite ["A Comparative Study of Ke

@inproceedings{vanvaerenbergh2013comparative,
author = {Van Vaerenbergh, Steven and Santamar{\'i}a, Ignacio},
booktitle = {2013 IEEE Digital Signal Processing (DSP) Workshop and IEEE Signal Processing Education (SPE)},
booktitle = {2013 IEEE Digital Signal Processing and Signal Processing Education Meeting (DSP/SPE)},
title = {A Comparative Study of Kernel Adaptive Filtering Algorithms},
doi = {10.1109/DSP-SPE.2013.6642587},
pages = {181--186},
year = {2013},
month = aug,
note = {Software available at \url{https://github.com/steven2358/kafbox/}}
}

Expand Down
2 changes: 1 addition & 1 deletion demo/demo_parameter_estimation_lorenz.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
kaf = krlst(struct('lambda',lambda_est,'M',100,'sn2',reg_est,...
'kerneltype','gauss','kernelpar',sigma_est));

for i=1:N,
for i=1:N
if ~mod(i,floor(N/10)), fprintf('.'); end % progress indicator, 10 dots

Y_est(i) = kaf.evaluate(X(i,:)); % predict the next output
Expand Down
2 changes: 1 addition & 1 deletion demo/demo_prediction.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
%% RUN ALGORITHM
N = size(X,1);
Y_est = zeros(N,1);
for i=1:N,
for i=1:N
if ~mod(i,floor(N/10)), fprintf('.'); end % progress indicator, 10 dots
Y_est(i) = kaf.evaluate(X(i,:)); % predict the next output
kaf.train(X(i,:),Y(i)); % train with one input-output pair
Expand Down
2 changes: 1 addition & 1 deletion demo/demo_prediction_kstep.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
%% RUN ALGORITHM
N = size(X,1);
Y_est = zeros(N,1);
for i=k:N,
for i=k:N
if ~mod(i,floor(N/10)), fprintf('.'); end % progress indicator, 10 dots
Y_est(i) = kaf.evaluate(X(i,:)); % predict the next output

Expand Down
2 changes: 1 addition & 1 deletion demo/demo_prediction_kstep_split.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
Y_test = Y(N_train+1:N_train+N_test);

Y_test_MSE = zeros(N_train,1);
for i=1:N_train,
for i=1:N_train
% train on data set 1
if ~mod(i,floor(N_train/10)), fprintf('.'); end % progress indicator, 10 dots
kaf.train(X(i,:),Y(i)); % train with one input-output pair
Expand Down
6 changes: 3 additions & 3 deletions demo/demo_prediction_mackey_glass.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
MSE = zeros(n_train,n_algos);
y_est_final = zeros(n_test,n_algos);
titles = cell(n_algos,1);
for j=1:n_algos,
for j=1:n_algos
kaf = algos{j};
titles{j} = upper(class(kaf)); % store algorithm name
fprintf('Training %s',titles{j})
for i=1:n_train,
for i=1:n_train
if ~mod(i,floor(n_train/10)), fprintf('.'); end % progress indicator

kaf.train(X_train(i,:),y_train(i)); % train with one input-output pair
Expand All @@ -69,7 +69,7 @@
plot(y_test,'LineWidth',2);
titles2 = {'original'};
line_styles = {'--','-.'};
for j=1:n_algos,
for j=1:n_algos
plot(y_est_final(:,j),'LineWidth',2,'LineStyle',line_styles{j});
end
titles2(2:n_algos+1) = titles;
Expand Down
2 changes: 1 addition & 1 deletion demo/demo_profiler_prediction_lorenz.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
% output_dir = output_dir_default;
% fprintf('Using default folder "%s" for storing results.\n', output_dir_default);
% end
output_dir = fullfile(mfilename('fullpath'),'..','results');
output_dir = fullfile(fileparts(mfilename('fullpath')),'results');

t1 = tic;
[data,algorithms,results] = kafbox_profiler(data,sim_opts,algorithms,output_dir);
Expand Down
10 changes: 5 additions & 5 deletions demo/demo_reconverge_all.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
%% PROGRAM

w = who;
for i=1:length(w), % copy all parameters to option structure
for i=1:length(w) % copy all parameters to option structure
eval(sprintf('opt.%s = %s;',w{i},w{i}))
end

Expand All @@ -30,8 +30,8 @@
fdir = fileparts(which('kafbox_template.m'));
files = dir(fullfile(fdir,'*.m'));
[~,algorithms] = cellfun(@fileparts, {files.name}, 'UniformOutput',0);
for i=length(algorithms):-1:1,
if ~exist(algorithms{i},'class'),
for i=length(algorithms):-1:1
if ~exist(algorithms{i},'class')
algorithms(i) = []; % remove files that do not represent classes
end
end
Expand All @@ -49,7 +49,7 @@
titles{algo_ind} = strrep(upper(algorithm),'_','\_');

kaf = feval(algorithm);
for i=1:N,
for i=1:N
if ~mod(i,floor(N/10)), fprintf('.'); end

y_est = kaf.evaluate(X_test);
Expand Down Expand Up @@ -81,7 +81,7 @@
num_in_league = (rm==0)*5 + rm;
% plot the results for the num_in_league worst results
league_inds = num_alg-remaining+num_in_league:-1:num_alg-remaining+1;
for i=league_inds,
for i=league_inds
plot(10*log10(MSE(:,ind(i))),'LineWidth',1)
end
title(sprintf('League %d',fig_ind))
Expand Down
4 changes: 2 additions & 2 deletions demo/demo_regression_2d.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

%% PROGRAM

kaf = feval(algorithm, opts);
kaf = feval(algorithm, opts); %#ok<FVAL>

% generate some data
c = 5;
Expand All @@ -22,7 +22,7 @@
y = sin(3*x(:,1)).*cos(x(:,1)+x(:,2));

fprintf('Training')
for i=1:N,
for i=1:N
if ~mod(i,floor(N/10)), fprintf('.'); end
kaf.train(x(i,:),y(i));
% y_test = kaf.evaluate(x(i+1,:));
Expand Down
4 changes: 2 additions & 2 deletions demo/demo_sample_run.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

fprintf('Running KRLS-T\n');
t1 = tic;
for i=1:n,
for i=1:n
if ~mod(i,floor(n/10)), fprintf('.'); end
Qold = kaf.Q;
kaf.train(x(i),y(i));
Expand Down Expand Up @@ -108,7 +108,7 @@
end

if savefig
if ~exist('fig','file')
if ~exist('fig','file') %#ok<UNRCH>
mkdir('fig');
end
% write individual png
Expand Down
4 changes: 2 additions & 2 deletions demo/demo_sinc.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
%% RUN ALGORITHM
fprintf('%s: ',upper(algorithm));
Y_est = zeros(N_test,1);
kaf = feval(algorithm);
kaf = feval(algorithm); %#ok<FVAL>
t1 = tic;
for i=1:N,
for i=1:N
if ~mod(i,floor(N/10)), fprintf('.'); end
kaf.train(x(i),y(i));
end
Expand Down
8 changes: 4 additions & 4 deletions demo/demo_sinc_all.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
fdir = fileparts(which('kafbox_template.m'));
files = dir(fullfile(fdir,'*.m'));
[~,algorithms] = cellfun(@fileparts, {files.name}, 'UniformOutput',0);
for i=length(algorithms):-1:1,
if ~exist(algorithms{i},'class'),
for i=length(algorithms):-1:1
if ~exist(algorithms{i},'class')
algorithms(i) = []; % remove files that do not represent classes
end
end
Expand All @@ -46,7 +46,7 @@
titles{algo_ind} = strrep(upper(algorithm),'_','\_');

kaf = feval(algorithm);
for i=1:N,
for i=1:N
if ~mod(i,floor(N/10)), fprintf('.'); end
kaf.train(x(i),y(i));
end
Expand All @@ -73,7 +73,7 @@
num_in_league = (rm==0)*5 + rm;
% plot the results for the num_in_league worst results
league_inds = num_alg-remaining+num_in_league:-1:num_alg-remaining+1;
for i=league_inds,
for i=league_inds
plot(x_test,Y_est(:,ind(i)),'LineWidth',2)
end
title(sprintf('League %d',fig_ind))
Expand Down
2 changes: 1 addition & 1 deletion demo/demo_template_prediction.m
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@

fprintf('Running prediction algorithm %s',upper(class(kaf)))
Y_est = zeros(N,1);
for i=1:N,
for i=1:N
if ~mod(i,floor(N/10)), fprintf('.'); end

Y_est(i) = kaf.evaluate(X(i,:)); % make prediction
Expand Down
2 changes: 1 addition & 1 deletion demo/demo_template_system_identification.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

fprintf('Running system identification algorithm')
Y_est = zeros(N,1);
for i=1:N,
for i=1:N
if ~mod(i,floor(N/10)), fprintf('.'); end

Y_est(i) = kaf.evaluate(X(i,:)); % make prediction
Expand Down
8 changes: 4 additions & 4 deletions demo/krlst_split.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@

function kaf = krlst_split(parameters) % constructor
if (nargin > 0) % copy valid parameters
for fn = fieldnames(parameters)',
if ismember(fn,fieldnames(kaf)),
for fn = fieldnames(parameters)'
if ismember(fn,fieldnames(kaf))
kaf.(fn{1}) = parameters.(fn{1});
end
end
Expand Down Expand Up @@ -124,7 +124,7 @@ function train(kaf,x,y) % train the algorithm
function kaf = prune(kaf,Qold,gamma2)
m = size(kaf.Sigma,1);

if gamma2<kaf.jitter, % to avoid roundoff error
if gamma2<kaf.jitter % to avoid roundoff error
if gamma2<kaf.jitter/10
warning('Numerical roundoff error too high, you should increase jitter noise') %#ok<WNTAG>
end
Expand All @@ -136,7 +136,7 @@ function train(kaf,x,y) % train the algorithm
[~, r] = min(criterion); % remove element r, which incurs in the minimum error
smaller = 1:m; smaller(r) = [];

if r == m, % if we must remove the element we just added, perform reduced update instead
if r == m % if we must remove the element we just added, perform reduced update instead
kaf.Q = Qold;
kaf.reduced = true;
else
Expand Down
6 changes: 3 additions & 3 deletions demo/literature/liu2010kernel/fig2_12.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
N_tr = 1000; % number of training data
N_te = 50; % number of testing data

setups{1} = lms(struct('mu',.01));
setups{1} = lms(struct('mu',.01)); %#ok<CMLMS>
setups{2} = klms(struct('eta',0.2,'M',N_tr,'kerneltype','gauss','kernelpar',1));

%% PREPARE DATA
Expand All @@ -36,7 +36,7 @@
y = z - 0.9*z.^2 + ns; % output of nonlinear channel

X_all = zeros(N_tr+N_te,embedding); % time-embedding
for k=1:embedding,
for k=1:embedding
X_all(:,k) = y(k:N_tr+N_te+k-1);
end

Expand All @@ -52,7 +52,7 @@

MSE = zeros(N_tr,num_setup);

for setup_ind = 1:num_setup,
for setup_ind = 1:num_setup
kaf = setups{setup_ind};

for n=1:N_tr
Expand Down
4 changes: 2 additions & 2 deletions demo/literature/richard2009online/fig1.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
MSE = zeros(N,num_setup);
titles = cell(num_setup,1);

for sim_ind = 1:numsim,
for sim_ind = 1:numsim
fprintf('SIM %d:\n',sim_ind)

% Generate the data
[X,y,yref] = generate_doddbench(N);

for setup_ind = 1:num_setup,
for setup_ind = 1:num_setup
kaf = setups{setup_ind};
titles{setup_ind} = upper(class(kaf));

Expand Down
4 changes: 2 additions & 2 deletions demo/literature/richard2009online/fig2.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@
MSE = zeros(N,num_setup);
titles = cell(num_setup,1);

for sim_ind = 1:numsim,
for sim_ind = 1:numsim
fprintf('SIM %d:\n',sim_ind)

% Generate the data
[X,y,yref] = generate_richardbench(N);

for setup_ind = 1:num_setup,
for setup_ind = 1:num_setup
kaf = setups{setup_ind};
titles{setup_ind} = upper(class(kaf));

Expand Down
2 changes: 1 addition & 1 deletion demo/literature/richard2009online/generate_doddbench.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
dref = zeros(1,N+2);
dref(1:2)=[0.1 0.1];

for t=3:N+2,
for t=3:N+2
dref(t) = (0.8-0.5*exp(-dref(t-1)^2))*dref(t-1) - ...
(0.3+0.9*exp(-dref(t-1)^2))*dref(t-2)+0.1*sin(pi*dref(t-1));
end
Expand Down
2 changes: 1 addition & 1 deletion demo/literature/richard2009online/generate_richardbench.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
u = 0.25*randn(N+1,1);
dref = zeros(1,N+1);

for t=2:N+1,
for t=2:N+1
v(t) = 1.1*exp(-abs(v(t-1)))+u(t);
dref(t) = v(t)^2;
end
Expand Down
4 changes: 2 additions & 2 deletions demo/literature/vanvaerenbergh2006sliding/fig2.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
num_alg = length(setups);
MSE = zeros(N,num_alg);
MSE_final = zeros(1,num_alg);
for sim_ind = 1:num_sim,
for sim_ind = 1:num_sim
% generate data
[X,y,y_ref,X_test,y_test] = generate_channel_switch(opt);

Expand All @@ -54,7 +54,7 @@
fprintf('%9s M=%3d: ',upper(class(kaf)),kaf.M);

mse = zeros(N,1);
for i=1:N,
for i=1:N
if ~mod(i,floor(N/10)), fprintf('.'); end

y_est = kaf.evaluate(X_test);
Expand Down
6 changes: 3 additions & 3 deletions demo/literature/vanvaerenbergh2012kernel/fig3.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
% generate Gaussian input data s
s = rand(N+N_test,1);
s_mem = zeros(N+N_test,embedding);
for i = 1:embedding,
for i = 1:embedding
s_mem(i:N+N_test,i) = s(1:N+N_test-i+1); % time-embedding
end
s = s_mem(1:N+N_test,:); % input data, stored in columns
Expand Down Expand Up @@ -78,9 +78,9 @@

titles{setup_ind} = upper(class(kaf));
fprintf('%s\t',titles{setup_ind});
for n=1:N,
for n=1:N
if ~mod(n,round(N/10)), fprintf('.'); end
if n<=Nswitch,
if n<=Nswitch
Y_test = Y_test1;
else
Y_test = Y_test2;
Expand Down
6 changes: 3 additions & 3 deletions demo/literature/yukawa2012multikernel/fig1a.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
% mk_kernelpars = [.2 .5 1 2 5 10 20 50]; % alternative values

% remark 1 from paper determines mu0
setups{1} = lms(struct('mu',.01));
setups{1} = lms(struct('mu',.01)); %#ok<CMLMS>
setups{2} = knlms(struct('mu0',mk_thresh^(.2/min(mk_kernelpars)),'eta',0.2,'eps',3E-2,'kerneltype','gauss','kernelpar',1/sqrt(.2)));
setups{3} = knlms(struct('mu0',mk_thresh^(.5/min(mk_kernelpars)),'eta',0.2,'eps',3E-2,'kerneltype','gauss','kernelpar',1/sqrt(.5)));
setups{4} = mknlms_cs(struct('delta',mk_thresh,'eta',0.2,'rho',6E-2,'kerneltype','gauss','kernelpars',1./sqrt(mk_kernelpars)));
Expand All @@ -47,7 +47,7 @@
y = z - 0.9*z.^2 + ns; % output of nonlinear channel

X_all = zeros(N_tr+N_te,embedding); % time-embedding
for k=1:embedding,
for k=1:embedding
X_all(:,k) = y(k:N_tr+N_te+k-1);
end

Expand All @@ -63,7 +63,7 @@
num_setup = length(setups);
MSE = zeros(N_tr,num_setup);

for setup_ind = 1:num_setup,
for setup_ind = 1:num_setup
kaf = setups{setup_ind};

for n=1:N_tr
Expand Down
2 changes: 1 addition & 1 deletion demo/run_all_demos.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

% get list of literature scripts
folders_literature = dir(fullfile(fdir,'literature','*2*'));
for i=1:length(folders_literature);
for i=1:length(folders_literature)
folder_i = fullfile(fdir,'literature',folders_literature(i).name);
files_i = dir(fullfile(folder_i,'fig*.m'));
folders_i = repmat({folder_i},length(files_i),1);
Expand Down
Loading

0 comments on commit 694cf94

Please sign in to comment.