Statistics and matrix algebra in Ruby

I need to invert the variance-covariance matrix in Ruby and vector by matrix multiplication. Which Ruby / Gem Digital Library should I use?

+5
source share
4 answers

Try using the "matrix" library:

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

A numerically more stable feature than direct inversion is to use the Cholesky decomposition with the package, which you will 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, use the method described in the wikpedia article above.

, , .

+3

If you can compile the code, use ruby-gsl

gem install gsl

The inverse can be obtained using the LU module

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

+3
source

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

0
source

All Articles