public inbox for gsl-discuss@sourceware.org
 help / color / mirror / Atom feed
* gsl_ran_sample_matrix()
@ 2002-10-25 13:25 Joakim Hove
  2002-10-30 13:15 ` gsl_ran_sample_matrix() Brian Gough
  0 siblings, 1 reply; 3+ messages in thread
From: Joakim Hove @ 2002-10-25 13:25 UTC (permalink / raw)
  To: gsl-discuss


Hello,

i have written a small function, gsl_ran_sample_matrix(), which is
very similar to gsl_ran_sample(), but samples an entire row of data
from the original matrix.

Personally I use it in Bootstrap estimates of parameters:

Measurement nr    x       y    delta x    delta y
-------------------------------------------------
0               0.56     0.78   0.01     0.20 
1               0.67     0.89   0.04     ....
2               0.80     0.81   0.11
3               0.92     0.51   0.06     ....
4               0.88     1.00   0.07     ....
...........

When doing a bootstrap estimate of parameters I resample the
measurements randomly, but then of course it is important the whole
set of x,y,delta x and delta y values which belong together are sample
together. 

Would this be interesting to include in gsl??


Regards - Joakim


#include <gsl/gsl_matrix.h>
/*
  This function is like gsl_ran_sample() but samples entire rows from the original
  matrix, to be used when a row of data consist of data naturally grouped together,
  for instance several mesurements.
*/

void gsl_ran_sample_matrix(const gsl_rng *r, gsl_matrix *org_m, gsl_matrix *new_m) {
  size_t src_row,target_row;
  gsl_vector_view row;

  for (target_row=0; target_row < new_m->size1; target_row++) {
    src_row = gsl_rng_uniform_int(r,org_m->size1);

    row = gsl_matrix_row(org_m,src_row);
    gsl_matrix_set_row(new_m , target_row , (gsl_vector *) &row);
  }
}




-- 
==== Joakim Hove      www.phys.ntnu.no/~hove/   =======================
|| Institutt for fysikk  (735) 93637 / E3-141  |  Skøyensgate 10D    ||
|| N - 7491 Trondheim    hove@phys.ntnu.no     |  N - 7030 Trondheim ||
================================================= 73 93 31 68 =========

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

end of thread, other threads:[~2002-10-31  8:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-25 13:25 gsl_ran_sample_matrix() Joakim Hove
2002-10-30 13:15 ` gsl_ran_sample_matrix() Brian Gough
2002-10-31 13:10   ` gsl_ran_sample_matrix() Joakim Hove

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).