稀疏矩阵/内矩阵维数
好吧,尝试用搜索引擎做点什么。
我从 5 个文档的集合中生成了一个矩阵(术语文档)。输出为:
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
此外,我还根据用户查询生成了一个查询矩阵。
q= (1,1) 1 (2,1) 1
我试图通过应用向量空间建模来查找文档集与用户查询的相似性。代码如下:
% 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);
sc=q'*docs;
行总是产生错误:???内部矩阵尺寸必须。 同意。
任何人都可以帮我想出解决这个问题的办法吗?珍惜您的时间。
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 applying 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据示例中的数据,
docs
为 5x5,q
为 2x1。矩阵乘法q'*docs
尝试将 1x2 矩阵与 5x5 矩阵相乘。矩阵乘法要求第一个矩阵的第二个维度与第二个矩阵的第一个维度一致,因此您会得到错误。为什么要在
sc=zeros(1, n);
行定义sc
,然后用这个矩阵乘法覆盖它?According to the data in your example,
docs
is 5x5 andq
is 2x1. The matrix multiplicationq'*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 linesc=zeros(1, n);
and then overwriting it with this matrix multiplication?