[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Ruby as mathematical language

none

7/7/2005 3:46:00 PM

Hi Ruby world.

I am attaching some pieces of an email conversation I had with Yoshiki
Tsunesada regarding his excellent work rb-gsl. I wanted to start a
discussion about what extensions would make Ruby an intuitive and
powerful math language; I think he has already laid the foundation,
but there are some important pieces that we could add, especially in
the realm of indexing and assigning to matrices (and possibly in the
realm of graphics too). Feel free to comment :)

**********

Yoshiki said:

As mentioned in ruby-talk, by Nobu Nakada, the C coding
in Ruby/GSL seems to be somewhat "old-fashioned". My excuse
is that I studied Ruby-C API in ruby-1.4 ages, and I just
followed a "framework" explained in a Ruby textbook
written in that days. I have not followed the current
framework, although I still don't know what is the
"franework".
Because of this, it is impossible to create a subclass
of a Ruby/GSL class in a Ruby script, while still possible
in C. The definition of the singleton method "new" in C
is the problem, but I don't know how to improve it
(for all the classes in Ruby/GSL). Sorry for inconvenience.
This problem must be improved in a future version of Ruby/GSL,
to be extensible easily from Ruby, not from C.

You can still implement your new interfaces using C API,
but you may not prefer it. If you show all your requests
you want to do in Ruby/GSL, I will code them in C. I want
to put aside the framework problem for a while, since
it is rather messy to change the coding all for the classes.
********
I replied:

I wish I was a better programmer and could implement my extensions in
ruby-gsl's C.

