public inbox for gsl-discuss@sourceware.org
 help / color / mirror / Atom feed
* modifying matrix allocation functions for use with R
@ 2001-12-19 13:20 Faheem Mitha
  2001-12-19 13:20 ` Timothy H. Keitt
  2001-12-19 13:20 ` Brian Gough
  0 siblings, 2 replies; 9+ messages in thread
From: Faheem Mitha @ 2001-12-19 13:20 UTC (permalink / raw)
  To: gsl-discuss

Dear People,

Here is a relatively esoteric question. Some of you may be familiar with
R (sometimes called GNU S) which does statistical stuff. It is possible to
use C code compiled into a shared library as a backend for R. Now, I was
wanting to use some GSL routines in this code.

In particular, I need to use allocation functions like gsl_matrix_alloc.
Unfortunately, I'm not sure whether standard calloc/malloc that are used
work with R. I'm going to check this, but I think the answer is most
likely no. R uses a routine called R_alloc which takes storage from the R
heap and manages the cleanup itself (so you don't need to use free).

One option I was considering was rewriting gsl_matrix_alloc (leaving out
the error checking) in terms of R_alloc. However, I can't find the code
for FUNCTION(gsl_block, alloc) (I assume this means gsl_block_alloc)
used in the code for gsl_matrix_alloc. gsl_matrix_alloc itself seems to be
in matrix/init_source.c. Can someone point me to the code for
gsl_block_alloc, or suggest any other options?

I'm not subscribed to the list, so I would be obliged if you would cc me.

                            Sincerely, Faheem Mitha.

^ permalink raw reply	[flat|nested] 9+ messages in thread
* Re: calculating matrix inverses (was Re: modifying matrix allocationfunctions for use with R)
@ 2001-12-19 13:20 Edwin Robert Tisdale
  0 siblings, 0 replies; 9+ messages in thread
From: Edwin Robert Tisdale @ 2001-12-19 13:20 UTC (permalink / raw)
  To: gsl-discuss

Faheem Mitha wrote:

> I want to calculate the inverse of (HH^t)^{-1} H
> where H is a given matrix
> as part of simulating from a multivariate normal distribution
> (the given expression is the mean).

For a nonsingular square matrix

	A = (HH^T)

you need to solve

	AX = I

where I is the identity matrix and

	X = A^{-1}

is the inverse of A.

The problem with matrix inversion is that
there is no one right way to do it.
Perhaps, in this case, a Cholesky decomposition
might be the preferred solution method.
Computing the inverse in two steps --
decomposition followed by back substitution --
has the added advantage of allowing you
to evaluate the condition of the matrix
after the decomposition and
before you attempt to divide by zero
during the back substitution.
to divide by zero

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2001-12-19 13:20 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-12-19 13:20 modifying matrix allocation functions for use with R Faheem Mitha
2001-12-19 13:20 ` Timothy H. Keitt
2001-12-19 13:20 ` Brian Gough
2001-12-19 13:20   ` Faheem Mitha
2001-12-19 13:20     ` Brian Gough
2001-12-19 13:20       ` calculating matrix inverses (was Re: modifying matrix allocationfunctions for use with R) Faheem Mitha
2001-12-19 13:20         ` James Theiler
2001-12-19 13:20           ` Faheem Mitha
2001-12-19 13:20 Edwin Robert Tisdale

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).