How can I use the princomp matlab function in the following case?

I have 10 images (18x18). I save these images inside an array called images[324][10] , where the number 324 represents the number of pixels for the image and the number 10 represents the total number of images that I have.

I would like to use these images for a network of neurons, however 324 is a large number that can be specified as input, and therefore I would like to reduce this number, but save as much information as possible.

I heard that you can do this with the princomp function, which implements PCA.

The problem is that I did not find any example on how to use this function, and especially for my case.

If I run

 [COEFF, SCORE, latent] = princomp(images); 

It works fine, but how can I get the array newimages[number_of_desired_features][10] ?

+4
source share
1 answer

PCA may be the right choice here (but not the only one). Although, you should be aware that the PCA does not automatically reduce the amount of your input. I recommend you read this tutorial: http://arxiv.org/pdf/1404.1100v1.pdf is the one I used to understand the PCA and its really good for beginners.

Returning to your question. An image is a vector in 324-dimensional space. In this space, the first base vector is one that has a white pixel in the upper left corner, the next is the next white pixel, all the other black ones, and so on. This is probably not the best set of basic vectors to represent this image data. The PCA computes new base vectors (COEFF matrix โ€” new vectors expressed as values โ€‹โ€‹in the old vector space) and new image vector values โ€‹โ€‹(SCORE matrix). At this point, you have not lost ANY data at all (without reducing the number of numbers). But you can stop using some of the new base vectors because they are probably related to noise, not the data itself. All this is described in detail in the textbook.

 images = rand(10,324); [COEFF, SCORE] = princomp(images); reconstructed_images = SCORE / COEFF + repmat(mean(images,1), 10, 1); images - reconstructed_images %as you see there are almost only zeros - the non-zero values are effects of small numerical errors %its possible because you are only switching between the sets of base vectors used to represent the data for i=100:324 SCORE(:,i) = zeros(10,1); end %we remove the features 100 to 324, leaving only first 99 %obviously, you could take only the non-zero part of the matrix and use it %somewhere else, like for your neural network reconstructed_images_with_reduced_features = SCORE / COEFF + repmat(mean(images,1), 10, 1); images - reconstructed_images_with_reduced_features %there are less features, but reconstruction is still pretty good 
+5
source

Source: https://habr.com/ru/post/1446636/


All Articles