Ruby 中的统计和矩阵代数

发布于 2024-07-23 23:56:30 字数 63 浏览 9 评论 0原文

我需要在 Ruby 中求逆方差-协方差矩阵,并通过矩阵乘法求向量。 我应该使用哪个数值 Ruby 库/Gem?

I need to inverse a variance-covariance matrix in Ruby and vector by matrix multiplication. Which numerical Ruby library/Gem should I use?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

╰◇生如夏花灿烂 2024-07-30 23:56:30

比直接反演在数值上更稳定的可能性是对您找到的包使用 Cholesky 分解 < a href="http://www.approximity.com/public/download/code.html" rel="nofollow noreferrer">此处:

require 'Cholesky.rb'
require 'pp'
# m is the covariance matrix you want to invert (it is positive semidefinite)
l = m.cholesky
li = l.inverse
lit = li.transpose
# lit*li is approximately the inverse and the next line shows this
pp lit*li*m

比反转 l 更好的是使用链接的维基百科文章中描述的方法多于。

如果您的问题在数值上太不稳定,请考虑奇异值分解,但我没有其代码。

A numerically more stable possibility than direct inversion is to use a Cholesky decomposition with the package you find here:

require 'Cholesky.rb'
require 'pp'
# m is the covariance matrix you want to invert (it is positive semidefinite)
l = m.cholesky
li = l.inverse
lit = li.transpose
# lit*li is approximately the inverse and the next line shows this
pp lit*li*m

Better than inverting l is to use the method described in the wikpedia article linked above.

If your problem is numerically too unstable then consider the Singular Value Decomposition, but I don't have code for it.

人心善变 2024-07-30 23:56:30

如果可以编译代码,请使用 ruby​​-gsl

gem install gsl

可以使用 LU 模块获得逆矩阵

inverse=GSL::Linalg::LU.invert(matrix)

If you can compile code, use ruby-gsl

gem install gsl

The inverse can be obtained using LU module

inverse=GSL::Linalg::LU.invert(matrix)

半透明的墙 2024-07-30 23:56:30

尝试使用“矩阵”库:

http://www.ruby-doc.org/stdlib/libdoc/matrix/rdoc/index.html

Try using the 'matrix' library:

http://www.ruby-doc.org/stdlib/libdoc/matrix/rdoc/index.html
素手挽清风 2024-07-30 23:56:30

NMatrix。 支持各种操作,包括 BLAS 和 LAPACK(通过使用 ATLAS)的一些操作。

There is NMatrix. There is support for various operations, including some from BLAS and LAPACK (by using ATLAS).

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