开发者

Sparse Matrix/ Inner Matrix Dimension

开发者 https://www.devze.com 2023-02-12 21:30 出处:网络
Well, Trying to do something with search engines. I have generated a matrix (term-document) from a collection of 5 documents. The output is:

Well, Trying to do something with search engines.

I have generated a matrix (term-document) from a collection of 5 documents. The output is:

docs= (5,1) 1.0000 (1,2) 0.7071 (3,2) 0.7071 (1,3) 0.7071 (5,3) 0.7071 (3,4) 1.0000 (4,5) 1.0000

Also, I have generated a query matrix from user query.

q= (1,1) 1 (2,1) 1

I'm trying to find similarity of the document set with the user's query ap开发者_如何学JAVAplying Vector space modelling. Here goes the code:

% docs is a sprase matrix presenting a number of document.
sc=zeros(1, n); doc_inds=zeros(1, n);

% q is the user query. 
sc=q'*docs;

%sort documents according to their
similarity coefficient with the query
[sc, doc_inds]=sort(sc);
sc=sc(end:-1:1);doc_inds=doc_inds(end:-1:1);

The line sc=q'*docs; always produces error saying: ??? Inner matrix dimensions must . agree.

Can anyone help me getting an idea to deal with it ? Appreciate your time.


According to the data in your example, docs is 5x5 and q is 2x1. The matrix multiplication q'*docs is attempting to multiply a 1x2 matrix with a 5x5 matrix. Matrix multiplication requires that the second dimension of the first matrix agrees with the first dimension of the second matrix, thus the error you are getting.

Why are you defining sc at the line sc=zeros(1, n); and then overwriting it with this matrix multiplication?

0

精彩评论

暂无评论...
验证码 换一张
取 消