My extensions involve array indexing and assignment, but if you are
interested in improving the usability of rb-gsl, you might want to look
at Octave (http://www....) which is kind of a gnu matlab.
S-Plus/R (http://r-p...) is also a good model, though not as
good in my opinion as Matlab/Octave.

It seems to me the numerical part of rb-gsl is fantastic, but I am
often faced with assembling and dissassembling large (100 x 1000)
matrices, usually composed of lots of submatrices, and rb-gsl makes
that a little hard compared to other more mathematically oriented
languages. The problem with Octave and R though, is that they are quite
limited for general programming, while Ruby is amazing. So if you want
do some big numerical work and put it online, you are stuck.

As for recoding rb-gsl in a new framework, it might be worth waiting
until Ruby 2 is out? I wonder.

I am compiling Octave right now, and I will send you some examples of
what I am interested in being able to do after I have it working.

26 Answers

ptkwt

7/7/2005 4:44:00 PM

0

In article <1120751187.861412.229850@g49g2000cwa.googlegroups.com>,
none <webb.sprague@gmail.com> wrote:
>Hi Ruby world.
>
>I am attaching some pieces of an email conversation I had with Yoshiki
>Tsunesada regarding his excellent work rb-gsl. I wanted to start a
>discussion about what extensions would make Ruby an intuitive and
>powerful math language; I think he has already laid the foundation,
>but there are some important pieces that we could add, especially in
>the realm of indexing and assigning to matrices (and possibly in the
>realm of graphics too). Feel free to comment :)
>
>**********
>
>Yoshiki said:
>
>As mentioned in ruby-talk, by Nobu Nakada, the C coding
>in Ruby/GSL seems to be somewhat "old-fashioned". My excuse
>is that I studied Ruby-C API in ruby-1.4 ages, and I just
>followed a "framework" explained in a Ruby textbook
>written in that days. I have not followed the current
>framework, although I still don't know what is the
>"franework".
> Because of this, it is impossible to create a subclass
>of a Ruby/GSL class in a Ruby script, while still possible
>in C. The definition of the singleton method "new" in C
>is the problem, but I don't know how to improve it
>(for all the classes in Ruby/GSL). Sorry for inconvenience.
>This problem must be improved in a future version of Ruby/GSL,
>to be extensible easily from Ruby, not from C.
>
> You can still implement your new interfaces using C API,
>but you may not prefer it. If you show all your requests
>you want to do in Ruby/GSL, I will code them in C. I want
>to put aside the framework problem for a while, since
>it is rather messy to change the coding all for the classes.
>********
>I replied:
>
>I wish I was a better programmer and could implement my extensions in
>ruby-gsl's C.
>
>My extensions involve array indexing and assignment, but if you are
>interested in improving the usability of rb-gsl, you might want to look
>at Octave (http://www....) which is kind of a gnu matlab.
>S-Plus/R (http://r-p...) is also a good model, though not as
>good in my opinion as Matlab/Octave.
>
> It seems to me the numerical part of rb-gsl is fantastic, but I am
>often faced with assembling and dissassembling large (100 x 1000)
>matrices, usually composed of lots of submatrices, and rb-gsl makes
>that a little hard compared to other more mathematically oriented
>languages. The problem with Octave and R though, is that they are quite
>limited for general programming, while Ruby is amazing. So if you want
>do some big numerical work and put it online, you are stuck.
>
>As for recoding rb-gsl in a new framework, it might be worth waiting
>until Ruby 2 is out? I wonder.
>
>I am compiling Octave right now, and I will send you some examples of
>what I am interested in being able to do after I have it working.
>


Regarding your comments about rb-gsl; have you looked at narray? I've
not used rb-gsl, but it's been on my list.

As far as using Ruby as a mathematical language something like MatLab:
That would be very nice. Given that it's quite easy to create DSLs using
Ruby one would think it should be possible to create something that would
give MatLab a run for it's money (I really don't like MatLab as a
langauge). Also consider that you need to tightly integrate graphing
(perhaps through gnuplot?).

Phil

Ara.T.Howard

7/7/2005 5:22:00 PM

0

none

7/7/2005 5:51:00 PM

0

Regarding Narray, it seems kind of cool, but lacking in real
mathematical sophistication. I think it would be better to extend
rb-gsl to make composing matrices easier and thus keep the excellent
linear algebra facilities. Really, I think Narray and rb-gsl have a
lot of redundancy and I really don't like bouncing between the two of
them.

Regarding graphics, matplotlib for python rocks, I wonder if it can be
ported....

The basics are all around, the problem is designing an intuitive one
stop shop that is really usable. Being able to hack something out of
gnuplot is not the same as having a well put together
framework/library....

Ara.T.Howard

7/7/2005 6:08:00 PM

0

Steven Jenkins

7/7/2005 6:26:00 PM

0

Phil Tomson wrote:
> none <webb.sprague@gmail.com> wrote:
>>I wish I was a better programmer and could implement my extensions in
>>ruby-gsl's C.

One option would be to reimplement rb-gsl using SWIG. GSL is pretty big,
but wrapping it with SWIG might not be too hard if its interfaces are
implemented using a small number of types. You have to write two or
three typemaps for each type, and SWIG does the rest.

I've wrapped two libraries with SWIG. and while I don't consider myself
an expert, I have learned a few things. I'd be willing to help get
things kicked off.

One thing to bear in mind, however. Wrapping (whether with SWIG or not)
often requires copying input and output parameters. That's usually not a
big deal, but you might take a substantial performance hit if you're
passing large numbers of large arrays through a wrapper.

>>[snip]
>
> As far as using Ruby as a mathematical language something like MatLab:
> That would be very nice. Given that it's quite easy to create DSLs using
> Ruby one would think it should be possible to create something that would
> give MatLab a run for it's money (I really don't like MatLab as a
> langauge). Also consider that you need to tightly integrate graphing
> (perhaps through gnuplot?).

Much of the value of Matlab is not the language itself, but the large
number of libraries available for specialized applications like control
systems and signal processing. That's much harder to replace than the
underlying execution engine. (Which is, of course, part of the reason
Fortran is still with us.)

Steve



Paulo Jabardo

7/7/2005 6:32:00 PM

0

I'm new to ruby and I intend to use ruby to do
scientific data acquisition and a little processing. I
am very interested in mathematical libraries for ruby.

I just took looked at narray and it seems very nice. I
think we should be careful with gsl's matrix
capabilities. It was designed to provide dynamic
matrices to C. In dynamic labguages like ruby we could
do things differently providing much more flexibility.
With a contiguous block of memory it should not be
very difficult to write a thin interface so that
narray, for instance, could be used in gsl's linear
algebra procedures (if I remember correctly gsl
provides something like that - generate a matrix from
a memory block).

For ruby to be used as mathematical language I think
it is important to standardize on a single array
library that uses ruby's qualities to its full extent

Mathplotlib really looks amazing. If porting is
possible ruby would have a really nice graphics
capabilities.

Paulo


--- "Ara.T.Howard" <Ara.T.Howard@noaa.gov> escreveu:

> On Fri, 8 Jul 2005, none wrote:
>
> > Regarding Narray, it seems kind of cool, but
> lacking in real
> > mathematical sophistication. I think it would be
> better to extend
> > rb-gsl to make composing matrices easier and thus
> keep the excellent
> > linear algebra facilities. Really, I think Narray
> and rb-gsl have a
> > lot of redundancy and I really don't like bouncing
> between the two of
> > them.
>
> can you give an example of something you'd like to
> do but can't?
>
> > Regarding graphics, matplotlib for python rocks, I
> wonder if it can be
> > ported....
>
> narray's are easily plotted or viewed as images.
>
> > The basics are all around, the problem is
> designing an intuitive one stop
> > shop that is really usable. Being able to hack
> something out of gnuplot is
> > not the same as having a well put together
> framework/library....
>
> narray takes a bit of getting used to - but there is
> really a tight
> integration. check out
>
> http://www.gfd-dennou.org/...
> http://www.ir.isas.ac.jp/~masa...
>
> there's alot. not much in english - something i'm
> working to remedy in
>
>
>
http://sciruby.codeforpeople.com/sr.cgi/TheScientificRubyProgr...
>
> cheers.
>
> -a
> --
>
===============================================================================
> | email :: ara [dot] t [dot] howard [at] noaa [dot]
> gov
> | phone :: 303.497.6469
> | My religion is very simple. My religion is
> kindness.
> | --Tenzin Gyatso
>
===============================================================================
>
>
>


__________________________________________________
Converse com seus amigos em tempo real com o Yahoo! Messenger
http://br.download.yahoo.com/...


none

7/7/2005 6:35:00 PM

0

How do you get the singular value decomposition of a matrix in Narray
into a [u,x,v] triple of matrices? Then I want to grab the first
column of u (u(:,1) in matlab).

I am also interested in stacking a bunch of data matrices with various
lags:

c = column dimension of m
stacked_m = [m(:, 1:c-2); m(:, 2:c-1); m(:,3:c)]

Finally, just for grins, I want to assign 1 to all the elements of a
matrix if which are less than 1:

m(m<1) = 1

I think there is a *lot* of work, in various bits and pieces. (And I
don't write Japanese, unfortunately.) However, it seems to be all over
the place. (I was never very fond of the CPAN haphazard approach to
"library" development.)

I don't want to complain--I would be quite happy to help with a
project. I just think we need a push to come up with a use-case based
integration of all the tools, like scipy in Python (really like scipy +
matplotlib), all in one coherent package.

William Morgan

7/7/2005 6:53:00 PM

0

Excerpts from none's mail of 7 Jul 2005 (EDT):
> Regarding Narray, it seems kind of cool, but lacking in real
> mathematical sophistication. I think it would be better to extend
> rb-gsl to make composing matrices easier and thus keep the excellent
> linear algebra facilities. Really, I think Narray and rb-gsl have a
> lot of redundancy and I really don't like bouncing between the two of
> them.

If it's a matter of adding matrix composition capabilities, you probably
want add that to the GSL. Presumably Ruby would be the wrong place to
put the computationally intensive aspect of your operations.

> Regarding graphics, matplotlib for python rocks, I wonder if it can be
> ported....

There is mrplot in Ruby, which I haven't used, but the screenshots look
very decent: http://rubyforge.org/projec....

> The basics are all around, the problem is designing an intuitive one
> stop shop that is really usable. Being able to hack something out of
> gnuplot is not the same as having a well put together
> framework/library....

As someone who uses the living hell that is R on a regular basis (though
not for any kind of linear algebra), I would give my left nut to be able
to use Ruby in its stead. But as Steve Jenkins pointed out, the real
value in Octave and R is the huge libraries behind them, not the
languages themselves.

Still, you've got to start somewhere. I'm very interested in this as
well.

--
William <wmorgan-ruby-talk@masanjin.net>


Paulo Jabardo

7/7/2005 6:56:00 PM

0



> One option would be to reimplement rb-gsl using
> SWIG. GSL is pretty big,
> but wrapping it with SWIG might not be too hard if
> its interfaces are
> implemented using a small number of types. You have
> to write two or
> three typemaps for each type, and SWIG does the
> rest.
ruby-gsl already wraps most of gsl. From what I've
seen on this list, the problem is the Vector and
Matrix libraries, even though they seem to work fine
in ruby-gsl even though it does not use every OO
concept available to ruby users.


> I've wrapped two libraries with SWIG. and while I
> don't consider myself
> an expert, I have learned a few things. I'd be
> willing to help get
> things kicked off.
>
> One thing to bear in mind, however. Wrapping
> (whether with SWIG or not)
> often requires copying input and output parameters.
> That's usually not a
> big deal, but you might take a substantial
> performance hit if you're
> passing large numbers of large arrays through a
> wrapper.

This really could hurt in many situations.


> Much of the value of Matlab is not the language
> itself, but the large
> number of libraries available for specialized
> applications like control
> systems and signal processing. That's much harder to
> replace than the
> underlying execution engine. (Which is, of course,
> part of the reason
> Fortran is still with us.)

You hit the nail! But remember that now there are many
Free/OS libraries available. But even if we wrapped
and developped many numerical libraries I don't think
ruby (or python) would be the ideal language for
computation. R/S-PLUS, for instance, were designed for
this purpose alone and I think it is a great language.
Even matlab has a language appropriate to numerical
computation (I don't like matlab's language).

Good graphics capabilities is very important for a
mathematical environment to succeed.

Paulo








_______________________________________________________
Yahoo! Acesso Grátis - Internet rápida e grátis.
Instale o discador agora! http://br.acesso....


William Morgan

7/7/2005 7:00:00 PM

0

Excerpts from none's mail of 7 Jul 2005 (EDT):
> I think there is a *lot* of work, in various bits and pieces. (And I
> don't write Japanese, unfortunately.) However, it seems to be all
> over the place. (I was never very fond of the CPAN haphazard approach
> to "library" development.)
>
> I don't want to complain--I would be quite happy to help with a
> project. I just think we need a push to come up with a use-case based
> integration of all the tools, like scipy in Python (really like scipy
> + matplotlib), all in one coherent package.

I too think the time is ripe for this. With a really good data model and
a really good plotting library, and GSL/NArray/other/combination thereof
in the background, Ruby could take over the (scientific) world.

A good starting point is Ara's SciRuby wiki
(http://sciruby.codefor...), particularly
http://sciruby.codefor.../sr.cgi/InterestingProjects

--
William <wmorgan-ruby-talk@masanjin.net>