稀疏矩阵/内矩阵维数

发布于 2024-10-19 03:12:28 字数 754 浏览 0 评论 0原文

好吧,尝试用搜索引擎做点什么。

我从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情话墙 2024-10-26 03:12:28

根据示例中的数据,docs 为 5x5,q 为 2x1。矩阵乘法 q'*docs 尝试将 1x2 矩阵与 5x5 矩阵相乘。矩阵乘法要求第一个矩阵的第二个维度与第二个矩阵的第一个维度一致,因此您会得到错误。

为什么要在 sc=zeros(1, n); 行定义 sc ,然后用这个矩阵乘法覆盖它?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文