Re: cumulative function? [message #12236] |
Mon, 27 July 1998 00:00  |
David Foster
Messages: 341 Registered: January 1996
|
Senior Member |
|
|
Alex Schuster wrote:
>
> dschmidt@lanl.gov (David M. Schmidt) wrote:
>
>> Anyone know of a fast (e.g. built-in) way to construct a cumulative
>> vector from a given input vector?
>>
>> The slow way is:
>>
>> Given A(100)
>> C=fltarr(100)
>> C(0)=A(0)
>> For i=1,99 do C(i)=C(i-1)+A(i)
>
> You could use an index array:
>
> index = indgen( 99 ) + 1
> C(0) = A(0)
> C(index) = C(index-1) + A(index)
>
> Or the shift function:
>
> C(99) = 0
> C = shift( C, 1 ) + A ; or was it -1 ?
>
> Alex
Just wanted to point out that I don't think this is what David is
after, as it won't get you a *cumulative* density function:
ind=indgen(20)+1
a=indgen(20)+50
c[0]=a[0]
c[ind] = c[ind-1] + a[ind]
print, c
50 101 53 55 56 57
58 60 62 63 64 65
67 68 69 70 71 72
73 74 74
I checked the code for HIST_EQUAL.PRO, and there is a /HISTOGRAM_ONLY
keyword that is supposed to return the cumulative distribution
histogram. Of course, you won't know about this keyword from reading
the OnLine help because IT ISN'T MENTIONED!! You have to set the
BINSIZE, MAXV, MINV, and TOP keywords explicitly. The problem is,
the routine uses the same "slow method" that David lists earlier!
; HISTOGRAM_ONLY: If set, return the cumulative distribution
histogram,
; rather than the histogram equalized array. MAXV, MINV, and
; BINSIZE will be set, describing the scaling of the histogram,
; if not specified.
Sorry, but given that it is Monday and I just got back from vacation,
I cannot think of a faster way. If it was really critical you could
write a short C function and call it using CALL_EXTERNAL. I've done
this a lot so feel free to email me if you want help.
Dave
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
David S. Foster Univ. of California, San Diego
Programmer/Analyst Brain Image Analysis Laboratory
foster@bial1.ucsd.edu Department of Psychiatry
(619) 622-5892 8950 Via La Jolla Drive, Suite 2240
La Jolla, CA 92037
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
|
|
|