MathGroup Archive 2002

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

Search the Archive

RE: Re: help on bootstrap sample

  • To: mathgroup at smc.vnet.net
  • Subject: [mg37419] RE: [mg37374] Re: [mg37338] help on bootstrap sample
  • From: "tgarza01 at prodigy.net.mx" <tgarza01 at prodigy.net.mx>
  • Date: Sun, 27 Oct 2002 06:33:25 -0500 (EST)
  • Reply-to: tgarza01 at prodigy.net.mx
  • Sender: owner-wri-mathgroup at wolfram.com

Hello, Bobby:

Well, this is rather strange. I obtained my first results on a Dell 4500,
with 4.1, WinXP, 2.0 GHz, Pentium 4, 512Mb RAM. Since I'm away from home
for the weekend, I'm now using a Toshiba laptop, with 4.1, WinXP, 1.7 GHz,
Pentium 4, 512Mb RAM. I copied the code from your message below and
executed it. My new results are similar to the previous ones:

In[1]:=
Needs[
  "DiscreteMath`Combinatorica`"]
In[2]:=
swor[data_List, n_] := 
  Module[{ord = RandomKSubset[
      Length[data], n]}, 
   data[[ord]]]

In[3]:=
Timing[Table[swor[Range[100], 
     10], {10000}]; ]
Out[3]=
{3.064 Second,Null}

In[4]:=
Timing[Table[swor[Range[1000], 
     30], {1000}]; ]
Out[4]=
{0.762 Second,Null}

In[5]:=
Timing[Table[swor[Range[10000], 
     100], {1000}]; ]
Out[5]=
{2.493 Second,Null}

I can find no explanation for the differences with your timings, especially
in the third case. Weird, isn't it?

Regards,

Tomas
Original Message:
-----------------
From: DrBob drbob at bigfoot.com
To: mathgroup at smc.vnet.net
Subject: [mg37419] RE: [mg37374] Re: [mg37338] help on bootstrap sample


I got very different timing results here (with 4.2, WinXP, 2.2GHz
Pentinum4, 1024MB RAM), so I'm curious what machine, version, etc. you
are using:

Timing[Table[SampelNoReplace[Range[100], 10], {10000}]; ]
Timing[Table[swor[Range[100], 10], {10000}]; ]
{2.75*Second, Null}
{2.6100000000000003*Second,   Null}

Timing[Table[SampelNoReplace[Range[1000], 30], {1000}]; ]
Timing[Table[swor[Range[1000], 30], {1000}]; ]
{0.875*Second, Null}
{2.609*Second, Null}

Timing[Table[SampelNoReplace[Range[10000], 100], {1000}]; ]
Timing[Table[swor[Range[10000], 100], {1000}]; ]
{6.344000000000001*Second,   Null}
{31.436999999999998*Second,   Null}

As you can see, your method was generally much slower than the original,
on my machine.  Very strange!

(However, the method I had posted was horribly slow --- so slow I won't
bother to post results for it.)

Bobby

-----Original Message-----
From: Tomas Garza [mailto:tgarza01 at prodigy.net.mx] 
To: mathgroup at smc.vnet.net
Subject: [mg37419] [mg37374] Re: [mg37338] help on bootstrap sample


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: [mg37419] [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
>     ]
>
>
>
>






--------------------------------------------------------------------
mail2web - Check your email from the web at
http://mail2web.com/ .




  • Prev by Date: Re: Re: Off by 0.00000001, Why?
  • Next by Date: Print[] without linefeed?
  • Previous by thread: Re: help on bootstrap sample
  • Next by thread: Problem with user defined functions