This is the mail archive of the gsl-discuss@sources.redhat.com mailing list for the GSL project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

gsl_ran_sample_matrix()


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 =========


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]