Setting precision in Ruby-GSL calculations?

Dear all,

I’d like to use ruby-gsl for some singular value decompositions, i.e.
a matrix m should be decomposed into a product of three matrices,

m=usv.transposed,

now,as the documentation says that this algorithm is not implemented
if the dimensions of m (m1 x m2) are such that m1<m2, I’ve implemented
my own version, re-reading some long-forgotten linear algebra book.
In the process, I need to find the eigenvectors and the eigenvalues of
m*m.transposed,
but these are printed out and apparently also calculated only to three
decimal digits
by the command

 eigval, eigvec =  Eigen::symmv(m*m.transposed).

This causes the matrix u, which is constructed from the values eigval,
to have quite strange values for its determinant (I get values of
1.06,
0.96 for uu.transpose.det, but u is unitary by definition, i.e.,
u
u.transpose.det=1).

Then, of course, m isn’t remotely equal to usv.transposed …

Is there a way of setting the precision of the eigenvalue and
eigenvector
calculations
any higher ?

Thank you very much,

Best regards,

Axel

[email protected] wrote:

In the process, I need to find the eigenvectors and the eigenvalues of
u*u.transpose.det=1).
Best regards,

Axel

If m = usv.transposed, what does m.transposed equal? Isn’t it
m.transposed = vs.transposedu.transposed?

In other words, can you transpose m … m.transposed has dimensions m2 x
m1 … and take the SVD of m.transposed, and then recover the SVD of m
from that?

I’ve forgotten most of my computational linear algebra too. :slight_smile:

By the way, how large are m1 and m2?

Hi,

I’d like to use ruby-gsl for some singular value decompositions, i.e.
Which library do you use? There are two extensions,
ruby-gsl and rb-gsl(Ruby/GSL).

ruby-gsl http://ruby-gsl.sourceforge.net/
rb-gsl (Ruby/GSL) http://rubyforge.org/projects/rb-gsl/

but these are printed out and apparently also calculated only to three
decimal digits
If you use Ruby/GSL, this is just because
matrices are displayed with the printf format
%4.3e, not because of precision. You can get
more significant figures by displaying elements
as m[0][1].

by the command

 eigval, eigvec =  Eigen::symmv(m*m.transposed).

This causes the matrix u, which is constructed from the values
eigval,
to have quite strange values for its determinant (I get values of
1.06,
0.96 for uu.transpose.det, but u is unitary by definition, i.e.,
u
u.transpose.det=1).
Is it unitary? Isn’t it an orthogonal matrix?

Then, of course, m isn’t remotely equal to usv.transposed …

The following is rb-gsl(Ruby/GSL) outputs.

irb(main):001:0> require(“gsl”)
=> true
irb(main):002:0> m = GSL::Matrix[[10, 5, -10], [2, -11, 10]].trans
=> GSL::Matrix
[ 1.000e+01 2.000e+00
5.000e+00 -1.100e+01
-1.000e+01 1.000e+01 ]
irb(main):003:0> u, v, s = m.SV_decomp
=> [GSL::Linalg::SV::UMatrix
[ -2.981e-01 8.944e-01
-5.963e-01 -4.472e-01
7.454e-01 5.356e-17 ], GSL::Linalg::SV::VMatrix
[ -7.071e-01 7.071e-01
7.071e-01 7.071e-01 ], GSL::Linalg::SV::SingularValues
[ 1.897e+01 9.487e+00 ]]
irb(main):004:0> u.transu (U is orthogonal)
=> GSL::Matrix
[ 1.000e+00 1.408e-16
1.408e-16 1.000e+00 ]
irb(main):005:0> v
v.trans (V is also orthogonal)
=> GSL::Matrix
[ 1.000e+00 -1.015e-17
-1.015e-17 1.000e+00 ]
irb(main):006:0> u*Matrix.diagonal(s)*v.trans
=> GSL::Matrix (Reconstruct m)
[ 1.000e+01 2.000e+00
5.000e+00 -1.100e+01
-1.000e+01 1.000e+01 ]

Is this what you expect?

Yoshiki

[email protected] wrote:

[snip]

Is this what you expect?

Yoshiki
R and Ruby/GSL agree … that’s a good sign they’re both right. :slight_smile:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs