PHP中的奇异值分解(SVD) [英] Singular Value Decomposition (SVD) in PHP

查看:116
本文介绍了PHP中的奇异值分解(SVD)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在PHP中实现奇异值分解(SVD).我知道有几个外部库可以为我做这件事.但是我有两个关于PHP的问题: 1)您认为用PHP编码SVD是否可能和/或合理? 2)如果(1)是:您能帮我用PHP编写代码吗?

I would like to implement Singular Value Decomposition (SVD) in PHP. I know that there are several external libraries which could do this for me. But I have two questions concerning PHP, though: 1) Do you think it's possible and/or reasonable to code the SVD in PHP? 2) If (1) is yes: Can you help me to code it in PHP?

我已经自己编码了SVD的某些部分. 这里是代码,我在其中对操作过程进行了评论.某些部分这段代码并不完全正确.

I've already coded some parts of SVD by myself. Here's the code which I made comments to the course of action in. Some parts of this code aren't completely correct.

如果您能帮助我,那就太好了.提前非常感谢您!

It would be great if you could help me. Thank you very much in advance!

推荐答案

SVD-python 是SVD的非常清晰,简约的实现. 它实际上是伪代码,应该相当容易理解 并比较/借鉴您的php实现,即使您不太了解python.

SVD-python Is a very clear, parsimonious implementation of the SVD. It's practically psuedocode and should be fairly easy to understand and compare/draw on for your php implementation, even if you don't know much python.

SVD-python

这就是说,正如其他人提到的那样,我不希望能够通过php实现来完成非常重型的LSA,这听起来像是一个相当有限的Web主机.

That said, as others have mentioned I wouldn't expect to be able to do very heavy-duty LSA with php implementation what sounds like a pretty limited web-host.

欢呼

上面的模块本身并不能做任何事情,但是其中包含一个示例 开头的评论.假设您下载了python模块,并且该模块可访问(例如,在同一文件夹中),则您 可以实现一个简单的示例,

The module above doesn't do anything all by itself, but there is an example included in the opening comments. Assuming you downloaded the python module, and it was accessible (e.g. in the same folder), you could implement a trivial example as follow,

#!/usr/bin/python
import svd
import math

a = [[22.,10., 2.,  3., 7.],
     [14., 7.,10.,  0., 8.],
     [-1.,13.,-1.,-11., 3.],
     [-3.,-2.,13., -2., 4.],
     [ 9., 8., 1., -2., 4.],
     [ 9., 1.,-7.,  5.,-1.],
     [ 2.,-6., 6.,  5., 1.],
     [ 4., 5., 0., -2., 2.]]

u,w,vt = svd.svd(a)
print w

此处'w'包含您的奇异值列表.
当然,这只会使您成为潜在语义分析及其亲属的一部分. 通常,您需要减少奇异值的数量,然后采用一些适当的距离 度量文档,单词或文档和单词等之间的相似性的指标. 合成矢量之间的角度的余弦值很受欢迎.

Here 'w' contains your list of singular values.
Of course this only gets you part of the way to latent semantic analysis and its relatives. You usually want to reduce the number of singular values, then employ some appropriate distance metric to measure the similarity between your documents, or words, or documents and words, etc. The cosine of the angle between your resultant vectors is pretty popular.

潜在语义映射(pdf)

到目前为止,我已经阅读了关于您其余步骤的最清晰,最简洁和最有启发性的论文 需要按照SVD进行锻炼.

is by far the clearest, most concise and informative paper I've read on the remaining steps you need to work out following the SVD.

Edit2:还请注意,如果您要处理非常大的长期文档矩阵(我假设这是 是您正在做的事情)执行分解几乎肯定会更有效率 在脱机模式下,然后仅响应于请求以实时方式执行比较. 尽管svd-python非常适合学习,但svdlibc更适合您这么繁重的工作 计算.

also note that if you're working with very large term-document matrices (I'm assuming this is what you are doing) it is almost certainly going to be far more efficient to perform the decomposition in an offline mode, and then perform only the comparisons in a live fashion in response to requests. while svd-python is great for learning, the svdlibc is more what you would want for such heavy computation.

最后,如上面的bellegarda文件所述,请记住,您不必重新计算 每次获取新文档或请求时都使用svd.取决于您要做什么 大概每星期左右执行一次svd就可以了,在离线模式下,在本地计算机上, 然后上传结果(尽管有大小/带宽问题).

finally as mentioned in the bellegarda paper above, remember that you don't have to recompute the svd every single time you get a new document or request. depending on what you are trying to do you could probably get away with performing the svd once every week or so, in an offline mode, a local machine, and then uploading the results (size/bandwidth concerns notwithstanding).

无论如何,祝你好运!

这篇关于PHP中的奇异值分解(SVD)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