forked from tiepvupsu/DICTOL
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
448 additions
and
361 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
function [acc, rt] = D2L2R2_wrapper(Y_train, label_train, Y_test, label_test,... | ||
k, lambda1, lambda2, alpha) | ||
if nargin == 0 %% test mode | ||
addpath(fullfile('..', 'utils')); | ||
addpath(fullfile('..', 'ODL')); | ||
addpath(fullfile('..', 'LRSDL_FDDL')); | ||
addpath(fullfile('..', 'D2L2R2')); | ||
dataset = 'myYaleB'; | ||
N_train = 10; | ||
k = 8; | ||
lambda1 = 0.001; | ||
lambda2 = 0.01; | ||
alpha = 0.01; | ||
% eta = 0.1; | ||
[dataset, Y_train, Y_test, label_train, label_test] = train_test_split(... | ||
dataset, N_train); | ||
end | ||
%% Data preparation | ||
C = max(label_train); | ||
opts.k = k; | ||
opts.lambda1 = lambda1; | ||
opts.lambda2 = lambda2; | ||
opts.alpha = alpha; | ||
opts.max_iter = 100; | ||
opts.show = false; | ||
opts.showD = false; | ||
opts.verbal = true; | ||
opts = initOpts(opts); | ||
%% ========= Train ============================== | ||
[D, D_range, X, CoefM, opts, rt] = D2L2R2(Y_train, label_train, opts); | ||
%% ========= test ============================== | ||
acc = []; | ||
opts.verbal = false; | ||
opts.max_iter = 300; | ||
for vgamma = [0.001, 0.005, 0.01, 0.1] | ||
opts.gamma = vgamma; | ||
opts.weight = 0.5; | ||
|
||
pred = D2L2R2_pred(Y_test, D, D_range, CoefM, opts); | ||
acc = [acc double(sum(pred == label_test))/numel(label_test)]; | ||
fprintf('gamma = %.4f, acc = %5f\n', vgamma, acc(end)); | ||
end | ||
best_acc = max(acc); | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
function [acc, rt] = DLCOPAR_wrapper(Y_train, label_train, Y_test , label_test, ... | ||
k, k0, lambda, eta) | ||
% function [acc, rt] = LRSDL_wrapper(Y_train, label_train, Y_test , label_test, ... | ||
% k, k0, lambda1, lambda2, lambda3) | ||
% ----------------------------------------------- | ||
% Author: Tiep Vu, [email protected], 5/11/2016 | ||
% (http://www.personal.psu.edu/thv102/) | ||
% ----------------------------------------------- | ||
if nargin == 0 % test mode | ||
dataset = 'myYaleB'; | ||
N_train = 10; | ||
[~, Y_train, Y_test, label_train, label_test] = ... | ||
train_test_split(dataset, N_train); | ||
k = 8; | ||
k0 = 5; | ||
lambda = 0.001; | ||
eta = 0.01; | ||
end | ||
opts.k = k; | ||
opts.k0 = k0; | ||
C = max(label_test); | ||
D_range_ext = [k*(0:C), k*C + k0]; | ||
opts.lambda = lambda; | ||
opts.eta = eta; | ||
train_range = label_to_range(label_train); | ||
opts.show = false; | ||
opts.max_iter = 5; | ||
opts.verbal = true; | ||
opts = initOpts(opts); | ||
%% ========= Train ============================== | ||
[D, X, rt] = DLCOPAR(Y_train, train_range, opts); | ||
%% ========= test ============================== | ||
acc = []; | ||
for vgamma = [0.0001, 0.001, 0.005, 0.01] | ||
opts.gamma = vgamma; | ||
fprintf('gamma %5f\n', vgamma); | ||
opts.classify_mode = 'LC'; | ||
pred = DLCOPAR_pred(Y_test, D, D_range_ext, opts); | ||
acc = [acc double(sum(pred == label_test))/numel(label_test)]; | ||
fprintf('LC mode, acc = %5f\n', acc(end)); | ||
|
||
opts.classify_mode = 'GC'; | ||
pred = DLCOPAR_pred(Y_test, D, D_range_ext, opts); | ||
acc = [acc double(sum(pred == label_test))/numel(label_test)]; | ||
fprintf('GC mode, acc = %5f\n', acc(end)); | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
function [acc, rt] = DLSI_wrapper(Y_train, label_train, Y_test , label_test, ... | ||
k, lambda, eta) | ||
% function acc = SRC_wrapper(Y_train, range_train, Y_test , range_test, lambda) | ||
% Description : SRC | ||
% INPUT: | ||
% dataset: name of the dataset stored in 'data', excluding '.mat' | ||
% N_trn: number of training images per class | ||
% lambda : regularization parameter lambda | ||
% ----------------------------------------------- | ||
% Author: Tiep Vu, [email protected], 5/11/2016 | ||
% (http://www.personal.psu.edu/thv102/) | ||
% ----------------------------------------------- | ||
if nargin == 0 % test mode | ||
dataset = 'myYaleB'; | ||
N_train = 10; | ||
[~, Y_train, Y_test, label_train, label_test] = ... | ||
train_test_split(dataset, N_train); | ||
k = 8; | ||
lambda = 0.001; | ||
eta = 0.01; | ||
end | ||
C = max(label_train); | ||
D_range = k*(0:C); | ||
opts.lambda = lambda; | ||
opts.eta = eta; | ||
opts.D_range = D_range; | ||
opts.show_cost = 0; | ||
train_range = label_to_range(label_train); | ||
opts.show = 0; | ||
opts.verbal = true; | ||
opts.max_iter = 100; | ||
%% ========= Train ============================== | ||
[D, ~, rt] = DLSI(Y_train, train_range, opts); | ||
%% ========= test ============================== | ||
opts.verbal = false; | ||
pred = DLSI_pred(Y_test, D, opts); | ||
acc = double(sum(pred == label_test))/numel(label_test); | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.