Covariance function - Out of memory











up vote
0
down vote

favorite












I am trying to perform PCA on the MNIST data set. I have the following code so far.



...load data into MATLAB

% Centre data matrix
imagesMean = mean(images);
imagesShifted = images - imagesMean;

% Compute covariance matrix of mean shifted images
covariance = cov(imagesShifted);


Trying to do this gives me the following response:




Out of memory. Type "help memory" for your options.



Error in cov (line 155) c = (xc' * xc) ./ denom;



Error in PCA (line 27) covariance = cov(imagesShifted);




imagesShifted is a 784x60000 double matrix.



I am using a MacBook Pro 2015 with 16GB RAM and a 2.8 GHz processor and a dedicated graphics card.



I looked under the help menu for the memory command but the information only seems relevant to Windows machines. Also looked at the MathWorks website for resolving out of memory issues but wasn't sure how to proceed based on that information.



How can I get around this issue?










share|improve this question


















  • 1




    Do you need a 60,000x60,000 matrix out or a 784x784 matrix out? If so you'll need to transpose your matrix before you put into the covariance function. Also, MATLAB has a dedicated pca function mathworks.com/help/stats/pca.html
    – Durkee
    Nov 4 at 13:41















up vote
0
down vote

favorite












I am trying to perform PCA on the MNIST data set. I have the following code so far.



...load data into MATLAB

% Centre data matrix
imagesMean = mean(images);
imagesShifted = images - imagesMean;

% Compute covariance matrix of mean shifted images
covariance = cov(imagesShifted);


Trying to do this gives me the following response:




Out of memory. Type "help memory" for your options.



Error in cov (line 155) c = (xc' * xc) ./ denom;



Error in PCA (line 27) covariance = cov(imagesShifted);




imagesShifted is a 784x60000 double matrix.



I am using a MacBook Pro 2015 with 16GB RAM and a 2.8 GHz processor and a dedicated graphics card.



I looked under the help menu for the memory command but the information only seems relevant to Windows machines. Also looked at the MathWorks website for resolving out of memory issues but wasn't sure how to proceed based on that information.



How can I get around this issue?










share|improve this question


















  • 1




    Do you need a 60,000x60,000 matrix out or a 784x784 matrix out? If so you'll need to transpose your matrix before you put into the covariance function. Also, MATLAB has a dedicated pca function mathworks.com/help/stats/pca.html
    – Durkee
    Nov 4 at 13:41













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am trying to perform PCA on the MNIST data set. I have the following code so far.



...load data into MATLAB

% Centre data matrix
imagesMean = mean(images);
imagesShifted = images - imagesMean;

% Compute covariance matrix of mean shifted images
covariance = cov(imagesShifted);


Trying to do this gives me the following response:




Out of memory. Type "help memory" for your options.



Error in cov (line 155) c = (xc' * xc) ./ denom;



Error in PCA (line 27) covariance = cov(imagesShifted);




imagesShifted is a 784x60000 double matrix.



I am using a MacBook Pro 2015 with 16GB RAM and a 2.8 GHz processor and a dedicated graphics card.



I looked under the help menu for the memory command but the information only seems relevant to Windows machines. Also looked at the MathWorks website for resolving out of memory issues but wasn't sure how to proceed based on that information.



How can I get around this issue?










share|improve this question













I am trying to perform PCA on the MNIST data set. I have the following code so far.



...load data into MATLAB

% Centre data matrix
imagesMean = mean(images);
imagesShifted = images - imagesMean;

% Compute covariance matrix of mean shifted images
covariance = cov(imagesShifted);


Trying to do this gives me the following response:




Out of memory. Type "help memory" for your options.



Error in cov (line 155) c = (xc' * xc) ./ denom;



Error in PCA (line 27) covariance = cov(imagesShifted);




imagesShifted is a 784x60000 double matrix.



I am using a MacBook Pro 2015 with 16GB RAM and a 2.8 GHz processor and a dedicated graphics card.



I looked under the help menu for the memory command but the information only seems relevant to Windows machines. Also looked at the MathWorks website for resolving out of memory issues but wasn't sure how to proceed based on that information.



How can I get around this issue?







matlab statistics pca covariance






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 4 at 9:47









Sithling

305110




305110








  • 1




    Do you need a 60,000x60,000 matrix out or a 784x784 matrix out? If so you'll need to transpose your matrix before you put into the covariance function. Also, MATLAB has a dedicated pca function mathworks.com/help/stats/pca.html
    – Durkee
    Nov 4 at 13:41














  • 1




    Do you need a 60,000x60,000 matrix out or a 784x784 matrix out? If so you'll need to transpose your matrix before you put into the covariance function. Also, MATLAB has a dedicated pca function mathworks.com/help/stats/pca.html
    – Durkee
    Nov 4 at 13:41








1




1




Do you need a 60,000x60,000 matrix out or a 784x784 matrix out? If so you'll need to transpose your matrix before you put into the covariance function. Also, MATLAB has a dedicated pca function mathworks.com/help/stats/pca.html
– Durkee
Nov 4 at 13:41




Do you need a 60,000x60,000 matrix out or a 784x784 matrix out? If so you'll need to transpose your matrix before you put into the covariance function. Also, MATLAB has a dedicated pca function mathworks.com/help/stats/pca.html
– Durkee
Nov 4 at 13:41












1 Answer
1






active

oldest

votes

















up vote
1
down vote













For large data sets, I suggest you to use the princomp function of matlab, with the flag 'econ' activated.



https://es.mathworks.com/help/stats/princomp.html



Or the pca function with the flag 'economy' or indicating the 'NumComponents' you wish.



https://es.mathworks.com/help/stats/pca.html






share|improve this answer








New contributor




Sergio is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


















  • princomp has been removed
    – Durkee
    2 days ago











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53139501%2fcovariance-function-out-of-memory%23new-answer', 'question_page');
}
);

Post as a guest
































1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote













For large data sets, I suggest you to use the princomp function of matlab, with the flag 'econ' activated.



https://es.mathworks.com/help/stats/princomp.html



Or the pca function with the flag 'economy' or indicating the 'NumComponents' you wish.



https://es.mathworks.com/help/stats/pca.html






share|improve this answer








New contributor




Sergio is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


















  • princomp has been removed
    – Durkee
    2 days ago















up vote
1
down vote













For large data sets, I suggest you to use the princomp function of matlab, with the flag 'econ' activated.



https://es.mathworks.com/help/stats/princomp.html



Or the pca function with the flag 'economy' or indicating the 'NumComponents' you wish.



https://es.mathworks.com/help/stats/pca.html






share|improve this answer








New contributor




Sergio is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


















  • princomp has been removed
    – Durkee
    2 days ago













up vote
1
down vote










up vote
1
down vote









For large data sets, I suggest you to use the princomp function of matlab, with the flag 'econ' activated.



https://es.mathworks.com/help/stats/princomp.html



Or the pca function with the flag 'economy' or indicating the 'NumComponents' you wish.



https://es.mathworks.com/help/stats/pca.html






share|improve this answer








New contributor




Sergio is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









For large data sets, I suggest you to use the princomp function of matlab, with the flag 'econ' activated.



https://es.mathworks.com/help/stats/princomp.html



Or the pca function with the flag 'economy' or indicating the 'NumComponents' you wish.



https://es.mathworks.com/help/stats/pca.html







share|improve this answer








New contributor




Sergio is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this answer



share|improve this answer






New contributor




Sergio is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









answered Nov 4 at 18:21









Sergio

613




613




New contributor




Sergio is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Sergio is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Sergio is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • princomp has been removed
    – Durkee
    2 days ago


















  • princomp has been removed
    – Durkee
    2 days ago
















princomp has been removed
– Durkee
2 days ago




princomp has been removed
– Durkee
2 days ago


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53139501%2fcovariance-function-out-of-memory%23new-answer', 'question_page');
}
);

Post as a guest




















































































這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini