简体   繁体   中英

cosine similarity between two matrices

I have two arrays both of 256x256, the information within them have two different units (one is in meters and the other one is in degrees) when I plot them with a colormap the images look quite alike but I know that the information within them is totally different in both magnitude and units. Because the image looks like, I would like to calculate a percentage of how similar are they from one another. (I know it is vague to state it like that, but I am open for ideas on how to compare them)

So far I am using scikitlearn cosine_similarity function between the two matrices but I am having problems understanding what the resulting matrix means.

Which value represents then the similarity? Is there a better method to analyze both images? (images attached)

import numpy as np
import matplotlib.pyplot as plt
from sklearn import metrics


matrix_A=dataA #256x256 matrix 
matrix_B=dataB #256x256 matrix

sim_AB=metrics.pairwise.cosine_similarity(A,B) #Similarity matrix
plt.imshow(sim_AB)

数据A数据B

相似度矩阵

I believe cosine_similarity treats the matrices as features on columns and samples on rows (or the other way around). So it's like you're having 256 features and 256 samples (for each) and the result is a comparison between the features. Maybe scipy 's correlate2d is what you're looking for? That would compute the correlation between the two images. The higher the correlation, the more similar they are. Alternatively, you could define some metric and compute the distance, like <(AB)^2> but this makes less sense if the units are different.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM