MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: help on bootstrap sample

  • To: mathgroup at smc.vnet.net
  • Subject: [mg37374] Re: [mg37338] help on bootstrap sample
  • From: Tomas Garza <tgarza01 at prodigy.net.mx>
  • Date: Fri, 25 Oct 2002 02:48:28 -0400 (EDT)
  • References: <200210240655.CAA05072@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

In the sampling with replacement I could find no improvement. In the
sampling with replacement, I think you'd do well to abandon procedural
programming and use the many possibilities Mathematica offers to improve
programming. Unfortunately, in spite of this I still couldn't find dramatic
improvements in speed (but then, I'm not a very skilled programmer). It
seems, however, that improvements in speed depend on the relative sizes of
your data set and the sample.

The idea is to use the AddOn package DiscreteMath`Combinatorica`, which has
a nice function RandomKSubset (cf. the Help Browser). Then I propose the
function swor (it stands for sample without replacement):

In[1]:=
Needs["DiscreteMath`Combinatorica`"]

In[2]:=
swor[data_List,n_]:=Module[
    {ord=RandomKSubset[Length[data],n]},
    data[[ord]]]

It certainly looks simpler and nicer then your function SampelNoReplace.
Now, I tried three combinations of data and sample sizes:

In[44]:=
Table[SampelNoReplace[Range[100],10],{10000}];//Timing
Out[44]=
{3.282 Second,Null}
In[45]:=
Table[swor[Range[100],10],{10000}];//Timing
Out[45]=
{2.906 Second,Null}
In[42]:=
Table[SampelNoReplace[Range[1000],30],{1000}];//Timing
Out[42]=
{1.031 Second,Null}
In[43]:=
Table[swor[Range[1000],30],{1000}];//Timing
Out[43]=
{0.641 Second,Null}
In[46]:=
Table[SampelNoReplace[Range[10000],100],{1000}];//Timing
Out[46]=
{8.219 Second,Null}
In[47]:=
Table[swor[Range[10000],100],{1000}];//Timing
Out[47]=
{2.312 Second,Null}

So, as you see, in all cases we get some improvement, and it varies from 13%
to 255%.

Tomas Garza
Mexico City
----- Original Message -----
From: "Søren Merser" <merser at image.dk>
To: mathgroup at smc.vnet.net
Subject: [mg37374] [mg37338] help on bootstrap sample


> Hi Mathematica freeks
> I've made two small rutines for sampling (bootstrap statistics)
> They are working , but at least 'SampleNoReplace' is rather slow
> I was wondering if any of you know of a faster way to do this
> Regards soren
>
> SampelReplace[data_List:{0, 1}, n_:1] :=
>   Module[{}, data[[Table[Random[Integer, {1, Length@data} ], {n}]]]]
>
> SampelNoReplace[data_List, n_] := Module[{idx, len, res, d, hi, i},
>     d = data;
>     res = {};
>     len = hi = Length@d;
>
>     For[i = 1, i <= n && i <= len, i++,
>       idx = Random[Integer, {1, hi--} ];
>       AppendTo[res, d[[idx]]];
>       d = Drop[d, {idx}];
>       ];
>     res
>     ]
>
>
>
>




  • Prev by Date: Re: Pascal's Triangle
  • Next by Date: RE: RE: how to extract parameter values
  • Previous by thread: Re: help on bootstrap sample
  • Next by thread: help on bootstrap sample