Skip to content

Commit

Permalink
Merge branch 'liblinear-partial-order'
Browse files Browse the repository at this point in the history
  • Loading branch information
javism committed Jan 31, 2018
2 parents 664afcf + 5d4dbcd commit f184bb3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
35 changes: 35 additions & 0 deletions src/Algorithms/Algorithm.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,36 @@ function parseArgs(obj,varargin)
end
end

function setParam(obj,param)
%SETPARAM(PARAM) set parameters contained in param and keep default
%values of class parameters field. It throws different exceptions if
%the field does not exits on the class or if the type assignement is not consistent.
%paramNames = fieldnames(obj.parameters);
paramNames = fieldnames(param);

for i = 1:length(paramNames)
inpName = paramNames{i};
if isfield(obj.parameters,inpName)
% check type
if strcmp(class(obj.parameters.(inpName)), class(param.(inpName)))
obj.parameters.(inpName) = param.(inpName);
else
% Check boolean
if islogical(obj.parameters.(inpName)) && ...
(strcmp(param.(inpName),'true') || strcmp(param.(inpName),'false'))
obj.parameters.(inpName) = eval(pair{2});
else
msg = sprintf('Data type of property ''%s'' (%s) not compatible with data type (%s) of assigned value in configuration file', ...
inpName, class(obj.parameters.(inpName)), class(param.(inpName)));
error(msg);
end
end
else
error('Error ''%s'' is not a recognized class parameter name',inpName)
end
end
end

function mInf = runAlgorithm(obj,train, test, param)
%RUNALGORITHM runs the corresponding algorithm, fitting the
%model and testing it in a dataset.
Expand All @@ -84,7 +114,12 @@ function parseArgs(obj,varargin)
% returns predictions and model in mInf structure.
if nargin == 3
param = [];
else
% Mix parameters with default
obj.setParam(param)
end
param = obj.parameters;

c1 = clock;
[model,mInf.projectedTrain, mInf.predictedTrain] = obj.fit(train,param);
model.algorithm = class(obj);
Expand Down
2 changes: 0 additions & 2 deletions src/tests/singletests/liblinearTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
% Parameter C (Cost)
param.C = 0.10;

param.k = 0.10;

% Running the algorithm
info = algorithmObj.runAlgorithm(train,test,param);

Expand Down

0 comments on commit f184bb3

Please sign in to comment.