comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Resampling from cumulative probability distribution
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Resampling from cumulative probability distribution [message #58348 is a reply to message #58346] Sat, 26 January 2008 06:58 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Klemens writes:

> I am computing a bootstrap analysis where the resampling routine from
> a cumulative probability distribution needs the most cpu time. May be
> you have some ideas how to eliminate the loop and speed up the
> routine ...
>
> function get_bootstrap_pdf, np, cdf
>
> zz = randomu(S, np) ; np is the number of
> samples
>
> cdfa = cdf[0:n_elements(cdf)-2] ; cdf is the cumulative
> probability distribution
> cdfb = cdf[1:n_elements(cdf)-1]
>
> b = fltarr(n_elements(cdf)) ; b will be the
> resampled distribution
> b[*] = 0.00
>
> for i = 0, n_elements(cdf)-2 do begin ;
> loop through all bins
> index = where((zz ge cdfa[i]) and (zz lt cdfb[i]))
> if (max(index) ge 0) then begin
> b[i] = n_elements(index)
> endif else begin
> b[i] = 0.00
> endelse
> endfor
>
> total_b = total(b)
> b = b / total(b)
>
> return, b
>
> end
>
> Thanks for your help in advance !

I think you want something like this. I've added a common block
for your seed. Without it, I think you will find your results
not all that random.:-)

function get_bootstrap_pdf, np, cdf

common seed, s

zz = randomu(S, np)

cdfa = cdf[0:n_elements(cdf)-2]
cdfb = cdf[1:n_elements(cdf)-1]

I = findgen(n_elements(cdfa))
b = ((zz ge cdfa) and (zz lt cdfb)) * I

return, b / total(b)

end

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: IDLdoc 3.0 released
Next Topic: Overlaying where data

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 16:29:33 PDT 2025

Total time taken to generate the page: 0.48159 seconds