Thread: Matrix (linear algebra) operations and types in PG?

Matrix (linear algebra) operations and types in PG?

From
"Webb Sprague"
Date:
Hi all,

This is just a random question/idea (I tried googling, but couldn't
get an answer quickly):

Has anyone written a library to effect linear algebra types and
operations through Postgres?  E.G., convert a float 2-d array to a
matrix, convert a float 1-d array to a vector, multiply them, take the
matrix power, calculate eigenvalues, some easy functions for
converting tables to matrices, etc.  This might be extremely useful to
some of the data analysis folks out there--I would have used it a year
ago on a project.

It seems like a fairly straightforward project, which would consist
primarily in hooking up the LAPACK libraries and defining some types
and operations. Is there something tricky that I haven't foreseen?

If I had the summer free, I would apply for a google summer of code
project (hint to the world...).

Re: Matrix (linear algebra) operations and types in PG?

From
Andreas Kretschmer
Date:
Webb Sprague <webb.sprague@gmail.com> schrieb:

> Hi all,
>
> This is just a random question/idea (I tried googling, but couldn't
> get an answer quickly):
>
> Has anyone written a library to effect linear algebra types and
> operations through Postgres?  E.G., convert a float 2-d array to a
> matrix, convert a float 1-d array to a vector, multiply them, take the
> matrix power, calculate eigenvalues, some easy functions for
> converting tables to matrices, etc.  This might be extremely useful to

Take a look at pl/r, http://www.joeconway.com/plr/. This is a interface
to R: http://www.r-project.org/
I'm not familiar with this, but i think, this may be helpful for you.


Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect.                              (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly."    (unknow)
Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°

Re: Matrix (linear algebra) operations and types in PG?

From
"Webb Sprague"
Date:
Hi all,

> Take a look at pl/r, http://www.joeconway.com/plr/. This is a interface
> to R: http://www.r-project.org/
> I'm not familiar with this, but i think, this may be helpful for you.

Shoot -- I should have said that I knew about plr -- supposedly a
great project (maybe the reason there is no matrix type/operator in
PG), but not what I am interested in, for reasons more to do with
curiousity and the joy of hacking than with any pragmatic need.
(Thanks, though, Andreas)

Re: Matrix (linear algebra) operations and types in PG?

From
Joe Conway
Date:
Webb Sprague wrote:
> Hi all,
>
>> Take a look at pl/r, http://www.joeconway.com/plr/. This is a interface
>> to R: http://www.r-project.org/
>> I'm not familiar with this, but i think, this may be helpful for you.
>
> Shoot -- I should have said that I knew about plr -- supposedly a
> great project (maybe the reason there is no matrix type/operator in
> PG), but not what I am interested in, for reasons more to do with
> curiousity and the joy of hacking than with any pragmatic need.
> (Thanks, though, Andreas)

I've found myself recently wanting a lighter weight way to do certain
advanced math operations along these lines. For example, I needed a
quick and simple way to do N-order polynomial least squares fits. But I
found LAPACK more complex than I really wanted.

Looking around a bit I found http://freshmeat.net/projects/ccmath which
unfortunately looks unmaintained and LGPL licensed, but has a nice
simple API for doing curve fits. It also has all the matrix operations
you're looking for.

I've already used it to write a polynomial least squares fit custom
aggregate for postgres, and was thinking to do something with the fft
and power spectrum functions next.

BTW, I tried to contact the author to see if he'd be willing to allow me
to pull out just the stuff I need and release it under a BSD license
along with my code, but he did not reply.

Joe