covartech / PRT

Pattern Recognition Toolbox for MATLAB
http://covartech.github.io/
MIT License
145 stars 70 forks source link

k-folds breaking with R2011b #21

Closed giuliano0 closed 11 years ago

giuliano0 commented 11 years ago

Hello,

My Matlab version is R2011b and I updated my working copy of PRT last week. This broke a well used script I have to k-fold a dataset. Here is the output:

Error using union (line 107) Unknown flag. Error in prtUtilIntegerAssociativeArray/merge (line 104) [unionKeys,ind1,ind2] = union(keys1,keys2,'R2012a'); % Bug fix 2013-06-13 Error in prtUtilIntegerAssociativeArrayClassNames/merge (line 29) temp = merge@prtUtilIntegerAssociativeArray(self,other); Error in prtUtilIntegerAssociativeArray/combine (line 87) out = merge(self,in2); Error in prtDataInterfaceCategoricalTargets/catClasses (line 318) [self.classNamesArray,integerSwaps] = combine(self.classNamesArray,ds.classNamesArray); Error in prtDataSetClass/catObservations (line 170) self = catClasses(self,varargin{:}); Error in prtDataSetBase/crossValidateCombineFoldResults (line 406) dsOut = catObservations(dsTestCell{:}); Error in prtDataSetStandard/crossValidateCombineFoldResults (line 627) dsOut = crossValidateCombineFoldResults@prtDataSetBase(dsTestCell_first, dsTestCell, testIndices); Error in prtAction/crossValidate (line 387) dsOut = crossValidateCombineFoldResults(outputDataSetCell{1}, outputDataSetCell, testingIndiciesCell); Error in prtAction/kfolds (line 433) [outputs{:}] = self.crossValidate(ds,keys); Error in svm_one_vs_one (line 36) crossvalout = classifier.kfolds(dataset, 2);

And this is the code causing the issue:

classifier = prtClassLibSvm; classifier.internalDecider = prtDecisionBinaryMinPe; crossvalout = classifier.kfolds(dataset, 2);

Thanks in advance.

peterTorrione commented 11 years ago

Hello,

This looks like a MATLAB version issue; the MathWorks changed the way Union worked in 2012B, and now to get the old behavior we need to send a special flag: What used to read:

[unionKeys,ind1,ind2] = union(keys1,keys2);

now reads:

[unionKeys,ind1,ind2] = union(keys1,keys2,'R2012a'); % Bug fix 2013-06-13

Of course, old versions of UNION don't know about the 'R2012a' flag.

I think the following code will fix it:

        %Backwards compatible bug-fix; 2013.08.11
        s = ver('matlab');
        versionNum = str2double(s.Version);
        if versionNum >= 8
            [unionKeys,ind1,ind2] = union(keys1,keys2,'R2012a'); % Bug fix 2013-06-13
        else
            [unionKeys,ind1,ind2] = union(keys1,keys2);
        end

These changes have been committed, but we cannot really test since we don't have versions of MATLAB that old. We know that they work on newer versions of MATLAB, though.

Also, note that the PRT currently supports versions of MATLAB since 2010, but that will change soon - we may begin supporting only the most recent 1 year of MATLAB releases soon.

peterTorrione commented 11 years ago

Please let us know if the proposed modification didn't help!