📄 mil_run.m
字号:
function run = MIL_Run(classifier)
warning('off','MATLAB:colon:operandsNotRealScalar');
% clear global preprocess;
global preprocess;
global temp_train_file temp_test_file temp_output_file temp_model_file weka_dir mySVM_dir libSVM_dir SVMLight_dir;
preprocess = [];
if (~isfield(preprocess, 'Message')), preprocess.Message = ''; end;
if (~isfield(preprocess, 'NumCrossFolder')), preprocess.NumCrossFolder = 3; end;
if (~isfield(preprocess, 'TrainTestSplitBoundary')), preprocess.TrainTestSplitBoundary = 100; end;
if (~isfield(preprocess, 'Normalization')), preprocess.Normalization = 1; end;
%if (~isfield(preprocess, 'SizeFactor')), preprocess.SizeFactor = 0.5; end;
%if (~isfield(preprocess, 'ShotAvailable')), preprocess.ShotAvailable = 0; end;
%if (~isfield(preprocess, 'DataSampling')), preprocess.DataSampling = 0; end;
%if (~isfield(preprocess, 'Sparse')), preprocess.Sparse = 0; end;
if (~isfield(preprocess, 'Shuffled')), preprocess.Shuffled = 0; end;
if (~isfield(preprocess, 'OutputFlag')), preprocess.OutputFlag = 'a'; end;
%if (~isfield(preprocess, 'SVD')), preprocess.SVD = 0; end;
%if (~isfield(preprocess, 'FLD')), preprocess.FLD = 0; end;
%if (~isfield(preprocess, 'CHI')), preprocess.ChiSquare = 0; end;
%if (~isfield(preprocess, 'ValidateByShot')), preprocess.ValidateByShot = 0; end;
%if (~isfield(preprocess, 'Ensemble')), preprocess.Ensemble = 0; end;
%if (~isfield(preprocess, 'ComputeMAP')), preprocess.ComputeMAP = 0; end;
if (~isfield(preprocess, 'Evaluation')), preprocess.Evaluation = 0; preprocess.TrainTestSplitBoundary = -2; end;
%if (~isfield(preprocess, 'MultiClassType')), preprocess.MultiClassType = 0; end;
%if (~isfield(preprocess, 'MultiClass') | (preprocess.MultiClassType == 0)),
% preprocess.MultiClass.LabelType = 1; preprocess.MultiClass.CodeType = -1; preprocess.MultiClass.LossFuncType = -1;
% preprocess.MultiClass.UncertaintyFuncType = -1; preprocess.MultiClass.ProbEstimation = -1;
%end;
%if (~isfield(preprocess, 'ConstraintAvailable')), preprocess.ConstraintAvailable = 0; end;
%if (~isfield(preprocess, 'ConstraintFileName')), preprocess.ConstraintFileName = ''; end;
if (~isfield(preprocess, 'input_file')), preprocess.input_file = ''; end;
if (~isfield(preprocess, 'output_file')), preprocess.output_file = ''; end;
if (~isfield(preprocess, 'pred_file')), preprocess.pred_file = ''; end;
if (~isfield(preprocess, 'model_file')), preprocess.model_file = ''; end;
if (~isfield(preprocess, 'WorkingDir')), preprocess.WorkingDir = ''; end;
if (~isfield(preprocess, 'EnforceDistrib')), preprocess.EnforceDistrib = 0; end;
if (~isfield(preprocess, 'InputFormat')), preprocess.InputFormat = 0; end;
if (nargin < 1), Report_Error; end;
[header, para, rem] = ParseCmd(classifier, '--');
if (strcmpi(header, 'classify')),
p = str2num(char(ParseParameter(para, {'-v'; '-sf'; '-n'; '-if'; '-of'; '-pf'; '-distrib'}, ...
{'1'; '0'; '1'; '0'; '0'; '0'; '0'})));
preprocess.Vebosity = p(1);
preprocess.Shuffled = p(2);
preprocess.Normalization = p(3);
preprocess.InputFormat = p(4);
preprocess.OutputFormat = p(5);
preprocess.PredFormat = p(6);
preprocess.EnforceDistrib = p(7);
% preprocess.ShotAvailable = p(4);
% preprocess.ValidateByShot = p(5);
% preprocess.DataSampling = p(6);
% preprocess.DataSamplingRate = p(7);
% preprocess.SVD = p(8);
% preprocess.FLD = p(9);
% preprocess.ComputeMAP = p(10);
% preprocess.InputFormat = p(11);
% preprocess.ChiSquare = p(12);
% preprocess.Sparse = p(15);
% preprocess.EnforceDistrib = p(16);
p = ParseParameter(para, {'-t'; '-o'; '-p'; '-oflag'; '-dir'; '-drf' }, {''; ''; ''; 'a'; ''; ''});
preprocess.input_file = char(p{1, :});
preprocess.output_file = char(p{2, :});
preprocess.pred_file = char(p{3, :});
preprocess.OutputFlag = char(p{4, :});
preprocess.WorkingDir = char(p{5, :});
% preprocess.DimReductionFile = char(p{6, :});
classifier = rem;
else
Report_Error;
end;
% Setup the environmental varaible for directory information
if (isempty(preprocess.WorkingDir)),
filename = 'MIL_Classify.m';
if (~exist(filename)),
error('Cannot find the files in LibMIL!');
end;
cur_dir = which(filename);
sep_pos = findstr(cur_dir, filesep);
preprocess.WorkingDir = cur_dir(1:sep_pos(length(sep_pos))-1);
end;
root = preprocess.WorkingDir;
temp_dir = sprintf('%s/temp', root);
if (~exist(temp_dir)),
s = mkdir(root, 'temp');
if (s ~= 1), error('Cannot create temp directory!'); end;
end;
temp_train_file = sprintf('%s/temp.train.txt', temp_dir);
temp_test_file = sprintf('%s/temp.test.txt', temp_dir);
temp_output_file = sprintf('%s/temp.output.txt', temp_dir);
temp_model_file = sprintf('%s/temp.model.txt', temp_dir);
%weka_dir = sprintf('%s/weka-3-4/weka.jar', root);
%5mySVM_dir = sprintf('%s/svm', root);
libSVM_dir = sprintf('%s/svm', root);
%SVMLight_dir = sprintf('%s/svm', root);
[header, para, rem] = ParseCmd(classifier, '--');
if (strcmpi(header, 'train_test_validate')),
preprocess.Evaluation = 0;
p = str2num(char(ParseParameter(para, {'-t'}, {'-2'})));
preprocess.TrainTestSplitBoundary = p(1);
classifier = rem;
elseif (strcmpi(header, 'cross_validate')),
preprocess.Evaluation = 1;
p = str2num(char(ParseParameter(para, {'-t'}, {'3'})));
preprocess.NumCrossFolder = p(1);
classifier = rem;
elseif (strcmpi(header, 'test_file_validate')),
preprocess.Evaluation = 2;
p = char(ParseParameter(para, {'-t'}, {''}));
preprocess.test_file = p(1, :);
classifier = rem;
elseif (strcmpi(header, 'train_only')),
preprocess.Evaluation = 3;
p = char(ParseParameter(para, {'-m'}, {''}));
preprocess.model_file = p(1, :);
temp_model_file = preprocess.model_file;
classifier = rem;
elseif (strcmpi(header, 'test_only')),
preprocess.Evaluation = 4;
p = char(ParseParameter(para, {'-m'}, {''}));
preprocess.model_file = p(1, :);
temp_model_file = preprocess.model_file;
classifier = rem;
elseif (strcmpi(header, 'leave_one_out')),
preprocess.Evaluation = 5;
classifier = rem;
end;
% [header, para, rem] = ParseCmd(classifier, '--');
% if (strcmpi(header, 'train_test_simple')),
% preprocess.MultiClassType = 0;
% p = str2num(char(ParseParameter(para, {'-LabelType'}, {'1'})));
% preprocess.MultiClass.LabelType = p(1);
% classifier = rem;
% elseif (strcmpi(header, 'train_test_multiple_class')),
% preprocess.MultiClassType = 1;
% p = str2num(char(ParseParameter(para, {'-LabelType'; '-CodeType'; '-LossFuncType'}, {'1'; '0'; '2'})));
% preprocess.MultiClass.LabelType = p(1);
% preprocess.MultiClass.CodeType = p(2);
% preprocess.MultiClass.LossFuncType = p(3);
% preprocess.MultiClass.UncertaintyFuncType = 2;
% preprocess.MultiClass.ProbEstimation = 0;
% classifier = rem;
% elseif (strcmpi(header, 'train_test_multiple_label')),
% preprocess.MultiClassType = 2;
% p = str2num(char(ParseParameter(para, {'-LabelType'}, {'1'})));
% preprocess.MultiClass.LabelType = p(1);
% classifier = rem;
% elseif (strcmpi(header, 'train_test_multiple_class_AL')),
% preprocess.MultiClassType = 3;
% p = str2num(char(ParseParameter(para, {'-LabelType'; '-CodeType'; '-LossFuncType'; '-ALIter'; '-ALIncrSize'}, {'1'; '0'; '2'; '4'; '10'})));
% preprocess.MultiClass.LabelType = p(1);
% preprocess.MultiClass.CodeType = p(2);F@
% preprocess.MultiClass.LossFuncType = p(3);
% preprocess.ActiveLearning.Iteration = p(4);
% preprocess.ActiveLearning.IncrementSize = p(5);
% preprocess.MultiClass.UncertaintyFuncType = 2;
% preprocess.MultiClass.ProbEstimation = 0;
% classifier = rem;
% end;
% Initialize the message string
preprocess.Message = '';
if (preprocess.Evaluation == 0)
msg = sprintf(' Train-Test Split, Boundary: %d, ', preprocess.TrainTestSplitBoundary);
preprocess.Message = [preprocess.Message msg];
elseif (preprocess.Evaluation == 1)
msg = sprintf(' Cross Validation, Folder: %d, ', preprocess.NumCrossFolder);
preprocess.Message = [preprocess.Message msg];
elseif (preprocess.Evaluation == 2)
msg = sprintf(' Testing on File %s, ', preprocess.test_file);
preprocess.Message = [preprocess.Message msg];
elseif (preprocess.Evaluation == 3)
msg = sprintf(' Training on File %s, ', preprocess.input_file);
preprocess.Message = [preprocess.Message msg];
elseif (preprocess.Evaluation == 4)
msg = sprintf(' Testing on File %s, ', preprocess.input_file);
preprocess.Message = [preprocess.Message msg];
else
msg = sprintf(' Train-Test Split, Boundary: %d, ', preprocess.TrainTestSplitBoundary);
preprocess.Message = [preprocess.Message msg];
end;
% if (preprocess.MultiClassType == 0)
% msg = sprintf(' Classification, ', preprocess.TrainTestSplitBoundary);
% preprocess.Message = [preprocess.Message msg];
% elseif (preprocess.MultiClassType == 1)
% msg = sprintf(' Multiclass Classification Wrapper, ', preprocess.NumCrossFolder);
% preprocess.Message = [preprocess.Message msg];
% elseif (preprocess.MultiClassType == 2)
% msg = sprintf(' Multilabel Classification Wrapper, ', preprocess.NumCrossFolder);
% preprocess.Message = [preprocess.Message msg];
% elseif (preprocess.MultiClassType == 3)
% msg = sprintf(' Multiclass Active Learning Wrapper, ', preprocess.NumCrossFolder);
% preprocess.Message = [preprocess.Message msg];
% end;
% if (preprocess.SVD == 1)
% msg = sprintf(' SVD ');
% preprocess.Message = [preprocess.Message msg];
% end;
if (preprocess.Shuffled == 1)
msg = sprintf(' Shuffled ');
preprocess.Message = [preprocess.Message msg];
end;
% if (preprocess.Sparse == 1)
% msg = sprintf(' Sparse ');
% preprocess.Message = [preprocess.Message msg];
% end;
% if (preprocess.MultiClass.CodeType == 0)
% msg = sprintf(' Coding: 1-vs-r ');
% preprocess.Message = [preprocess.Message msg];
% elseif (preprocess.MultiClass.CodeType == 1)
% msg = sprintf(' Coding: 1-vs-1 ');
% preprocess.Message = [preprocess.Message msg];
% elseif (preprocess.MultiClass.CodeType == 2)
% msg = sprintf(' Coding: ECOC15_5 ');
% preprocess.Message = [preprocess.Message msg];
% elseif (preprocess.MultiClass.CodeType == 3)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -