
The test also works for distance matrices (in this case they have to have zeros on the main diagonal and all positive values, usually what you get out of the pdist command in matlab). I recommend the use of spearman correlation instead of pearson as a metric for comparing the two matrices. The following function performs a Mantel test between two similarity matrices and computes the p value using permutation tests. The most symple test to assess the statistical significance between a pair of simliarity matrices is the Mantel test. Then the simlarity matrix obtained for them is justįor example the similarity matrix could be an intersubject correlation matrix or a matrix from representational similarity analysis.
#PERMUTE FUNCTION MATLAB SERIES#
For example we could have N time series stored in MATLAB in a variable 'timeSeries'. Similarity matrices are symmetrical matrices where each element in the matrix denotes the amount of similarity between two pairs. The interesting point is that as you are using 2 rows of m to fill a colum of m_reshape, you are later on filling those “missing” colums with cat info creating this strange composition.Comparing two similarity (or dissimilarity/distance) matrices using mantel test That dimension corresponds to cat and basically has same effect. Obviously when dog image is finished, this is, when you have already used m it takes moves to m to keep taking pixels. You are basically taking dogs to create the image on the top left and then dogs to create image in the top right. That’s why you can see that streching efect on the image. The problem is that in m, in dimension 3 you have 1100 elements, meanwhile in dimension 2 of m_reshape you have 2200 elements, so it actually takes 2 rows from m to fill a row of m_reshape. So it is filling the row 0 of m_reshape with colum pixels from m. So when you reshape it takes pixels from dimensions at the right and places them until filling new shape dimensions In this composition you have a BatchxImagesxrowsxcolums Ĭontiguous here mens 1-2, 2-3 even 1-2-3, but not 1-3 for example. If you want to reshape the ordering only remains for contiguous dimensions. You achieve what you want which is all the colums of image 1, all the colums of image 2 However if u properly order the dimensions So it takes the information of the image1, colum 1, then image2, colum 1 and so on. Here you are filling taking the info of one image and then the other because u set N at the right. If you permute and set dimensions before reshaping If u pay attention it 's resized to be fit in the desired shape What’s going on there? as you are reordering it’s getting the information in the original order which is, all colums of image 1, all rows of image 1, all colums of image 2, all rows of image 2 and so on. If you just reshape you get a wrong ordering


The cat cropped looks like that (that’s grayscale) I’m converting RGB images to gray and croping to have same size Im2 = np.mean(skio.imread('/home/jfm/Downloads/cat.jpg'),axis=2) Im1 = np.mean(skio.imread('/home/jfm/Downloads/dog.jpg'),axis=2)

So lets see what happens if you reshape vs permute + reshape vs permute without paying attention
#PERMUTE FUNCTION MATLAB HOW TO#
So an example about how to apply view could be the following oneĪnd these tensor contains B batches of N images whose size is HxW and you want to make a montage of these images in a single one concatanating in the colums your outgoing dimension would be That’s why this operation is different from 0 It takes numbers until it fills the dimensions. On the other hand, if you reshape you can see you are modifying the ordering because this is not rotating the cube but mapping in an ordered way from right to left. You are just rotating the tensor, but order is preserved
