File: msvmocas_light_example.m

package info (click to toggle)
libocas 0.97%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 6,756 kB
  • ctags: 352
  • sloc: ansic: 7,956; makefile: 118; sh: 7
file content (49 lines) | stat: -rw-r--r-- 1,694 bytes parent folder | download | duplicates (5)
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
trn_file = './data/example4_train.light';
tst_file = './data/example4_test.light';

C = 1;
TolRel = 0.01;
TolAbs = 0.00;
QPBound = 0;
BufSize = 2000;
nData = inf;
MaxTime = inf;
verb = 0;

Method = 0; % standard BMRM alias Cutting Plane Algorithm
fprintf('Training SVM by Cutting Plane Algorithm...');
[cp_W,cp_stat] = msvmocas_light(trn_file,C,Method,TolRel,TolAbs,QPBound,BufSize,nData,MaxTime,verb);
fprintf('done\n');

fprintf('Evaluating classifier on testing data...');
[score,true_labels] = linclassif_light(tst_file,cp_W,[]);
[dummy,pred_labels] = max(score);
cp_tst_err = sum(pred_labels(:) ~= true_labels(:))/length(true_labels);
fprintf('done\n');


fprintf('Training time: %f[s], #trn_errors: %d, nIter: %d\n',...
        cp_stat.total_time, cp_stat.nTrnErrors, cp_stat.nIter);
fprintf('Objval  primal: %f, dual: %f, gap: %f\n', ...
        cp_stat.Q_P, cp_stat.Q_D,cp_stat.Q_P-cp_stat.Q_D);
fprintf('Testing error: %f %%\n',cp_tst_err*100);
   

Method = 1; % OCAS 
fprintf('\nTraining SVM by OCAS...');
[ocas_W,ocas_stat] = msvmocas_light(trn_file,C,Method,TolRel,TolAbs,QPBound,BufSize,nData,MaxTime,verb);
fprintf('done\n');

fprintf('Evaluating classifier on testing data...');
[score,true_labels] = linclassif_light(tst_file,ocas_W,[]);
[dummy,pred_labels] = max(score);
ocas_tst_err = sum(pred_labels(:) ~= true_labels(:))/length(true_labels);
fprintf('done\n');


fprintf('Training time: %f[s], #trn_errors: %d, nIter: %d\n',...
        ocas_stat.total_time, ocas_stat.nTrnErrors, ocas_stat.nIter);
fprintf('Objval  primal: %f, dual: %f, gap: %f\n', ...
        ocas_stat.Q_P, ocas_stat.Q_D,ocas_stat.Q_P-ocas_stat.Q_D);
fprintf('Testing error: %f %%\n',ocas_tst_err*100);