contrib/mul/vpdfl/vpdfl_resample.cxx
Go to the documentation of this file.
00001 // This is mul/vpdfl/vpdfl_resample.cxx
00002 #include "vpdfl_resample.h"
00003 //:
00004 // \file
00005 // \author Tim Cootes
00006 // \brief Select random sample of data with replacement.
00007 
00008 #include <vnl/vnl_random.h>
00009 
00010 // Object used to do sampling
00011 static vnl_random vpdfl_resample_mz_random;
00012 
00013 //: Fill x with n samples drawn at random from d
00014 //  If n not specified (or zero) then draw d.size() samples from d
00015 void vpdfl_resample(vcl_vector<vnl_vector<double> >& x,
00016                     const vcl_vector<vnl_vector<double> >& d, int ns)
00017 {
00018   vpdfl_resample(x,&d[0],d.size(),ns);
00019 }
00020 
00021 //: Fill x with ns samples drawn at random from d[0..n-1]
00022 //  If ns not specified (or zero) then draw d.size() samples from d
00023 void vpdfl_resample(vcl_vector<vnl_vector<double> >& x,
00024                     const vnl_vector<double>* d, int n, int ns)
00025 {
00026   if (ns==0) ns=n;
00027   x.resize(ns);
00028 
00029   for (int i=0;i<ns;++i)
00030     x[i] = d[vpdfl_resample_mz_random.lrand32(0,n-1)];
00031 }