00001 // This is mul/pdf1d/pdf1d_resample.cxx 00002 #include "pdf1d_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 pdf1d_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 pdf1d_resample(vnl_vector<double>& x, const vnl_vector<double>& d, int ns) 00016 { 00017 pdf1d_resample(x,d.data_block(),d.size(),ns); 00018 } 00019 00020 //: Fill x with ns samples drawn at random from d[0..n-1] 00021 // If ns not specified (or zero) then draw d.size() samples from d 00022 void pdf1d_resample(vnl_vector<double>& x, const double* d, int n, int ns) 00023 { 00024 if (ns==0) ns=n; 00025 x.set_size(ns); 00026 00027 for (int i=0;i<ns;++i) 00028 x[i] = d[pdf1d_resample_mz_random.lrand32(0,n-1)]; 00029 }