Re: Weighted histogram [message #55639] |
Wed, 29 August 2007 06:29 |
Conor
Messages: 138 Registered: February 2007
|
Senior Member |
|
|
On Aug 29, 9:05 am, David Fanning <n...@dfanning.com> wrote:
> Conor writes:
>> Concepts such as retirement are strange and foreign
>> to me. Clearly anyone who retires is simply lazy :)
>
> You have a lot in common with my wife. :-(
>
> 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.")
lol! That's certainly not something a person wants to hear...
|
|
|
Re: Weighted histogram [message #55641 is a reply to message #55639] |
Wed, 29 August 2007 06:05  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Conor writes:
> Concepts such as retirement are strange and foreign
> to me. Clearly anyone who retires is simply lazy :)
You have a lot in common with my wife. :-(
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.")
|
|
|
Re: Weighted histogram [message #55642 is a reply to message #55641] |
Wed, 29 August 2007 05:58  |
Conor
Messages: 138 Registered: February 2007
|
Senior Member |
|
|
On Aug 28, 2:59 pm, David Fanning <n...@dfanning.com> wrote:
> Conor writes:
>> The reverse_indices to a histogram are highly useful, and worth
>> learning. You should definitely memorize that entire link.
>
> We are setting up a fund now to maintain this link after
> my retirement. Let Coyote know if you wish to contribute. :-)
>
> 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.")
That's weird, why in the world would you want to retire?
-Conor
Sorry, this is only my first year in grad school - I haven't even had
a "real" job yet. Concepts such as retirement are strange and foreign
to me. Clearly anyone who retires is simply lazy :)
|
|
|
Re: Weighted histogram [message #55655 is a reply to message #55642] |
Tue, 28 August 2007 11:59  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Conor writes:
> The reverse_indices to a histogram are highly useful, and worth
> learning. You should definitely memorize that entire link.
We are setting up a fund now to maintain this link after
my retirement. Let Coyote know if you wish to contribute. :-)
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.")
|
|
|
Re: Weighted histogram [message #55657 is a reply to message #55655] |
Tue, 28 August 2007 11:55  |
Conor
Messages: 138 Registered: February 2007
|
Senior Member |
|
|
On Aug 27, 10:20 pm, snudge42 <snudg...@gmail.com> wrote:
> Hi guys,
>
> I have an array of velocities, final_v, and an array of weightings,
> prob_arr, which may look something like:
>
> final_v = [0,10,20,30,40,50,60,70,80,90]
> prob_arr = [0.05,0.1,0.05,0.0,0.05,0.15,0.2,0.2,0.15,0.05]
>
> I'd like to plot a histogram with the velocities along the x-axis and
> the weighted histogram values along the y-axis. I've got the first bit
> happening, but am having trouble working out how to do the y-axis.
> This is my code so far:
>
> testHisto = HISTOGRAM(final_v)
> s = SIZE(testHisto)
> maxData = MAX(final_v, MIN=minData)
> x = FINDGEN(s(1)) * ((maxData - minData)/(s(1)-1)) + minData
> plot, x, testHisto, PSYM = 10, XSTYLE=1
>
> Any help out there?
>
> Sebastian
So, first things first. You could make use of the locations keyword
to histogram and save yourself some trouble:
testHisto = histogram( final_v, locations=x )
plot, x, testHisto, psym=10, xs=1
That gives the exact same result as your calculation, but is faster
and more robust. As for your problem, you will want to use the
reverse_indices keyword to histogram (see http://www.dfanning.com/tips/histogram_tutorial.html
for hints on using histogram). You should try something like this:
final_v = [0,10,20,30,40,50,60,70,80,90]
prob_arr = [0.05,0.1,0.05,0.0,0.05,0.15,0.2,0.2,0.15,0.05]
prob_arr /= max(prob_arr) ; normalize prob_arr to one
; build histogram and extract reverse_indices
testHisto = histogram( final_v, locations=x, reverse_indices=ri )
testHisto = float(testHisto)
; loop through each bin
for i=1,n_elements(testHisto)-1 do begin
; see if there is data in this bin
if ri[i-1] eq ri[i] then continue
; retrieve the indices of the original data
inds = ri[ri[i-1]:ri[i]-1]
; loop through and multiply the histogram by the probability
for j=0,n_elements(inds)-1 do testHisto[i-1] *= prob_arr[inds[j]]
endfor
; plot the result
plot,x,testHisto,yr=[0,2],psym=10
The reverse_indices to a histogram are highly useful, and worth
learning. You should definitely memorize that entire link.
|
|
|