1
votes

I've written a Matlab script for classification. When I execute this I'm getting Out Of Memory error.

for i =1:size(Y)  
    if(predictions(i) ~= clasL(find(ismember(mydata,X(i)),'rows')))  
        error = error+1;  
    end  
end

In the above code Y and predictions are vectors of dimension 19928. And mydata and X are 19928*62061 and 12819*62061 matrices. When I execute the following code I'm getting the following error

Error using  == 
Out of memory. Type HELP MEMORY for your options.

Error in ismember (line 62)
            tf = (a == s);

Error in myinit (line 105)
if(predictions(i) ~= clasL(find(ismember(mydata,X(i)),1)))

How to overcome this? Please help me. Thanks

1
Is clasL your own custom function? It's difficult or impossible to modify and fix the code to solve the memory issue without knowing what function clasL does. Could you edit your question and include the code of clasL function in it? - nrz
Sorry. clasL is another vector of dimension 19928. Basically clasL contains original class label and predictions contains predicted class label. - Rudra Murthy

1 Answers

1
votes

First try running ulimit on the MATLAB process so it can use as much memory as is available.

Second, I think you want to switch the order of arguments to ismember:

ismember(X(i, :), mydata, 'rows')

Third, you don't need the extra find function if you change the order of arguments. You would then simply do this (inside the loop):

[~, idx] = ismember(X(i, :), mydata, 'rows')
if (idx > 0 && predictions(i) ~= clasL(idx))
    error = error+1;  
end 

Fourth, to save on time, you can run ismember just once for all the rows in X (no loop) and then find the number of errors in a vectorized manner:

[~, idxs] = ismember(X, mydata, 'rows')
error = sum(predictions(idxs > 0) ~= clasL(idxs > 0))